generated from freudenreichan/info2Praktikum-NeuronalesNetz
noch probleme bei übergabe von unterfunktion readIndividualImage
This commit is contained in:
1 parent
290b0d649e
commit
c2a26bc3ad
1 file changed
+12
-8
+12
-8
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
static GrayScaleImage *readIndividualImage(unsigned int width, unsigned int height, FILE *file){
|
static GrayScaleImage *readIndividualImage(unsigned int width, unsigned int height, FILE *file){
|
||||||
|
|
||||||
char *buf = calloc(width * height, sizeof(char));
|
GrayScalePixelType *buf = calloc(width * height, sizeof(unsigned char));
|
||||||
if(!buf){
|
if(!buf){
|
||||||
fprintf(stderr, "calloc failed!\n");
|
fprintf(stderr, "calloc failed!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -21,7 +21,7 @@ static GrayScaleImage *readIndividualImage(unsigned int width, unsigned int heig
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrayScaleImage *gimage = calloc(sizeof(GrayScaleImage, 1));
|
GrayScaleImage *gimage = calloc(sizeof(GrayScaleImage), 1);
|
||||||
if(gimage == NULL){
|
if(gimage == NULL){
|
||||||
fprintf(stderr, "calloc failed!\n");
|
fprintf(stderr, "calloc failed!\n");
|
||||||
free(buf);
|
free(buf);
|
||||||
@@ -45,6 +45,7 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
fprintf(stderr, "Couldn't allocate enough space!\n");
|
fprintf(stderr, "Couldn't allocate enough space!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
series->count = 0;
|
||||||
|
|
||||||
FILE *file = fopen(path, "rb");
|
FILE *file = fopen(path, "rb");
|
||||||
if(file == NULL){
|
if(file == NULL){
|
||||||
@@ -62,29 +63,31 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bytes = fread(buffer, sizeof(short), 3, file) != (3*szieof(short))){
|
if((bytes = fread(buffer, sizeof(short), 3, file)) != (3*sizeof(short))){
|
||||||
fprintf(stderr, "Couldn't read number of images/sizes of Images!\n");
|
fprintf(stderr, "Couldn't read number of images/sizes of Images!\n");
|
||||||
clearSeries(series);
|
clearSeries(series);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Merke menge an Bildern und Länge und Breite der Bilder
|
||||||
series->count = (short)buffer[0];
|
series->count = (short)buffer[0];
|
||||||
unsigned int width = (short)buffer[1];
|
unsigned int width = (short)buffer[1];
|
||||||
unsigned int height = (short)buffer[2];
|
unsigned int height = (short)buffer[2];
|
||||||
|
|
||||||
series->labels = calloc(count, sizeof(char));
|
series->labels = calloc(series->count, sizeof(char));
|
||||||
if(series->labels == NULL){
|
if(series->labels == NULL){
|
||||||
fprintf(stderr, "calloc failed!\n");
|
fprintf(stderr, "calloc failed!\n");
|
||||||
clearSeries(series);
|
clearSeries(series);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < count; i++){
|
//Lies Bilder aus
|
||||||
if(series->images[i] = readIndividualImage(width, heigth, file) == NULL){
|
for (int i = 0; i < series->count; i++){
|
||||||
|
if((series->images[i] = *readIndividualImage(width, height, file))){
|
||||||
clearSeries(series);
|
clearSeries(series);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fread(series->labels[i], sizeof(char), 1, file);
|
fread(&series->labels[i], sizeof(char), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return series;
|
return series;
|
||||||
@@ -94,7 +97,8 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
void clearSeries(GrayScaleImageSeries *series)
|
void clearSeries(GrayScaleImageSeries *series)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < series->count; i++){
|
for(int i = 0; i < series->count; i++){
|
||||||
free(series->GrayScaleImage[i]);
|
free(&series->images[i]);
|
||||||
}
|
}
|
||||||
|
free(series->labels);
|
||||||
free(series);
|
free(series);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user