Matrix add
This commit is contained in:
parent
c349bad3c9
commit
575c7e21e4
29
imageInput.c
29
imageInput.c
@ -21,30 +21,47 @@ int checkHeader(FILE* fileName)
|
|||||||
//// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
//// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||||
GrayScaleImageSeries *readImages(const char *path)
|
GrayScaleImageSeries *readImages(const char *path)
|
||||||
{
|
{
|
||||||
FILE* file = fopen(path,"rb");
|
FILE* file = fopen(path,"rb");
|
||||||
unsigned int width=0,height=0;
|
unsigned int width=0,height=0;
|
||||||
GrayScaleImageSeries *imageSeries = malloc(sizeof(GrayScaleImageSeries));
|
GrayScaleImageSeries *imageSeries = (GrayScaleImageSeries*)malloc(sizeof(GrayScaleImageSeries));
|
||||||
|
if (imageSeries ==NULL) {
|
||||||
|
printf("Error allocating memory for GrayScaleImageSeries\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
imageSeries->count = 0;
|
imageSeries->count = 0;
|
||||||
if(checkHeader(file) == 0) {
|
if(checkHeader(file) == 0) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fread(&imageSeries->count,sizeof(unsigned short),1,file);
|
fread(&imageSeries->count,sizeof(unsigned short),1,file);
|
||||||
imageSeries->images = malloc(imageSeries->count * sizeof(GrayScaleImage));
|
imageSeries->images = (GrayScaleImage*)malloc(imageSeries->count * sizeof(GrayScaleImage));
|
||||||
fread(&width,sizeof(unsigned short),1,file);
|
fread(&width,sizeof(unsigned short),1,file);
|
||||||
fread(&height,sizeof(unsigned short),1,file);
|
fread(&height,sizeof(unsigned short),1,file);
|
||||||
imageSeries->labels = malloc(imageSeries->count * sizeof(unsigned char));
|
imageSeries->labels = malloc(imageSeries->count * sizeof(unsigned char));
|
||||||
|
if(imageSeries->labels == NULL) {
|
||||||
|
free(imageSeries);
|
||||||
|
fclose(file);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; i < imageSeries->count; i++) {
|
for(int i = 0; i < imageSeries->count; i++) {
|
||||||
imageSeries->images[i].width = width;
|
imageSeries->images[i].width = width;
|
||||||
imageSeries->images[i].height = height;
|
imageSeries->images[i].height = height;
|
||||||
const unsigned int imageSize = height*width;
|
const unsigned int imageSize = height*width;
|
||||||
imageSeries->images[i].buffer = malloc(imageSize*sizeof(GrayScalePixelType));
|
imageSeries->images[i].buffer = (GrayScalePixelType*) malloc(imageSize*sizeof(GrayScalePixelType));
|
||||||
|
if(imageSeries->images[i].buffer == NULL) {
|
||||||
|
free(imageSeries->images);
|
||||||
|
free(imageSeries);
|
||||||
|
fclose(file);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
for (int j=0;j<imageSize;j++)
|
for (int j=0;j<imageSize;j++)
|
||||||
{
|
{
|
||||||
fread(&imageSeries->images[i].buffer[j],sizeof(GrayScalePixelType),1,file);
|
fread(&imageSeries->images[i].buffer[j],sizeof(GrayScalePixelType),1,file);
|
||||||
}
|
}
|
||||||
fread(&imageSeries->labels[i],sizeof(unsigned char),1,file);
|
fread(&imageSeries->labels[i],sizeof(unsigned char),1,file);
|
||||||
}
|
}
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
return imageSeries;
|
return imageSeries;
|
||||||
}
|
}
|
||||||
@ -52,6 +69,10 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
|
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
|
||||||
void clearSeries(GrayScaleImageSeries *series)
|
void clearSeries(GrayScaleImageSeries *series)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < series->count; i++)
|
||||||
|
{
|
||||||
|
free(series->images[i].buffer);
|
||||||
|
}
|
||||||
free(series->images);
|
free(series->images);
|
||||||
free(series->labels);
|
free(series->labels);
|
||||||
free(series);
|
free(series);
|
||||||
|
|||||||
11
matrix.c
11
matrix.c
@ -71,6 +71,17 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
|||||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//Prüfung ob größe Matrix1 und matrix2 identisch
|
||||||
|
Matrix matrix;
|
||||||
|
matrix.cols = matrix1.cols;
|
||||||
|
matrix.rows = matrix1.rows;
|
||||||
|
matrix.buffer= (MatrixType*) malloc(matrix.rows*matrix.cols * sizeof(MatrixType));
|
||||||
|
for (int i = 0; i < matrix1.rows; i++) {
|
||||||
|
for (int j = 0; j < matrix1.cols; j++) {
|
||||||
|
(matrix.buffer[i*matrix.cols+j])= (matrix1.buffer[i*matrix.cols+j]) + (matrix2.buffer[i*matrix.cols+j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#define IDENTIFICATION_TAG "__info2_neural_network_file_format__"
|
#define IDENTIFICATION_TAG "__info2_neural_network_file_format__"
|
||||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user