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