Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c98197327 | ||
|
|
8368439db1 | ||
|
|
97bf884e59 |
47
imageInput.c
47
imageInput.c
@ -5,12 +5,59 @@
|
|||||||
|
|
||||||
#define BUFFER_SIZE 100
|
#define BUFFER_SIZE 100
|
||||||
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
||||||
|
#define FILE_HEADER_SIZE (sizeof(FILE_HEADER_STRING)-1)
|
||||||
|
|
||||||
|
|
||||||
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||||
|
FILE *checkFile(const char *path)
|
||||||
|
{
|
||||||
|
FILE *datei = fopen(path,"rb");
|
||||||
|
if (datei == NULL)
|
||||||
|
{
|
||||||
|
perror("Datei konnte nicht geoeffnet werden");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
char buffer[FILE_HEADER_SIZE+1];
|
||||||
|
if (fread(buffer,1,FILE_HEADER_SIZE,datei)!=FILE_HEADER_SIZE)
|
||||||
|
{
|
||||||
|
perror("Header konnte nicht eingelessen werden");
|
||||||
|
fclose(datei);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
buffer[FILE_HEADER_SIZE] = '\0';
|
||||||
|
if (strcmp(buffer,FILE_HEADER_STRING)!=0)
|
||||||
|
{
|
||||||
|
printf("Falscher Dateikopf");
|
||||||
|
//printf("\n%s",buffer);
|
||||||
|
//printf("\n%s",FILE_HEADER_STRING);
|
||||||
|
//printf("\n%d",strcmp(buffer,FILE_HEADER_STRING));
|
||||||
|
fclose(datei);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return datei;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||||
GrayScaleImageSeries *readImages(const char *path)
|
GrayScaleImageSeries *readImages(const char *path)
|
||||||
{
|
{
|
||||||
|
FILE *datei = checkFile(path);
|
||||||
|
if (datei==NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
unsigned short image_count, width, height;
|
||||||
|
fread(&image_count,1,sizeof(unsigned short),datei);
|
||||||
|
fread(&width,1,sizeof(unsigned short),datei);
|
||||||
|
fread(&height,1,sizeof(unsigned short),datei);
|
||||||
|
//printf("%u Bilder und %u mal %u",image_count,width,height);
|
||||||
|
|
||||||
|
fclose(datei);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GrayScaleImageSeries *series = NULL;
|
GrayScaleImageSeries *series = NULL;
|
||||||
|
|
||||||
return series;
|
return series;
|
||||||
|
|||||||
@ -19,5 +19,5 @@ typedef struct
|
|||||||
|
|
||||||
GrayScaleImageSeries *readImages(const char *path);
|
GrayScaleImageSeries *readImages(const char *path);
|
||||||
void clearSeries(GrayScaleImageSeries *series);
|
void clearSeries(GrayScaleImageSeries *series);
|
||||||
|
FILE *checkFile(const char *path);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
7
main.c
7
main.c
@ -1,11 +1,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "imageInput.h"
|
#include "imageInput.h"
|
||||||
#include "mnistVisualization.h"
|
//#include "mnistVisualization.h"
|
||||||
#include "neuralNetwork.h"
|
//#include "neuralNetwork.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
readImages("mnist_test.info2");
|
||||||
|
/*
|
||||||
const unsigned int windowWidth = 800;
|
const unsigned int windowWidth = 800;
|
||||||
const unsigned int windowHeight = 600;
|
const unsigned int windowHeight = 600;
|
||||||
|
|
||||||
@ -65,4 +67,5 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
49
matrix.c
49
matrix.c
@ -6,30 +6,67 @@
|
|||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
|
// Allocate memory for the matrix structure
|
||||||
|
Matrix matrix;
|
||||||
|
matrix.rows = rows;
|
||||||
|
matrix.cols = cols;
|
||||||
|
matrix.data = (MatrixType *)malloc(rows * cols * sizeof(MatrixType));
|
||||||
|
if (matrix.data == NULL)
|
||||||
|
{
|
||||||
|
// Handle memory allocation failure
|
||||||
|
matrix.rows = 0;
|
||||||
|
matrix.cols = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearMatrix(Matrix *matrix)
|
void clearMatrix(Matrix *matrix)
|
||||||
{
|
{
|
||||||
|
// Free the allocated memory for the matrix data
|
||||||
|
if (matrix->data != NULL)
|
||||||
|
{
|
||||||
|
free(matrix->data);
|
||||||
|
matrix->data = NULL;
|
||||||
|
matrix->rows = 0;
|
||||||
|
matrix->cols = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
|
// Set the value at the specified row and column index
|
||||||
|
if (rowIdx < matrix.rows && colIdx < matrix.cols)
|
||||||
|
{
|
||||||
|
matrix.data[rowIdx * matrix.cols + colIdx] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
|
// Get the value at the specified row and column index
|
||||||
|
if (rowIdx < matrix.rows && colIdx < matrix.cols)
|
||||||
|
{
|
||||||
|
return matrix.data[rowIdx * matrix.cols + colIdx];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
|
// Add two matrices and return the result
|
||||||
|
if (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
|
||||||
|
{
|
||||||
|
// Handle dimension mismatch
|
||||||
|
Matrix emptyMatrix = createMatrix(0, 0);
|
||||||
|
return emptyMatrix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
|
// Multiply two matrices and return the result
|
||||||
|
if (matrix1.cols != matrix2.rows)
|
||||||
|
{
|
||||||
|
// Handle dimension mismatch
|
||||||
|
Matrix emptyMatrix = createMatrix(0, 0);
|
||||||
|
return emptyMatrix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
6
matrix.h
6
matrix.h
@ -6,6 +6,12 @@
|
|||||||
typedef float MatrixType;
|
typedef float MatrixType;
|
||||||
|
|
||||||
// TODO Matrixtyp definieren
|
// TODO Matrixtyp definieren
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned int rows;
|
||||||
|
unsigned int cols;
|
||||||
|
MatrixType *data;
|
||||||
|
} Matrix;
|
||||||
|
|
||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user