5 Commits
Author SHA1 Message Date
urbanjo98912 c58801f245 readImages completed 2025-11-02 21:11:56 +01:00
urbanjo98912 12fd42ce7d matrix.c & matrix.h completed 2025-10-29 22:01:22 +01:00
urbanjo98912 d479ed4000 Merge branch 'timo' 2025-10-27 15:09:28 +01:00
urbanjo98912 a70da6d7ca delete folder 2025-10-27 15:06:42 +01:00
hertelti100229 695f0c087c Code sichten 2025-10-14 18:43:23 +02:00
5 changed files with 178 additions and 10 deletions

No files matched your search

@@ -5,14 +5,90 @@
#define BUFFER_SIZE 100
#define FILE_HEADER_STRING "__info2_image_file_format__"
#define HEADER_STRING_LEN strlen(FILE_HEADER_STRING)
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
/* ---------------- Hilfsfunktionen ---------------- */
static int readHeader(FILE *file, unsigned int *count, unsigned int *width, unsigned int *height)
{
char buffer[HEADER_STRING_LEN + 1];
if (fread(buffer, 1, HEADER_STRING_LEN, file) != HEADER_STRING_LEN)
return 0;
buffer[HEADER_STRING_LEN] = '\0';
if (strcmp(buffer, FILE_HEADER_STRING) != 0)
return 0;
if (fread(count, sizeof(unsigned int), 1, file) != 1)
return 0;
if (fread(width, sizeof(unsigned int), 1, file) != 1)
return 0;
if (fread(height, sizeof(unsigned int), 1, file) != 1)
return 0;
return 1;
}
static int readSingleImage(FILE *file, GrayScaleImage *image)
{
unsigned int pixelCount = image->width * image->height;
if (fread(image->buffer, sizeof(GrayScalePixelType), pixelCount, file) != pixelCount)
return 0;
return 1;
}
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
GrayScaleImageSeries *readImages(const char *path)
{
GrayScaleImageSeries *series = NULL;
FILE *file = fopen(path, "rb");
if (!file)
return NULL;
unsigned int count, w, h;
if (!readHeader(file, &count, &w, &h)) {
fclose(file);
return NULL;
}
GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries));
series->count = count;
series->images = malloc(count * sizeof(GrayScaleImage));
series->labels = malloc(count * sizeof(unsigned char));
for (unsigned int i = 0; i < count; i++)
{
series->images[i].width = w;
series->images[i].height = h;
series->images[i].buffer = malloc(w * h * sizeof(GrayScalePixelType));
if (!readSingleImage(file, &series->images[i])) {
fclose(file);
clearSeries(series);
return NULL;
}
// label einlesen
if (fread(&series->labels[i], sizeof(unsigned char), 1, file) != 1) {
fclose(file);
clearSeries(series);
return NULL;
}
}
fclose(file);
return series;
}
+88 -6
View File
@@ -6,30 +6,112 @@
Matrix createMatrix(unsigned int rows, unsigned int cols)
{
Matrix m;
if (rows == 0 || cols == 0)
{
m.rows = 0;
m.cols = 0;
m.buffer = NULL;
return m;
}
m.rows = rows;
m.cols = cols;
m.buffer = (MatrixType *)calloc(rows * cols, sizeof(MatrixType));
return m;
}
void clearMatrix(Matrix *matrix)
{
if (matrix != NULL)
{
if (matrix->buffer != NULL)
{
free(matrix->buffer);
matrix->buffer = NULL;
}
matrix->rows = 0;
matrix->cols = 0;
}
}
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{
if (matrix.buffer != NULL)
{
if (rowIdx < matrix.rows || colIdx < matrix.cols)
{
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
}
}
}
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{
if (matrix.buffer == NULL || rowIdx >= matrix.rows || colIdx >= matrix.cols)
{
return UNDEFINED_MATRIX_VALUE;
}
return matrix.buffer[rowIdx * matrix.cols + colIdx];
}
Matrix add(const Matrix matrix1, const Matrix matrix2)
{
Matrix result;
if (matrix1.buffer == NULL || matrix2.buffer == NULL || matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
{
result.rows = 0;
result.cols = 0;
result.buffer = NULL;
return result;
}
result = createMatrix(matrix1.rows, matrix1.cols);
for (int i = 0; i < matrix1.rows; i++)
{
for (int j = 0; j < matrix1.cols; j++)
{
MatrixType value = getMatrixAt(matrix1, i, j) + getMatrixAt(matrix2, i, j);
setMatrixAt(value, result, i, j);
}
}
return result;
}
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{
}
Matrix result;
if (matrix1.buffer == NULL || matrix2.buffer == NULL || matrix1.cols != matrix2.rows)
{
result.rows = 0;
result.cols = 0;
result.buffer = NULL;
return result;
}
result = createMatrix(matrix1.rows, matrix2.cols);
for (int i = 0; i < matrix1.rows; i++)
{
for (int j = 0; j < matrix2.cols; j++)
{
MatrixType sum = 0;
for (int k = 0; k < matrix1.cols; k++)
{
sum += getMatrixAt(matrix1, i, k) * getMatrixAt(matrix2, k, j);
}
setMatrixAt(sum, result, i, j);
}
}
return result;
}
+7
View File
@@ -7,6 +7,13 @@ typedef float MatrixType;
// TODO Matrixtyp definieren
typedef struct
{
int rows;
int cols;
MatrixType *buffer;
} Matrix;
Matrix createMatrix(unsigned int rows, unsigned int cols);
void clearMatrix(Matrix *matrix);
Submodule I2_Neuronales_Netz deleted from ff67cfdff5.
+7 -3
View File
@@ -1,9 +1,13 @@
#include "input.h"
#include <string.h>
#include <ctype.h>
#include <string.h>
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei
// (words.txt) einliest und als C-String zurückgibt.
// Bedingungen, die in main.c geprüft werden:
// - existiert die angegebene Datei
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
@@ -39,4 +43,4 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
return word_counter;
}
}