forked from freudenreichan/info2Praktikum-NeuronalesNetz
61 lines
1.7 KiB
C
61 lines
1.7 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "imageInput.h"
|
|
|
|
#define BUFFER_SIZE 100
|
|
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
|
|
|
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
|
GrayScaleImage *readSingleImage(size_t widht, size_t height) {
|
|
|
|
}
|
|
|
|
|
|
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
|
GrayScaleImageSeries *readImages(const char *path)
|
|
{
|
|
GrayScaleImageSeries *series = NULL;
|
|
unsigned short NumberOfImages;
|
|
unsigned short PictureWidth;
|
|
unsigned short PictureHeight;
|
|
char* verifyWord;
|
|
size_t bufferCount = 0;
|
|
|
|
FILE *file = fopen("mnist_test.info2", "rb"); // opening the file
|
|
|
|
bufferCount = fread(&verifyWord, 27, 1, file);
|
|
if (bufferCount != 1 || verifyWord != FILE_HEADER_STRING) {
|
|
strerror("Error: wrong file or unable to read the file!");
|
|
// return error code;
|
|
}
|
|
|
|
bufferCount = 0;
|
|
bufferCount = fread(&NumberOfImages, 2, 1, file);
|
|
if (bufferCount != 1) {
|
|
strerror("Error: failed to read number of pictures");
|
|
// return error code
|
|
}
|
|
|
|
bufferCount = 0;
|
|
bufferCount = fread(&PictureWidth, 2, 1, file);
|
|
if (bufferCount != 1) {
|
|
strerror("Error: failed to read the picture width!");
|
|
// return error code
|
|
}
|
|
|
|
bufferCount = 0;
|
|
bufferCount = fread(&PictureHeight, 2, 1, file);
|
|
if (bufferCount != 1) {
|
|
strerror("Error: failed to read the picture height!");
|
|
// return error code
|
|
}
|
|
|
|
return series;
|
|
}
|
|
|
|
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
|
|
void clearSeries(GrayScaleImageSeries *series)
|
|
{
|
|
}
|