found mistake in imageInput.c
This commit is contained in:
parent
f149efb86a
commit
c19508d6b2
19
imageInput.c
19
imageInput.c
@ -29,8 +29,8 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
|
|
||||||
if (readSource != NULL)
|
if (readSource != NULL)
|
||||||
{
|
{
|
||||||
series = calloc(3 * sizeof(unsigned int) + 3*sizeof(headerString), amountOfStatusInfoToRead);
|
series = calloc(amountOfStatusInfoToRead, 3 * sizeof(unsigned int) + 3 * sizeof(headerString));
|
||||||
series->images = calloc(2 * sizeof(unsigned int) + sizeof(headerString), amountOfStatusInfoToRead);
|
series->images = calloc(amountOfStatusInfoToRead, 2 * sizeof(unsigned int) + sizeof(headerString));
|
||||||
|
|
||||||
numberOfBytesToRead = readStatusInfo(readSource, series, headerString, sizeOfStausInfoElementsInBytes, amountOfStatusInfoToRead);
|
numberOfBytesToRead = readStatusInfo(readSource, series, headerString, sizeOfStausInfoElementsInBytes, amountOfStatusInfoToRead);
|
||||||
|
|
||||||
@ -45,7 +45,13 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
// reallocate memory so that each image width can be saved seperately
|
// reallocate memory so that each image width can be saved seperately
|
||||||
series->images = realloc(series->images, series->count * (2 * sizeof(unsigned int) + sizeof(headerString)));
|
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++)
|
for (int i = 0; i < series->count; i++)
|
||||||
{
|
{
|
||||||
series->images[i].width = series->images->width;
|
series->images[i].width = series->images->width;
|
||||||
@ -53,6 +59,7 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
readImagedata(readSource, series, numberOfBytesToRead);
|
readImagedata(readSource, series, numberOfBytesToRead);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -122,14 +129,14 @@ unsigned int readStatusInfo(FILE *const source, GrayScaleImageSeries *const seri
|
|||||||
|
|
||||||
|
|
||||||
// reads the imagebytes and the label of all images
|
// 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;
|
int i = 0;
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < series->count ; i++)
|
for (i = 0; i < series->count ; i++)
|
||||||
{
|
{
|
||||||
fread(&(series->images->buffer[i]), sizeof(*series->images->buffer), amountOfBytes, 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);
|
fread(&(series->labels[i]), sizeof(*series->images->buffer), sizeof(*series->labels), source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
matrix.c
20
matrix.c
@ -41,31 +41,25 @@ void clearMatrix(Matrix *matrix)
|
|||||||
|
|
||||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
|
// printf("hier0\n");
|
||||||
if(matrix.buffer == NULL)
|
if(matrix.buffer == NULL)
|
||||||
{
|
{
|
||||||
// printf("Fehler beim Setzen! Matrix nicht initialisiert");
|
// printf("Fehler beim Setzen! Matrix nicht initialisiert");
|
||||||
return;
|
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)
|
if(rowIdx >= matrix.rows || colIdx >= matrix.cols)
|
||||||
{
|
{
|
||||||
// printf("Ungueltige Indizes beim Setzen!\n");
|
// printf("Ungueltige Indizes beim Setzen!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// printf("%d \n", rowIdx + matrix.rows * colIdx);
|
// printf("hier1\n");
|
||||||
*(&matrix.buffer[0] + colIdx * matrix.rows + rowIdx) = value;
|
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
|
||||||
// printf("value %f\n", value);
|
// printf("hier2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
float wert = 0;
|
|
||||||
|
|
||||||
if(matrix.buffer == NULL)
|
if(matrix.buffer == NULL)
|
||||||
{
|
{
|
||||||
//printf("Fehler beim Lesen! Matrix nicht initialisiert");
|
//printf("Fehler beim Lesen! Matrix nicht initialisiert");
|
||||||
@ -78,11 +72,7 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wert = matrix.buffer[rowIdx * matrix.cols + colIdx];
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||||
|
|||||||
@ -182,6 +182,7 @@ static Matrix imageBatchToMatrixOfImageVectors(const GrayScaleImage images[], un
|
|||||||
{
|
{
|
||||||
for(int j = 0; j < images[i].width * images[i].height; j++)
|
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);
|
setMatrixAt((MatrixType)images[i].buffer[j], matrix, j, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user