Hilfsfunktion und clearSeries geschrieben
This commit is contained in:
parent
2f30c2d030
commit
4486fbd82e
25
imageInput.c
25
imageInput.c
@ -7,6 +7,25 @@
|
||||
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
||||
|
||||
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||
static int checkFileHeader(FILE *fp)
|
||||
{
|
||||
if (!fp) // Datei konnte nicht geöffnet werden
|
||||
return 0;
|
||||
|
||||
char buffer[BUFFER_SIZE];
|
||||
size_t headerLen = strlen(FILE_HEADER_STRING);
|
||||
if (headerLen >= BUFFER_SIZE) // Safety Check
|
||||
return 0;
|
||||
|
||||
if (fread(buffer, 1, headerLen, fp) != headerLen)
|
||||
return 0;
|
||||
|
||||
buffer[headerLen] = '\0';
|
||||
if (strcmp(buffer, FILE_HEADER_STRING) != 0)
|
||||
return 0;
|
||||
|
||||
return 1; // Header stimmt
|
||||
}
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||
GrayScaleImageSeries *readImages(const char *path)
|
||||
@ -19,4 +38,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)
|
||||
{
|
||||
if (series == NULL)
|
||||
return;
|
||||
|
||||
free(series->images);
|
||||
free(series->labels);
|
||||
free(series);
|
||||
}
|
||||
21
matrix.c
21
matrix.c
@ -16,12 +16,29 @@ void clearMatrix(Matrix *matrix)
|
||||
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
|
||||
if (matrix.buffer != NULL)
|
||||
{
|
||||
if (rowIdx < matrix.rows && colIdx < matrix.cols)
|
||||
{
|
||||
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
|
||||
if (matrix.buffer != NULL)
|
||||
{
|
||||
if (rowIdx < matrix.rows && colIdx < matrix.cols)
|
||||
{
|
||||
return matrix.buffer[rowIdx * matrix.cols + colIdx];
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user