Fehlerbehandlung Aktualisiert
This commit is contained in:
parent
e98bc885d9
commit
92744ae015
43
imageInput.c
43
imageInput.c
@ -12,9 +12,11 @@ static void einzelBild(unsigned char *px_ls, FILE *file, GrayScaleImageSeries *s
|
||||
bild.height = hoehe;
|
||||
bild.width = breite;
|
||||
bild.buffer = malloc(sizeof(GrayScalePixelType)*hoehe*breite);
|
||||
if(bild.buffer == NULL){
|
||||
return;
|
||||
}
|
||||
|
||||
int anz = fread(px_ls,sizeof(unsigned char), hoehe*breite +1, file);
|
||||
//printf("Test\n%d\n%d\n",anz, (breite*hoehe + 1));
|
||||
|
||||
if(anz == (breite*hoehe + 1)){
|
||||
series->labels[bildnummer] = px_ls[breite*hoehe];
|
||||
@ -42,16 +44,29 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
|
||||
|
||||
ausgelesen = malloc(sizeof(char)*BUFFER_SIZE);
|
||||
|
||||
if(anzahl_ls == NULL || breite_ls == NULL ||hoehe_ls == NULL || ausgelesen == NULL){
|
||||
return series;
|
||||
}
|
||||
|
||||
file = fopen(path,"rb");
|
||||
if(file==NULL){ //Fehlerbehandlung
|
||||
printf("Fehler bei File-Suche\n");
|
||||
free(anzahl_ls);
|
||||
free(breite_ls);
|
||||
free(hoehe_ls);
|
||||
free(ausgelesen);
|
||||
fclose(file);
|
||||
return series;
|
||||
}
|
||||
fread(ausgelesen,sizeof(char), strlen(FILE_HEADER_STRING), file);
|
||||
fread(ausgelesen,sizeof(unsigned char), strlen(FILE_HEADER_STRING), file);
|
||||
|
||||
if(strcmp(ausgelesen,FILE_HEADER_STRING)!=0){
|
||||
if(memcmp(ausgelesen,FILE_HEADER_STRING,strlen(FILE_HEADER_STRING))!=0){
|
||||
printf("Kein richtiger File-Header vorhanden\n");
|
||||
free(anzahl_ls);
|
||||
free(breite_ls);
|
||||
free(hoehe_ls);
|
||||
free(ausgelesen);
|
||||
fclose(file);
|
||||
return series;
|
||||
}
|
||||
@ -64,16 +79,35 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
breite = breite_ls[0];
|
||||
hoehe = hoehe_ls[0];
|
||||
series = malloc(sizeof(GrayScaleImageSeries)*(1+anzahl_ls[0]+anzahl_ls[0]*breite*hoehe));
|
||||
if(series == NULL){
|
||||
return series;
|
||||
}
|
||||
series->count = anzahl_ls[0];
|
||||
|
||||
//printf("%d\n%d\n%d\n",series->count, breite, hoehe);
|
||||
series->images = malloc(sizeof(GrayScaleImage)*series->count);
|
||||
series->labels = malloc(sizeof(unsigned char)*series->count);
|
||||
if (series->images == NULL || series->labels == NULL){
|
||||
free(anzahl_ls);
|
||||
free(breite_ls);
|
||||
free(hoehe_ls);
|
||||
free(ausgelesen);
|
||||
fclose(file);
|
||||
return series;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
px_ls = malloc(sizeof(GrayScalePixelType)*hoehe*breite +1); //Speicheranpassung für Einlese-Buffer
|
||||
if(px_ls == NULL){
|
||||
free(anzahl_ls);
|
||||
free(breite_ls);
|
||||
free(hoehe_ls);
|
||||
free(px_ls);
|
||||
free(ausgelesen);
|
||||
fclose(file);
|
||||
return series;
|
||||
}
|
||||
|
||||
for(int bildnummer=0; bildnummer <series->count;bildnummer++){
|
||||
einzelBild(px_ls, file, series, breite, hoehe, bildnummer);
|
||||
@ -100,7 +134,6 @@ void clearSeries(GrayScaleImageSeries *series)
|
||||
free(series->images[i].buffer);
|
||||
}
|
||||
}
|
||||
printf("Test\n");
|
||||
free(series->labels);
|
||||
free(series->images);
|
||||
free(series);
|
||||
|
||||
@ -13,11 +13,11 @@ static void prepareImageFile(const char *path, unsigned short int width, unsigne
|
||||
if(file != NULL)
|
||||
{
|
||||
const char *fileTag = "__info2_image_file_format__";
|
||||
GrayScalePixelType *zeroBuffer = (GrayScalePixelType *)calloc(numberOfImages * width * height, sizeof(GrayScalePixelType));
|
||||
GrayScalePixelType *zeroBuffer = calloc(width * height, sizeof(GrayScalePixelType));
|
||||
|
||||
if(zeroBuffer != NULL)
|
||||
{
|
||||
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
|
||||
fwrite(fileTag, sizeof(const char), strlen(fileTag), file);
|
||||
fwrite(&numberOfImages, sizeof(numberOfImages), 1, file);
|
||||
fwrite(&width, sizeof(width), 1, file);
|
||||
fwrite(&height, sizeof(height), 1, file);
|
||||
|
||||
23
matrix.c
23
matrix.c
@ -18,8 +18,9 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) {
|
||||
}
|
||||
matrix.rows = rows;
|
||||
matrix.cols = cols;
|
||||
memset(matrix.buffer, UNDEFINED_MATRIX_VALUE, rows*cols);
|
||||
|
||||
for (unsigned int i=0;i<rows*cols;i++){
|
||||
matrix.buffer[i] = UNDEFINED_MATRIX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return matrix;
|
||||
@ -27,19 +28,23 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) {
|
||||
|
||||
void clearMatrix(Matrix *matrix)
|
||||
{
|
||||
if(matrix != NULL){
|
||||
if(matrix->buffer != NULL)
|
||||
free(matrix->buffer);
|
||||
matrix->rows = 0;
|
||||
matrix->cols = 0;
|
||||
matrix->buffer = NULL;
|
||||
free(matrix->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
if(matrix.buffer != NULL){
|
||||
if(rowIdx<(matrix.rows) && colIdx<(matrix.cols)){
|
||||
matrix.buffer[matrix.cols*rowIdx + colIdx]=value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
@ -59,6 +64,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
output.rows = matrix1.rows;
|
||||
output.cols = matrix1.cols;
|
||||
output.buffer = malloc(sizeof(MatrixType)*output.rows*output.cols);
|
||||
if(output.buffer == NULL){
|
||||
return output;
|
||||
}
|
||||
for (int i=0;i<matrix1.rows*matrix1.cols;i++){
|
||||
output.buffer[i]= matrix1.buffer[i]+matrix2.buffer[i];
|
||||
}
|
||||
@ -67,6 +75,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
output.rows = matrix1.rows;
|
||||
output.cols = matrix1.cols;
|
||||
output.buffer = malloc(sizeof(MatrixType)*output.rows*output.cols);
|
||||
if(output.buffer == NULL){
|
||||
return output;
|
||||
}
|
||||
for (int i=0;i<matrix2.rows;i++){
|
||||
for (int ii=0;ii<matrix1.cols;ii++){
|
||||
output.buffer[(i*matrix1.cols)+ii]= matrix1.buffer[(i*matrix1.cols)+ii]+matrix2.buffer[i];
|
||||
@ -77,6 +88,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
output.rows = matrix2.rows;
|
||||
output.cols = matrix2.cols;
|
||||
output.buffer = malloc(sizeof(MatrixType)*output.rows*output.cols);
|
||||
if(output.buffer == NULL){
|
||||
return output;
|
||||
}
|
||||
for (int i=0;i<matrix1.rows;i++){
|
||||
for (int ii=0;ii<matrix2.cols;ii++){
|
||||
output.buffer[(i*matrix2.cols)+ii]= matrix2.buffer[(i*matrix2.cols)+ii]+matrix1.buffer[i];
|
||||
@ -93,6 +107,9 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
output.rows = matrix1.rows;
|
||||
output.cols = matrix2.cols;
|
||||
output.buffer = malloc(sizeof(MatrixType)*output.rows*output.cols);
|
||||
if(output.buffer == NULL){
|
||||
return output;
|
||||
}
|
||||
for (int spalte2=0;spalte2<output.cols;spalte2++){
|
||||
for (int zeile1=0;zeile1<matrix1.rows;zeile1++){
|
||||
for (int zeile2=0;zeile2<matrix2.rows;zeile2++){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user