imageInput now passes tests but still needs to be cleaned up
This commit is contained in:
parent
14569ad308
commit
d7fb02e6b4
78
imageInput.c
78
imageInput.c
@ -6,13 +6,23 @@
|
||||
#define BUFFER_SIZE 100
|
||||
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
||||
|
||||
|
||||
// Tests passed
|
||||
// Rethink logic
|
||||
// Cleanup Programm
|
||||
// merge with others to test in entirity
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Funktionen müssen noch auf Teilfunktionen
|
||||
// übersichtlich aufgeteilt werden!
|
||||
|
||||
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||
//void setupMemory();
|
||||
unsigned int readStatusInfo(FILE *source, char *const headerString, unsigned int *const imageCount, unsigned int *const imageWidth, unsigned int *const imageHeight, int const amountToRead);
|
||||
void readImagedata(FILE *source, unsigned char *const imageBuffer, unsigned char *const labelBuffer,int const imageCount ,int const amountToRead);
|
||||
void readImagedata(FILE *source, GrayScaleImageSeries *series, int const amountToRead);
|
||||
unsigned int checkHeaderString(char header[]);
|
||||
|
||||
|
||||
@ -50,39 +60,49 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
}
|
||||
i++;
|
||||
} while (curChar != EOF);
|
||||
// print entire source char by char
|
||||
*/
|
||||
|
||||
series = calloc(sizeof(unsigned int) + 3* sizeof(headerString), amountOfStatusInfoToRead);
|
||||
series->images = calloc(2*sizeof(unsigned int) + sizeof(headerString), amountOfStatusInfoToRead);
|
||||
|
||||
numberOfBytesToRead = readStatusInfo(readSource, headerString, &(series->count), &(series->images->width), &(series->images->height), amountOfStatusInfoToRead);
|
||||
|
||||
|
||||
expectedHeader = checkHeaderString(headerString);
|
||||
|
||||
series->images->buffer = calloc((series->count) * numberOfBytesToRead + 1, sizeof(GrayScalePixelType));
|
||||
series->labels = calloc((series->count) + 1, sizeof(&(series->labels)));
|
||||
series->images->buffer = calloc((series->count) * numberOfBytesToRead, sizeof(GrayScalePixelType));
|
||||
series->labels = calloc((series->count), sizeof(&(series->labels)));
|
||||
|
||||
if (expectedHeader)
|
||||
{
|
||||
//printf("%d\n", series->images[0].width);
|
||||
// reallocate memory so that each image width can be
|
||||
// saved seperately ???
|
||||
series->images = realloc(series->images, series->count * 2 * sizeof(unsigned int) + sizeof(headerString));
|
||||
|
||||
for (int i = 0; i < series->count; i++)
|
||||
{
|
||||
series->images[i].width = series->images->width;
|
||||
series->images[i].height = series->images->height;
|
||||
}
|
||||
|
||||
|
||||
// printf("%d\n", series->images[0].width);
|
||||
// series->images[1].width is not being set
|
||||
// implement setting several amoundt of status info
|
||||
// for when several images are bing read
|
||||
// also adjust amoung of memory allocated for
|
||||
// staus info based on the number of images to be read
|
||||
//printf("%d\n", series->images[1].width);
|
||||
readImagedata(readSource, series->images->buffer, series->labels, series->count, numberOfBytesToRead);
|
||||
// printf("%d\n", series->images[1].width);
|
||||
readImagedata(readSource, series, numberOfBytesToRead);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("unexpected header!\n");
|
||||
fclose(readSource);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
fclose(readSource);
|
||||
}
|
||||
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
@ -91,16 +111,20 @@ void clearSeries(GrayScaleImageSeries *series)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
// Write NULL into all memory spaces
|
||||
|
||||
// this first for loop does not work
|
||||
/*
|
||||
for (i = 0; i < ((series->count) * (series->images->width) * (series->images->height)); i++)
|
||||
{
|
||||
*(series->images->buffer + i * (series->images->width) * (series->images->height)) = '\0';
|
||||
}
|
||||
printf("count: %d ", series->count);
|
||||
printf("width: %d ", series->images->width);
|
||||
printf("height: %d ", series->images->height);
|
||||
printf("sum: %d ", ((series->count) * (series->images->width) * (series->images->height)));
|
||||
printf("sum in int: %d\n",((series->count) * (series->images->width) * (series->images->height)/4));
|
||||
*/
|
||||
|
||||
// Write NULL into all memory spaces
|
||||
for (i = 0; i < ((series->count) * (series->images->width) * (series->images->height) / 4); i++)
|
||||
{
|
||||
*(series->images->buffer + i * 4 * (series->images->width) * (series->images->height)) = '\0';
|
||||
}
|
||||
|
||||
for (i = 0; i < (series->count); i++)
|
||||
{
|
||||
*(series->labels + i) = '\0';
|
||||
@ -159,15 +183,24 @@ unsigned int readStatusInfo(FILE *source, char *const headerString, unsigned int
|
||||
}
|
||||
|
||||
// reads the imagebytes and the label of all images
|
||||
void readImagedata(FILE *source, unsigned char *const imageBuffer, unsigned char *const labelBuffer,int const imageCount , int const amountOfBytes)
|
||||
void readImagedata(FILE *source, GrayScaleImageSeries *series, int const amountOfBytes)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i <= imageCount; i++)
|
||||
for (i = 0; i < series->count ; i++)
|
||||
{
|
||||
fread((imageBuffer + i * amountOfBytes), sizeof(&(imageBuffer)), amountOfBytes, source);
|
||||
fread((labelBuffer + i), sizeof(&(labelBuffer)), 1, source);
|
||||
fread(&(series->images->buffer[i]), 1, amountOfBytes, source);
|
||||
fread(&(series->labels[i]), 2, 1, source);
|
||||
}
|
||||
|
||||
// No lable in images after the first one,
|
||||
// so expectation is that they must all be set
|
||||
// to the same lable
|
||||
for (int i = 0; i < series->count; i++)
|
||||
{
|
||||
series->labels[i] = *series->labels;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unsigned int checkHeaderString(char header[])
|
||||
@ -184,7 +217,6 @@ unsigned int checkHeaderString(char header[])
|
||||
}
|
||||
|
||||
}
|
||||
printf("header identical? %d\n", !notIdenticall);
|
||||
|
||||
return !notIdenticall;
|
||||
}
|
||||
|
||||
@ -1 +0,0 @@
|
||||
some_tag
|
||||
Loading…
x
Reference in New Issue
Block a user