generated from freudenreichan/info2Praktikum-NeuronalesNetz
Completed imageinput.c to the point that it does compile but doen't manage every test
This commit is contained in:
parent
7168681f1d
commit
c13c8bd6f6
18
imageInput.c
18
imageInput.c
@ -18,15 +18,16 @@ int checkString (FILE *file){ //Checks if String at the start of File equals exp
|
|||||||
rewind(file);
|
rewind(file);
|
||||||
size_t bytesRead = fread(actualString, 1,27 , file); //Stores Bytes of start of File to actualString
|
size_t bytesRead = fread(actualString, 1,27 , file); //Stores Bytes of start of File to actualString
|
||||||
if (bytesRead != 27){
|
if (bytesRead != 27){
|
||||||
return 0;} //Returns 0 if File is to short
|
return 0;
|
||||||
|
} //Returns 0 if File is to short
|
||||||
actualString[27] = '\0';
|
actualString[27] = '\0';
|
||||||
|
|
||||||
if (strcmp(actualString, expectedString) != 0){
|
if (strcmp(actualString, expectedString) != 0){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height);
|
void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height);
|
||||||
@ -44,7 +45,11 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
|
|
||||||
setParameters(file, imageCount, &(series->images->width), &(series->images->height));
|
setParameters(file, imageCount, &(series->images->width), &(series->images->height));
|
||||||
allocateMemory(series, *imageCount, series->images->width, series->images->height);
|
allocateMemory(series, *imageCount, series->images->width, series->images->height);
|
||||||
|
//allocateMemoryLabels();
|
||||||
|
for(int i = (series->images->width * series->images->height) - 1; i <= 0; i--)
|
||||||
|
{
|
||||||
|
fread(&(series->images->buffer[i]), sizeof(GrayScalePixelType), 1, file);
|
||||||
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return series;
|
return series;
|
||||||
}
|
}
|
||||||
@ -69,13 +74,14 @@ void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, un
|
|||||||
*imageCount = (int) buffer[0];
|
*imageCount = (int) buffer[0];
|
||||||
*width = (int) buffer[1];
|
*width = (int) buffer[1];
|
||||||
*height = (int) buffer[2];
|
*height = (int) buffer[2];
|
||||||
// TODO allocate memory for labels array (in imageInput.h)
|
// TODO allocate memory for labels array (in imageInput.h) -> Done in allocate Memory
|
||||||
|
|
||||||
// TODO read from file and write in 2d arry, write label in labels array, repeat for imageCount
|
// TODO read from file and write in 2d arry, write label in labels array, repeat for imageCount -> done in readImages
|
||||||
}
|
}
|
||||||
// change this to createMatrix?
|
// change this to createMatrix?
|
||||||
void allocateMemory(GrayScaleImageSeries* s, const int imageCount, const int width, const int height) {
|
void allocateMemory(GrayScaleImageSeries* s, const int imageCount, const int width, const int height) {
|
||||||
for (int i = 0; i < imageCount; i++) {
|
for (int i = 0; i < imageCount; i++) {
|
||||||
s->images[i].buffer = (unsigned char *) malloc(width * height * sizeof(unsigned char)); // allocates memory for every image in the series
|
s->images[i].buffer = (unsigned char *) malloc(width * height * sizeof(unsigned char)); // allocates memory for every image in the series
|
||||||
|
s->labels = malloc(width * height * sizeof(unsigned char));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user