Matrix add

This commit is contained in:
Bannach 2025-11-11 18:09:30 +01:00
parent c349bad3c9
commit 575c7e21e4
3 changed files with 38 additions and 5 deletions

View File

@ -23,28 +23,45 @@ GrayScaleImageSeries *readImages(const char *path)
{
FILE* file = fopen(path,"rb");
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;
if(checkHeader(file) == 0) {
fclose(file);
return NULL;
}
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(&height,sizeof(unsigned short),1,file);
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++) {
imageSeries->images[i].width = width;
imageSeries->images[i].height = height;
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++)
{
fread(&imageSeries->images[i].buffer[j],sizeof(GrayScalePixelType),1,file);
}
fread(&imageSeries->labels[i],sizeof(unsigned char),1,file);
}
fclose(file);
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
void clearSeries(GrayScaleImageSeries *series)
{
for (int i = 0; i < series->count; i++)
{
free(series->images[i].buffer);
}
free(series->images);
free(series->labels);
free(series);

View File

@ -71,6 +71,17 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
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)

View File

@ -8,6 +8,7 @@
#define IDENTIFICATION_TAG "__info2_neural_network_file_format__"
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
{
}
void test_loadModelReturnsCorrectNumberOfLayers(void)