generated from freudenreichan/info2Praktikum-NeuronalesNetz
finale Version
This commit is contained in:
parent
1ba120628e
commit
1ca7e7b955
22
imageInput.c
22
imageInput.c
@ -10,15 +10,11 @@
|
|||||||
|
|
||||||
static void readPictureData(FILE *file, unsigned short *ptrPicturesCount, unsigned short *ptrPictureWidth, unsigned short *ptrPictureHeight)
|
static void readPictureData(FILE *file, unsigned short *ptrPicturesCount, unsigned short *ptrPictureWidth, unsigned short *ptrPictureHeight)
|
||||||
{
|
{
|
||||||
unsigned int header = strlen(FILE_HEADER_STRING);
|
|
||||||
|
|
||||||
fseek(file, header, SEEK_SET);
|
|
||||||
|
|
||||||
fread(ptrPicturesCount, sizeof(unsigned short), 1, file);
|
fread(ptrPicturesCount, sizeof(unsigned short), 1, file);
|
||||||
fread(ptrPictureWidth, sizeof(unsigned short), 1, file);
|
fread(ptrPictureWidth, sizeof(unsigned short), 1, file);
|
||||||
fread(ptrPictureHeight, sizeof(unsigned short), 1, file);
|
fread(ptrPictureHeight, sizeof(unsigned short), 1, file);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -27,28 +23,39 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
{
|
{
|
||||||
unsigned short picturesCount, pictureWidth, pictureHeight;
|
unsigned short picturesCount, pictureWidth, pictureHeight;
|
||||||
GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries));
|
GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries));
|
||||||
char line[26];
|
char line[strlen(FILE_HEADER_STRING)+1];
|
||||||
|
|
||||||
FILE *file = fopen(path,"rb");
|
FILE *file = fopen(path,"rb");
|
||||||
|
|
||||||
|
//Prüfen auf erfolgreiches Öffnen der Datei
|
||||||
|
|
||||||
if (file == NULL){
|
if (file == NULL){
|
||||||
printf("failed open file\n");
|
printf("failed open file\n");
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(line, sizeof(line), 1, file);
|
//Prüfen auf übereinstimmung des headers
|
||||||
|
|
||||||
|
fread(line,1, strlen(FILE_HEADER_STRING), file);
|
||||||
|
|
||||||
|
line[strlen(FILE_HEADER_STRING)] = '\0';
|
||||||
|
|
||||||
if(strncmp(line, FILE_HEADER_STRING, strlen(FILE_HEADER_STRING))!=0)return NULL;
|
if(strncmp(line, FILE_HEADER_STRING, strlen(FILE_HEADER_STRING))!=0)return NULL;
|
||||||
|
|
||||||
fseek(file, 0, SEEK_SET);
|
|
||||||
|
|
||||||
|
|
||||||
|
//Anzahl, Breite und Höhe der Bilder einlesen
|
||||||
|
|
||||||
readPictureData(file, &picturesCount, &pictureWidth, &pictureHeight);
|
readPictureData(file, &picturesCount, &pictureWidth, &pictureHeight);
|
||||||
|
|
||||||
|
//Speicher für lables und images zuornden
|
||||||
|
|
||||||
series->labels = (unsigned char*)malloc(picturesCount * sizeof(char));
|
series->labels = (unsigned char*)malloc(picturesCount * sizeof(char));
|
||||||
series->images = (GrayScaleImage*)malloc(picturesCount * sizeof(GrayScaleImage));
|
series->images = (GrayScaleImage*)malloc(picturesCount * sizeof(GrayScaleImage));
|
||||||
series->count = picturesCount;
|
series->count = picturesCount;
|
||||||
|
|
||||||
|
//speicher reservierung für images und Einlesen der Bilddaten und labels
|
||||||
for(int i = 0; i < picturesCount; i++){
|
for(int i = 0; i < picturesCount; i++){
|
||||||
series->images[i].width = pictureWidth;
|
series->images[i].width = pictureWidth;
|
||||||
series->images[i].height = pictureHeight;
|
series->images[i].height = pictureHeight;
|
||||||
@ -74,4 +81,5 @@ void clearSeries(GrayScaleImageSeries *series)
|
|||||||
|
|
||||||
free(series->images);
|
free(series->images);
|
||||||
free(series->labels);
|
free(series->labels);
|
||||||
|
free(series);
|
||||||
}
|
}
|
||||||
|
|||||||
12
matrix.c
12
matrix.c
@ -7,11 +7,11 @@
|
|||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
if(rows <= 0 || cols <= 0){
|
if(rows <= 0 || cols <= 0){
|
||||||
Matrix matrix = { 0 , 0 , UNDEFINED_MATRIX_VALUE };
|
Matrix matrix = { NULL , 0 , UNDEFINED_MATRIX_VALUE };
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix matrix = { rows , cols };
|
Matrix matrix = { 0 ,rows , cols };
|
||||||
|
|
||||||
matrix.buffer = malloc((sizeof(MatrixType)*rows*cols));
|
matrix.buffer = malloc((sizeof(MatrixType)*rows*cols));
|
||||||
|
|
||||||
@ -47,6 +47,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
{
|
{
|
||||||
int matrixResultCols;
|
int matrixResultCols;
|
||||||
|
|
||||||
|
//abgleichen welche matrix die größere spalten anzahl besitzt
|
||||||
if(matrix1.cols <= matrix2.cols){
|
if(matrix1.cols <= matrix2.cols){
|
||||||
matrixResultCols = matrix2.cols;
|
matrixResultCols = matrix2.cols;
|
||||||
}
|
}
|
||||||
@ -54,8 +55,10 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
matrixResultCols = matrix1.cols;
|
matrixResultCols = matrix1.cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Matrix für das ergebnis generieren
|
||||||
Matrix result = createMatrix(matrix1.rows, matrixResultCols);
|
Matrix result = createMatrix(matrix1.rows, matrixResultCols);
|
||||||
|
|
||||||
|
//prüfen auf gleiche Reihenanzahl
|
||||||
if(matrix1.rows != matrix2.rows){
|
if(matrix1.rows != matrix2.rows){
|
||||||
|
|
||||||
result.buffer = NULL;
|
result.buffer = NULL;
|
||||||
@ -64,6 +67,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Addition bei gleicher spalten Anzahl
|
||||||
if(matrix1.cols == matrix2.cols){
|
if(matrix1.cols == matrix2.cols){
|
||||||
for(int i = 0; i < matrix1.rows; i++){
|
for(int i = 0; i < matrix1.rows; i++){
|
||||||
for(int j = 0; j < matrix1.cols; j++){
|
for(int j = 0; j < matrix1.cols; j++){
|
||||||
@ -72,6 +76,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Addition wenn matrix1 nur eine Spalte hat
|
||||||
if((matrix1.cols ==1 && matrix2.cols != 1)){
|
if((matrix1.cols ==1 && matrix2.cols != 1)){
|
||||||
for(int i = 0; i < matrix2.rows; i++){
|
for(int i = 0; i < matrix2.rows; i++){
|
||||||
for(int j = 0; j < matrix2.cols; j++){
|
for(int j = 0; j < matrix2.cols; j++){
|
||||||
@ -80,6 +85,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Addition wenn matrix2 nur eine Spalte hat
|
||||||
if((matrix2.cols == 1 && matrix1.cols != 1)){
|
if((matrix2.cols == 1 && matrix1.cols != 1)){
|
||||||
for(int i = 0; i < matrix1.rows; i++){
|
for(int i = 0; i < matrix1.rows; i++){
|
||||||
for(int j = 0; j < matrix1.cols; j++){
|
for(int j = 0; j < matrix1.cols; j++){
|
||||||
@ -94,7 +100,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
if (matrix1.cols != matrix2.rows) {
|
if (matrix1.cols != matrix2.rows) {
|
||||||
Matrix invalid = {0,0, NULL};
|
Matrix invalid = {NULL ,0, 0};
|
||||||
return invalid;
|
return invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
matrix.h
2
matrix.h
@ -6,9 +6,9 @@
|
|||||||
typedef float MatrixType;
|
typedef float MatrixType;
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
|
MatrixType *buffer;
|
||||||
unsigned int rows;
|
unsigned int rows;
|
||||||
unsigned int cols;
|
unsigned int cols;
|
||||||
MatrixType *buffer;
|
|
||||||
}Matrix;
|
}Matrix;
|
||||||
// TODO Matrixtyp definieren
|
// TODO Matrixtyp definieren
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user