generated from freudenreichan/info2Praktikum-NeuronalesNetz
last short fix for the day in imageInput.c
This commit is contained in:
parent
4d1908ed27
commit
419296af9e
23
imageInput.c
23
imageInput.c
@ -9,7 +9,7 @@
|
||||
|
||||
/// @brief Gets the next char value from specified and opened file
|
||||
/// @param openedFile stream FILE, from which to read
|
||||
/// @param iterations how many chars are being taken from
|
||||
/// @param iterations how many chars are being taken from (1 char equals 2 Hexdecimals equals 8bit)
|
||||
static int getCharValueFromFile(FILE* openedFile, int iterations) {
|
||||
int addToFile = 0;
|
||||
|
||||
@ -56,7 +56,7 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
|
||||
|
||||
if (fileTagEqual) {
|
||||
numberOfImages = getCharValueFromFile(openFile, 4);
|
||||
numberOfImages = getCharValueFromFile(openFile, 2);
|
||||
|
||||
// no Images in series -> No image-series
|
||||
if (numberOfImages == 0) {
|
||||
@ -64,8 +64,8 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
return series;
|
||||
}
|
||||
|
||||
width = getCharValueFromFile(openFile, 4);
|
||||
height = getCharValueFromFile(openFile, 4);
|
||||
width = getCharValueFromFile(openFile, 2);
|
||||
height = getCharValueFromFile(openFile, 2);
|
||||
|
||||
// no height/width --> impossible file
|
||||
if(height == 0 || width == 0) {
|
||||
@ -73,7 +73,7 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
return series;
|
||||
}
|
||||
|
||||
//all the starting parameters are set --> the images can be read
|
||||
//all the starting parameters are set --> the images can be read and stored
|
||||
GrayScaleImage* images = malloc(numberOfImages * sizeof(GrayScaleImage));
|
||||
unsigned char* labels = malloc(numberOfImages * sizeof(unsigned char));
|
||||
|
||||
@ -82,24 +82,22 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
series->labels = labels;
|
||||
|
||||
for (int i = 0; i < numberOfImages; i++) {
|
||||
|
||||
for (int j = 0; j < width * height; j++) {
|
||||
//this needs to be reworked
|
||||
// allocating the actual matrix image for image
|
||||
images[i].buffer = malloc(width * height);
|
||||
|
||||
images[i].height = height;
|
||||
images[i].width = width;
|
||||
images[i].buffer[j] = fgetc(openFile);
|
||||
}
|
||||
//rest of the values that only affect the image itself
|
||||
series->labels[i] = fgetc(openFile);
|
||||
series->count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fclose(openFile);
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
@ -107,10 +105,9 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
void clearSeries(GrayScaleImageSeries *series)
|
||||
{
|
||||
for (int i = 0; i < series->count; i++) {
|
||||
for (int j = 0; j < series->images->height * series->images->width; j++) {
|
||||
free(series->images[i].buffer[j]);
|
||||
}
|
||||
free(series->images[i].buffer);
|
||||
}
|
||||
|
||||
free(series->images);
|
||||
series->images = NULL;
|
||||
free(series->labels);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user