Fertigstellen von matrix.c und Hilfsfunktion von input.c

This commit is contained in:
Torsten Stock 2025-11-25 11:27:48 +01:00
parent 115b5b18f6
commit cd7d1fc0af
3 changed files with 37 additions and 13 deletions

View File

@ -8,24 +8,32 @@
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
void helpFunction
static void readPictureData(const char *path,const short ptrPicturesCount, const short ptrPictureWidth, const short ptrPictureHeigth)
{
GrayScalePixelType *bufferRead;
GrayScalePixelType *bufferWrite;
bufferRead = fopen(*path, "rb");
unsigned char header = strlen(FILE_HEADER_STRING);
unsigned int header = strlen(FILE_HEADER_STRING);
bufferWrite = createMatrix(1,header + 3);
FILE *file = fopen(path,"rb");
if (file == NULL){
perror("failed open file");
return;
}
fread(bufferWrite,sizeof(GrayScalePixelType),, bufferRead);
fseek(file, header, SEEK_SET);
pictures = *bufferRead + header;
fread(ptrPicturesCount, sizeof(unsigned short), 1, file);
fread(ptrPictureWidth, sizeof(unsigned short), 1, file);
fread(ptrPictureHeight, sizeof(unsigned short), 1, file);
fclose(file);
}
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
GrayScaleImageSeries *readImages(const char *path)
{
unsigned short picturesCount, pictureWidth, pictureHeight;
Matrix labels = creatmatrix(1,picturesCount);
Matrix images = creatmatrix(1,picturesCount);
@ -37,4 +45,18 @@ 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)
{
}
MatrixChar createMatrix(unsigned int rows, unsigned int cols)
{
if(rows <= 0 || cols <= 0){
Matrix matrix = { 0 , 0 , UNDEFINED_MATRIX_VALUE };
return matrix;
}
MatrixChar matrix = { rows , cols };
matrix.buffer = malloc((sizeof(char)*rows*cols));
return matrix;
}

View File

@ -17,6 +17,12 @@ typedef struct
unsigned int count;
} GrayScaleImageSeries;
typedef struct{
unsigned int rows;
unsigned int cols;
MatrixType *buffer;
}MatrixChar;
GrayScaleImageSeries *readImages(const char *path);
void clearSeries(GrayScaleImageSeries *series);

View File

@ -114,8 +114,4 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
}
return result;
}
//Für imageInput.c
//size_t fread(void *buffer, size_t elementSize, size_t count, FILE *FILE_HEADER_STRING)
//elementSize = width * height;
}