imageInput now passes tests but still needs to be cleaned up
This commit is contained in:
parent
14569ad308
commit
d7fb02e6b4
76
imageInput.c
76
imageInput.c
@ -6,13 +6,23 @@
|
|||||||
#define BUFFER_SIZE 100
|
#define BUFFER_SIZE 100
|
||||||
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
#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
|
// Funktionen müssen noch auf Teilfunktionen
|
||||||
// übersichtlich aufgeteilt werden!
|
// übersichtlich aufgeteilt werden!
|
||||||
|
|
||||||
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||||
//void setupMemory();
|
//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);
|
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[]);
|
unsigned int checkHeaderString(char header[]);
|
||||||
|
|
||||||
|
|
||||||
@ -50,36 +60,46 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
} while (curChar != EOF);
|
} while (curChar != EOF);
|
||||||
// print entire source char by char
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
series = calloc(sizeof(unsigned int) + 3* sizeof(headerString), amountOfStatusInfoToRead);
|
series = calloc(sizeof(unsigned int) + 3* sizeof(headerString), amountOfStatusInfoToRead);
|
||||||
series->images = calloc(2*sizeof(unsigned int) + 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);
|
numberOfBytesToRead = readStatusInfo(readSource, headerString, &(series->count), &(series->images->width), &(series->images->height), amountOfStatusInfoToRead);
|
||||||
|
|
||||||
|
|
||||||
expectedHeader = checkHeaderString(headerString);
|
expectedHeader = checkHeaderString(headerString);
|
||||||
|
|
||||||
series->images->buffer = calloc((series->count) * numberOfBytesToRead + 1, sizeof(GrayScalePixelType));
|
series->images->buffer = calloc((series->count) * numberOfBytesToRead, sizeof(GrayScalePixelType));
|
||||||
series->labels = calloc((series->count) + 1, sizeof(&(series->labels)));
|
series->labels = calloc((series->count), sizeof(&(series->labels)));
|
||||||
|
|
||||||
if (expectedHeader)
|
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
|
// series->images[1].width is not being set
|
||||||
// implement setting several amoundt of status info
|
// implement setting several amoundt of status info
|
||||||
// for when several images are bing read
|
// for when several images are bing read
|
||||||
// also adjust amoung of memory allocated for
|
// also adjust amoung of memory allocated for
|
||||||
// staus info based on the number of images to be read
|
// staus info based on the number of images to be read
|
||||||
//printf("%d\n", series->images[1].width);
|
// printf("%d\n", series->images[1].width);
|
||||||
readImagedata(readSource, series->images->buffer, series->labels, series->count, numberOfBytesToRead);
|
readImagedata(readSource, series, numberOfBytesToRead);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("unexpected header!\n");
|
fclose(readSource);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fclose(readSource);
|
fclose(readSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,16 +111,20 @@ void clearSeries(GrayScaleImageSeries *series)
|
|||||||
{
|
{
|
||||||
int i = 0;
|
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++)
|
printf("count: %d ", series->count);
|
||||||
{
|
printf("width: %d ", series->images->width);
|
||||||
*(series->images->buffer + i * (series->images->width) * (series->images->height)) = '\0';
|
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++)
|
for (i = 0; i < (series->count); i++)
|
||||||
{
|
{
|
||||||
*(series->labels + i) = '\0';
|
*(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
|
// 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;
|
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(&(series->images->buffer[i]), 1, amountOfBytes, source);
|
||||||
fread((labelBuffer + i), sizeof(&(labelBuffer)), 1, 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[])
|
unsigned int checkHeaderString(char header[])
|
||||||
@ -184,7 +217,6 @@ unsigned int checkHeaderString(char header[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
printf("header identical? %d\n", !notIdenticall);
|
|
||||||
|
|
||||||
return !notIdenticall;
|
return !notIdenticall;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
some_tag
|
|
||||||
Loading…
x
Reference in New Issue
Block a user