generated from freudenreichan/info2Praktikum-NeuronalesNetz
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ee6db1268 | ||
|
|
ec8c735eb2 | ||
|
|
f6a813a635 | ||
|
|
82d72c5e90 | ||
|
|
0a549b7e0d | ||
|
|
c99db0f96c |
No files matched your search
+24
-4
@@ -37,20 +37,28 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
{
|
{
|
||||||
FILE* file = fopen(path, "rb");
|
FILE* file = fopen(path, "rb");
|
||||||
// TODO open binary file from file name
|
// TODO open binary file from file name
|
||||||
GrayScaleImageSeries *series = NULL;
|
GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries));
|
||||||
|
GrayScaleImage *image = malloc(sizeof(GrayScaleImage));
|
||||||
|
series->images = image;
|
||||||
if(!(checkString(file)))
|
if(!(checkString(file)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
unsigned int* imageCount = &(series->count); // sets a pointer for int variable count in struct
|
unsigned int* imageCount = &(series->count); // sets a pointer for int variable count in struct
|
||||||
|
printf("%d", *imageCount);
|
||||||
setParameters(file, imageCount, &(series->images->width), &(series->images->height));
|
unsigned int* width = &(series->images->width);
|
||||||
|
//printf("%d", *width);
|
||||||
|
setParameters(file, imageCount, width, &(series->images->height));
|
||||||
|
printf("BP3\n");
|
||||||
allocateMemory(series, *imageCount, series->images->width, series->images->height);
|
allocateMemory(series, *imageCount, series->images->width, series->images->height);
|
||||||
|
printf("BP4\n");
|
||||||
//allocateMemoryLabels();
|
//allocateMemoryLabels();
|
||||||
for(int i = (series->images->width * series->images->height) - 1; i <= 0; i--)
|
for(int i = (series->images->width * series->images->height) - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
fread(&(series->images->buffer[i]), sizeof(GrayScalePixelType), 1, file);
|
fread(&(series->images->buffer[i]), sizeof(GrayScalePixelType), 1, file);
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
printf("BP5\n");
|
||||||
return series;
|
return series;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,16 +72,28 @@ void clearSeries(GrayScaleImageSeries *series)
|
|||||||
}
|
}
|
||||||
series->images = NULL;
|
series->images = NULL;
|
||||||
series->labels = NULL;
|
series->labels = NULL;
|
||||||
|
|
||||||
|
free(series);
|
||||||
|
|
||||||
|
series = NULL;
|
||||||
}
|
}
|
||||||
void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height) { // sets the parameters
|
void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height) { // sets the parameters
|
||||||
|
printf("BP1");
|
||||||
char buffer[3];
|
char buffer[3];
|
||||||
|
|
||||||
fseek(file, 27, SEEK_SET);
|
fseek(file, 27, SEEK_SET);
|
||||||
fread(buffer, 1, 3, file);
|
fread(buffer, 1, 3, file);
|
||||||
|
|
||||||
*imageCount = (int) buffer[0];
|
*imageCount = (int) buffer[0];
|
||||||
|
|
||||||
|
|
||||||
*width = (int) buffer[1];
|
*width = (int) buffer[1];
|
||||||
|
|
||||||
*height = (int) buffer[2];
|
*height = (int) buffer[2];
|
||||||
|
printf("BP2\n");
|
||||||
|
printf("%d\n", *imageCount);
|
||||||
|
printf("%d\n", *width);
|
||||||
|
printf("%d\n", *height);
|
||||||
// TODO allocate memory for labels array (in imageInput.h) -> Done in allocate Memory
|
// TODO allocate memory for labels array (in imageInput.h) -> Done in allocate Memory
|
||||||
|
|
||||||
// TODO read from file and write in 2d arry, write label in labels array, repeat for imageCount -> done in readImages
|
// TODO read from file and write in 2d arry, write label in labels array, repeat for imageCount -> done in readImages
|
||||||
|
|||||||
@@ -108,11 +108,17 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
Matrix result;
|
Matrix result;
|
||||||
|
result.rows = 0;
|
||||||
|
result.cols = 0;
|
||||||
|
result.buffer = NULL;
|
||||||
|
|
||||||
|
if (matrix1.cols != matrix2.rows) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
result.rows = matrix1.rows;
|
result.rows = matrix1.rows;
|
||||||
result.cols = matrix2.cols;
|
result.cols = matrix2.cols;
|
||||||
|
|
||||||
if (matrix1.rows == matrix2.cols) {
|
|
||||||
|
|
||||||
result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType));
|
result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType));
|
||||||
|
|
||||||
for(int i = 0; i < result.rows; i++) {
|
for(int i = 0; i < result.rows; i++) {
|
||||||
@@ -121,11 +127,8 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|||||||
for(int k = 0; k < matrix1.cols; k++) {
|
for(int k = 0; k < matrix1.cols; k++) {
|
||||||
value += matrix1.buffer[i * matrix1.cols + k] * matrix2.buffer[k * matrix2.cols + j];
|
value += matrix1.buffer[i * matrix1.cols + k] * matrix2.buffer[k * matrix2.cols + j];
|
||||||
}
|
}
|
||||||
result.buffer[i * matrix1.cols + j] = value;
|
result.buffer[i * result.cols + j] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
printf("Die angegebenen Matrizen haben keine passenden Dimensionen für die Multiplikation");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user