forked from freudenreichan/info2Praktikum-NeuronalesNetz
Implement ImageInput
This commit is contained in:
1 parent
682415e76e
commit
489bd3dc23
1 file changed
+18
-12
+18
-12
@@ -25,7 +25,7 @@ static unsigned int readNumber(FILE *file) {
|
|||||||
}
|
}
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
// TODO:alles in innere Funktion äußere Funktion nur fopen / fclose
|
||||||
|
|
||||||
// fillBuffer und readLabel muss immer in einer Schleife zusammen stehen
|
// fillBuffer und readLabel muss immer in einer Schleife zusammen stehen
|
||||||
static int fillBuffer(unsigned char buffer[], unsigned int bufferSize, FILE *file) {
|
static int fillBuffer(unsigned char buffer[], unsigned int bufferSize, FILE *file) {
|
||||||
@@ -50,14 +50,19 @@ GrayScaleImageSeries *readImages(const char *path) {
|
|||||||
if (!controlFile(file)) {
|
if (!controlFile(file)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries));
|
unsigned int count = readNumber(file);
|
||||||
series->count = readNumber(file);
|
|
||||||
unsigned int width = readNumber(file);
|
unsigned int width = readNumber(file);
|
||||||
unsigned int height = readNumber(file);
|
unsigned int height = readNumber(file);
|
||||||
if (width == 0 || height == 0 || series->count == 0 || series == NULL) {
|
if (width == 0 || height == 0 || count == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// Füllen des structs series
|
// Füllen des structs series
|
||||||
|
GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries));
|
||||||
|
if (series == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
series->count = count;
|
||||||
series->labels = malloc(series->count * sizeof(unsigned char));
|
series->labels = malloc(series->count * sizeof(unsigned char));
|
||||||
series->images = malloc(series->count * sizeof(GrayScaleImage));
|
series->images = malloc(series->count * sizeof(GrayScaleImage));
|
||||||
series->addrSourceTxt = file;
|
series->addrSourceTxt = file;
|
||||||
@@ -66,19 +71,20 @@ GrayScaleImageSeries *readImages(const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// struct grayScaleImage füllen als Teil eines Arrays innerhalb series
|
// struct grayScaleImage füllen als Teil eines Arrays innerhalb series
|
||||||
int readBufferFault = 1;
|
|
||||||
int readLabelFault = 1;
|
|
||||||
unsigned int const bufferSize = width * height;
|
unsigned int const bufferSize = width * height;
|
||||||
for (unsigned int i = 0; i < series
|
for (unsigned int i = 0; i < series->count; i++) {
|
||||||
->count && readBufferFault && readLabelFault; i++) {
|
|
||||||
GrayScaleImage *grayScaleImage = &series->images[i];
|
GrayScaleImage *grayScaleImage = &series->images[i];
|
||||||
grayScaleImage->buffer = calloc(bufferSize, width * height * sizeof(GrayScalePixelType));
|
grayScaleImage->buffer = calloc(bufferSize, width * height * sizeof(GrayScalePixelType));
|
||||||
|
if (grayScaleImage->buffer == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
grayScaleImage->width = width;
|
grayScaleImage->width = width;
|
||||||
grayScaleImage->height = height;
|
grayScaleImage->height = height;
|
||||||
readBufferFault = fillBuffer(grayScaleImage->buffer, bufferSize, file);// frage an tobi kann ich readbufferfault auch schöner initialisieren
|
int readBufferFault = fillBuffer(grayScaleImage->buffer, bufferSize, file);
|
||||||
readLabelFault = readLabels(file, series->labels, i);
|
int readLabelFault = readLabels(file, series->labels, i);
|
||||||
|
if (!readLabelFault || !readBufferFault) {
|
||||||
if (grayScaleImage->buffer == NULL) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user