forked from freudenreichan/info2Praktikum-NeuronalesNetz
neue Funktionen imageInput.c
This commit is contained in:
1 parent
5a285cf7e1
commit
69696064a5
1 file changed
+25
-9
+25
-9
@@ -18,13 +18,15 @@ static int validateFileHeader(FILE * file) {
|
||||
if (readbytes != headerlength) {
|
||||
return 0;
|
||||
}
|
||||
buffer[headerlength] == '\0';
|
||||
return (strcmp(buffer, FILE_HEADER_STRING) == 0);
|
||||
}
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||
GrayScaleImageSeries *readImages(const char *path)
|
||||
{
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
if (path == NULL) return NULL; //WARUM FEHLER, HEADERDATEIEN SIND DA!
|
||||
if (path == NULL) return NULL;
|
||||
FILE *file = fopen(path, "rb");
|
||||
if (file == NULL) {
|
||||
return NULL;
|
||||
@@ -47,33 +49,46 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//Speicher für die Bildserei
|
||||
GrayScaleImageSeries *series = (GrayScaleImageSeries *)malloc(sizeof(GrayScaleImageSeries));
|
||||
if (series == NULl) {
|
||||
|
||||
void pictureSeriesmemory();
|
||||
|
||||
int PicturesLabelsimport(&series);
|
||||
|
||||
}
|
||||
|
||||
//Speicher für Bildserei
|
||||
void pictureSeriesmemory() {
|
||||
|
||||
series = (GrayScaleImageSeries *)malloc(sizeof(GrayScaleImageSeries));
|
||||
if (series == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
series->count = (unsigned int)numImagesShort;
|
||||
series->count *= (unsigned int)numImagesShort;
|
||||
series->images = (GrayScaleImage*)malloc(series->count * sizeof(GrayScaleImage));
|
||||
series->labels = (unsigned char*)malloc(series->count * sizeof(unsigned char));
|
||||
|
||||
if (series->images == NULL || (series->count > 0 && series->labels == NULL)) {
|
||||
free(series->imapes);
|
||||
free(series->images);
|
||||
free(series->labels);
|
||||
free(series);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int pixelsPerImage = (unsigned int)widthShort * heigthShort;
|
||||
|
||||
//Bilder und Labels auslesen
|
||||
|
||||
//Bilder und Labels einlesen
|
||||
int PicturesLabelsimport(int series){
|
||||
|
||||
unsigned int pixelsPerImage = (unsigned int)widthShort * heightShort;
|
||||
for (unsigned int i = 0 < series->count; i++;) {
|
||||
series->images[i].width = (unsigned int)widthShort;
|
||||
series->images[i].height=(unsigned int)heightShort;
|
||||
series->images[i].buffer = (GrayScalePixelType *)malloc(pixelsPerImage * sizeof(GrayScalePixelType));
|
||||
|
||||
if (series->images.buffer == NULL) {
|
||||
if (series->images[i].buffer == NULL) {
|
||||
//Fehler -> zugewiesenen Speicher freigeben
|
||||
for (unsigned int j=0;j<i; j++) {
|
||||
free(series->images[j].buffer);
|
||||
@@ -113,6 +128,7 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
return series;
|
||||
}
|
||||
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
|
||||
void clearSeries(GrayScaleImageSeries *series)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user