Ergängzungen, kleine Änderungen
This commit is contained in:
parent
0ded688dae
commit
a7ce1d0897
18
imageInput.c
18
imageInput.c
@ -45,7 +45,7 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned short count = read(file); //lesen immer 2 Bits aus datei
|
||||
unsigned short count = read(file); //lesen immer 2 Bits aus datei, string wurde oben schon gelesen, fread merkt sich
|
||||
unsigned short weite = read(file);
|
||||
unsigned short höhe = read(file);
|
||||
|
||||
@ -57,7 +57,7 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries)); //reserviert Speicher
|
||||
if (!series) { fclose(file); return NULL; }
|
||||
|
||||
series->count = count; //auch(*series)count = count; speichert anzahl
|
||||
series->count = count; //auch(*series)count = count; speichert anzahl, kein speicher reservieren
|
||||
series->labels = malloc(count * sizeof(unsigned char)); //speicher bilder
|
||||
series->images = malloc(count * sizeof(GrayScaleImage)); //speicher für Bildstrukturen
|
||||
if (!series->labels || !series->images) { //geklappt?
|
||||
@ -68,21 +68,21 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
return NULL;
|
||||
}
|
||||
for (unsigned int i = 0; i < count; i++) { //liest alle bilder ein
|
||||
GrayScaleImage *img = &series->images[i]; //Zeiger auf aktuelles Bild
|
||||
img->width = weite; //speichert Werte von diesem Bild
|
||||
img->height = höhe;
|
||||
GrayScaleImage *bild = &series->images[i]; //Zeiger auf aktuelles Bild
|
||||
bild->width = weite; //speichert Werte von diesem Bild
|
||||
bild->height = höhe;
|
||||
|
||||
size_t pixels = (size_t)weite * (size_t)höhe;
|
||||
img->buffer = malloc(pixels * sizeof(GrayScalePixelType)); //speicherwerte für Pixel
|
||||
bild->buffer = malloc(pixels * sizeof(GrayScalePixelType)); //speicherwerte für Pixel
|
||||
|
||||
|
||||
if (!img->buffer) { //geklappt?
|
||||
if (!bild->buffer) { //geklappt?
|
||||
fclose(file);
|
||||
clearSeries(series);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fread(img->buffer, sizeof(GrayScalePixelType), weite * höhe, file) != weite * höhe) { // liest Pixelwerte aus Datei, speichert in Puffer
|
||||
if (fread(bild->buffer, sizeof(GrayScalePixelType), weite * höhe, file) != weite * höhe) { // liest Pixelwerte aus Datei, speichert in Puffer
|
||||
fclose(file);
|
||||
clearSeries(series);
|
||||
return NULL;
|
||||
@ -107,7 +107,7 @@ for (unsigned int i = 0; i < count; i++) { //liest alle bilder ein
|
||||
void clearSeries(GrayScaleImageSeries *series)
|
||||
{
|
||||
if (!series) return;
|
||||
for (unsigned int i = 0; i < series->count; i++) {
|
||||
for (unsigned int i = 0; i < series->count; i++) { //ale Bilder leeren
|
||||
free(series->images[i].buffer);
|
||||
}
|
||||
free(series->images);
|
||||
|
||||
10
matrix.c
10
matrix.c
@ -36,7 +36,7 @@ void clearMatrix(Matrix *matrix)
|
||||
|
||||
|
||||
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) //setzt einen bestimmten wert in die Matrix
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) //setzt einen bestimmten wert in die Matrix, MatrixType ist float!
|
||||
{
|
||||
if(matrix.buffer == NULL || matrix.rows ==0 || matrix.cols ==0) //leere Matrix -> abbruch
|
||||
return;
|
||||
@ -53,10 +53,10 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
|
||||
|
||||
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) //gibt Wert an Stelle zurück
|
||||
{
|
||||
if(matrix.buffer == NULL || matrix.rows ==0 || matrix.cols ==0) //leere Matrix -> abbruch
|
||||
return UNDEFINED_MATRIX_VALUE;
|
||||
return UNDEFINED_MATRIX_VALUE; //ist 0
|
||||
|
||||
if(rowIdx >= matrix.rows|| colIdx >= matrix.cols) //Wert außerhalb?
|
||||
return UNDEFINED_MATRIX_VALUE;
|
||||
@ -132,7 +132,7 @@ if(matrix1.buffer == NULL || matrix2.buffer == NULL) //Matrix leer?
|
||||
if (matrix1.cols != matrix2.rows) //Anzahl Spalten von 1. Matrix muss mit Anzahl Zeilen 2. Matrix übereinstimmen
|
||||
return result;
|
||||
|
||||
//unsigned entfernt?
|
||||
|
||||
int rows = matrix1.rows; // mxn nxp -> neu: mxp
|
||||
int cols = matrix2.cols;
|
||||
int inner = matrix1.cols;
|
||||
@ -145,7 +145,7 @@ for(unsigned int i = 0; i < rows; i++)
|
||||
{
|
||||
for(unsigned int j = 0; j < cols; j++)
|
||||
{
|
||||
MatrixType sum = 0; //MatrixType, damit man die art der varianle automatisch an die Matrix anpasst in .h
|
||||
MatrixType sum = 0; //MatrixType ist float, damit man die art der varianle automatisch an die Matrix anpasst in .h
|
||||
|
||||
for(unsigned int k = 0; k < inner; k++)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user