found mistake in imageInput.c
This commit is contained in:
parent
f149efb86a
commit
c19508d6b2
25
imageInput.c
25
imageInput.c
@ -29,8 +29,8 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
|
||||
if (readSource != NULL)
|
||||
{
|
||||
series = calloc(3 * sizeof(unsigned int) + 3*sizeof(headerString), amountOfStatusInfoToRead);
|
||||
series->images = calloc(2 * sizeof(unsigned int) + sizeof(headerString), amountOfStatusInfoToRead);
|
||||
series = calloc(amountOfStatusInfoToRead, 3 * sizeof(unsigned int) + 3 * sizeof(headerString));
|
||||
series->images = calloc(amountOfStatusInfoToRead, 2 * sizeof(unsigned int) + sizeof(headerString));
|
||||
|
||||
numberOfBytesToRead = readStatusInfo(readSource, series, headerString, sizeOfStausInfoElementsInBytes, amountOfStatusInfoToRead);
|
||||
|
||||
@ -45,14 +45,21 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
// 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 loop was previously running with i < series->count, wich caused programm to crash.
|
||||
/*
|
||||
for (int i = 1; i < series->count; i++)
|
||||
{
|
||||
(series->images + i * sizeof(series->images)) = calloc(1, (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;
|
||||
}
|
||||
|
||||
|
||||
readImagedata(readSource, series, numberOfBytesToRead);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -122,15 +129,15 @@ unsigned int readStatusInfo(FILE *const source, GrayScaleImageSeries *const seri
|
||||
|
||||
|
||||
// reads the imagebytes and the label of all images
|
||||
void readImagedata(FILE *const source, GrayScaleImageSeries *const series, int const amountOfBytes)
|
||||
void readImagedata(FILE *const source, GrayScaleImageSeries *const series, int const amountToRead)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < series->count ; i++)
|
||||
{
|
||||
fread(&(series->images->buffer[i]), sizeof(*series->images->buffer), amountOfBytes, source);
|
||||
fread(&(series->labels[i]), sizeof(*series->images->buffer), sizeof(*series->labels), source);
|
||||
printf("%d\n", i);
|
||||
fread(&(series->images[i].buffer), sizeof(*series->images->buffer), amountToRead, source);
|
||||
fread(&(series->labels[i]), sizeof(*series->images->buffer), sizeof(*series->labels), source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
32
matrix.c
32
matrix.c
@ -41,31 +41,25 @@ void clearMatrix(Matrix *matrix)
|
||||
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
// printf("hier0\n");
|
||||
if(matrix.buffer == NULL)
|
||||
{
|
||||
//printf("Fehler beim Setzen! Matrix nicht initialisiert");
|
||||
// printf("Fehler beim Setzen! Matrix nicht initialisiert");
|
||||
return;
|
||||
}
|
||||
|
||||
// printf("rowIdx %d\n", rowIdx);
|
||||
// printf("mat.row %d\n", matrix.rows);
|
||||
// printf("colIdx %d\n", colIdx);
|
||||
// printf("mat.cols %d\n", matrix.cols);
|
||||
|
||||
|
||||
if(rowIdx >= matrix.rows || colIdx >= matrix.cols)
|
||||
{
|
||||
//printf("Ungueltige Indizes beim Setzen!\n");
|
||||
// printf("Ungueltige Indizes beim Setzen!\n");
|
||||
return;
|
||||
}
|
||||
// printf("%d \n", rowIdx + matrix.rows * colIdx);
|
||||
*(&matrix.buffer[0] + colIdx * matrix.rows + rowIdx) = value;
|
||||
// printf("value %f\n", value);
|
||||
// printf("hier1\n");
|
||||
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
|
||||
// printf("hier2\n");
|
||||
}
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
float wert = 0;
|
||||
|
||||
if(matrix.buffer == NULL)
|
||||
{
|
||||
//printf("Fehler beim Lesen! Matrix nicht initialisiert");
|
||||
@ -78,11 +72,7 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
||||
return 0;
|
||||
}
|
||||
|
||||
wert = matrix.buffer[rowIdx * matrix.cols + colIdx];
|
||||
//printf("wert row %d col %d: %f\n", rowIdx, colIdx, *(&matrix.buffer[0] + colIdx * matrix.cols + rowIdx));
|
||||
//printf("geholter wert = %f\n", wert);
|
||||
|
||||
return wert;
|
||||
return matrix.buffer[rowIdx * matrix.cols + colIdx];
|
||||
}
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
@ -165,9 +155,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("Fehler bei Addition: Matrix Dimensionen stimmen nicht ueberein!\n");
|
||||
Matrix empty = {0, 0, NULL};
|
||||
return empty;
|
||||
//printf("Fehler bei Addition: Matrix Dimensionen stimmen nicht ueberein!\n");
|
||||
Matrix empty = {0, 0, NULL};
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -182,6 +182,7 @@ static Matrix imageBatchToMatrixOfImageVectors(const GrayScaleImage images[], un
|
||||
{
|
||||
for(int j = 0; j < images[i].width * images[i].height; j++)
|
||||
{
|
||||
// printf("i %d, j %d \n", i,j);
|
||||
setMatrixAt((MatrixType)images[i].buffer[j], matrix, j, i);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user