generated from freudenreichan/info2Praktikum-NeuronalesNetz
Formatierung
This commit is contained in:
1 parent
3a7c176d9a
commit
b1806ac8b2
1 file changed
+53
-50
+53
-50
@@ -7,56 +7,9 @@
|
||||
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
||||
|
||||
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||
|
||||
static FILE *openImageFile(const char *path)
|
||||
{
|
||||
|
||||
FILE *file = fopen(path, "rb");
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
|
||||
printf("Fehler: Datei %s konnte nicht geöffnet werden", path);
|
||||
return NULL;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static int checkFileHeader(FILE *file)
|
||||
{
|
||||
|
||||
char buffer[strlen(FILE_HEADER_STRING) + 1];
|
||||
|
||||
fread(buffer, sizeof(char), strlen(FILE_HEADER_STRING), file);
|
||||
|
||||
buffer[strlen(FILE_HEADER_STRING)] = '\0';
|
||||
|
||||
if (strcmp(buffer, FILE_HEADER_STRING) == 0)
|
||||
{
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static GrayScaleImageSeries *createSeries(unsigned int count)
|
||||
{
|
||||
|
||||
GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries));
|
||||
|
||||
if (series == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
series->count = count;
|
||||
|
||||
series->labels = malloc(count * sizeof(unsigned char));
|
||||
|
||||
series->images = malloc(count * sizeof(GrayScaleImage));
|
||||
|
||||
return series;
|
||||
}
|
||||
static FILE *openImageFile(const char *path);
|
||||
static int checkFileHeader(FILE *file);
|
||||
static GrayScaleImageSeries *createSeries(unsigned int count);
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||
GrayScaleImageSeries *readImages(const char *path)
|
||||
@@ -133,4 +86,54 @@ void clearSeries(GrayScaleImageSeries *series)
|
||||
free(series->labels);
|
||||
|
||||
free(series);
|
||||
}
|
||||
|
||||
static FILE *openImageFile(const char *path)
|
||||
{
|
||||
|
||||
FILE *file = fopen(path, "rb");
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
|
||||
printf("Fehler: Datei %s konnte nicht geöffnet werden", path);
|
||||
return NULL;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static int checkFileHeader(FILE *file)
|
||||
{
|
||||
|
||||
char buffer[strlen(FILE_HEADER_STRING) + 1];
|
||||
|
||||
fread(buffer, sizeof(char), strlen(FILE_HEADER_STRING), file);
|
||||
|
||||
buffer[strlen(FILE_HEADER_STRING)] = '\0';
|
||||
|
||||
if (strcmp(buffer, FILE_HEADER_STRING) == 0)
|
||||
{
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static GrayScaleImageSeries *createSeries(unsigned int count)
|
||||
{
|
||||
|
||||
GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries));
|
||||
|
||||
if (series == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
series->count = count;
|
||||
|
||||
series->labels = malloc(count * sizeof(unsigned char));
|
||||
|
||||
series->images = malloc(count * sizeof(GrayScaleImage));
|
||||
|
||||
return series;
|
||||
}
|
||||
Reference in new issue
Block a user