forked from freudenreichan/info2Praktikum-NeuronalesNetz
Implement ImageInput
This commit is contained in:
1 parent
489bd3dc23
commit
65f486df9d
2 files changed
+16
-10
No files matched your search
+16
-9
@@ -43,13 +43,7 @@ static int readLabels(FILE *file, unsigned char label[], unsigned int count) {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
GrayScaleImageSeries *readImages(const char *path) {
|
||||
FILE *file = fopen(path, "rb");
|
||||
if (!controlFile(file)) {
|
||||
return NULL;
|
||||
}
|
||||
GrayScaleImageSeries *innerSeries(FILE*file) {
|
||||
unsigned int count = readNumber(file);
|
||||
unsigned int width = readNumber(file);
|
||||
unsigned int height = readNumber(file);
|
||||
@@ -65,7 +59,6 @@ GrayScaleImageSeries *readImages(const char *path) {
|
||||
series->count = count;
|
||||
series->labels = malloc(series->count * sizeof(unsigned char));
|
||||
series->images = malloc(series->count * sizeof(GrayScaleImage));
|
||||
series->addrSourceTxt = file;
|
||||
if (series->labels == NULL || series->images == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -93,6 +86,21 @@ GrayScaleImageSeries *readImages(const char *path) {
|
||||
}
|
||||
|
||||
|
||||
GrayScaleImageSeries *readImages(const char *path) {
|
||||
FILE *file = fopen(path, "rb");
|
||||
if (!controlFile(file)) {
|
||||
return NULL;
|
||||
}
|
||||
GrayScaleImageSeries*address = innerSeries(file);
|
||||
fclose(file);
|
||||
if (address == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void clearSeries(GrayScaleImageSeries *series) {
|
||||
if (series == NULL) { return; }
|
||||
if (series->images != NULL) {
|
||||
@@ -107,6 +115,5 @@ void clearSeries(GrayScaleImageSeries *series) {
|
||||
if (series->labels != NULL) {
|
||||
free(series->labels);
|
||||
}
|
||||
fclose(series->addrSourceTxt);
|
||||
free(series);
|
||||
}
|
||||
Reference in new issue
Block a user