From 44b77815b30d9667bc79abe0373b3b465b85c2f0 Mon Sep 17 00:00:00 2001 From: Tobias Grampp Date: Wed, 12 Nov 2025 12:23:55 +0100 Subject: [PATCH 1/6] Added CreateMatrix Function --- matrix.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/matrix.c b/matrix.c index 59fd963..de25a4a 100644 --- a/matrix.c +++ b/matrix.c @@ -13,7 +13,10 @@ typedef struct Matrix { Matrix createMatrix(unsigned int rows, unsigned int cols) { - + Matrix newMatrix; + newMatrix.rows = rows; + newMatrix.cols = cols; + newMatrix.buffer = calloc(rows*cols, sizeof(MatrixType)) } void clearMatrix(Matrix *matrix) From 7acece0571ee7922a23738958602c82f6f07b1c5 Mon Sep 17 00:00:00 2001 From: Tobias Grampp Date: Wed, 12 Nov 2025 12:27:15 +0100 Subject: [PATCH 2/6] Added ClearMatrix Function And Added Return Value to CreateMatrix --- matrix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/matrix.c b/matrix.c index de25a4a..5dd668c 100644 --- a/matrix.c +++ b/matrix.c @@ -17,11 +17,13 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) newMatrix.rows = rows; newMatrix.cols = cols; newMatrix.buffer = calloc(rows*cols, sizeof(MatrixType)) + return newMatrix; } void clearMatrix(Matrix *matrix) { - + free(*matrix.buffer); + *matrix.buffer = NULL; } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) From b9b4d926f5c2dfe2979c21e04ba3047608624551 Mon Sep 17 00:00:00 2001 From: Niko Rost Date: Wed, 12 Nov 2025 12:40:02 +0100 Subject: [PATCH 3/6] Started working on Set and Get Function --- matrix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/matrix.c b/matrix.c index 59fd963..798ac2c 100644 --- a/matrix.c +++ b/matrix.c @@ -23,12 +23,14 @@ void clearMatrix(Matrix *matrix) void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + matrix = {rowIdx, colIdx, value}; //Writes Value of value variable in the selected place in Matrix + printf("Test: Value at %d, %d : %d\n", rowIdx, colIdx, matrix.buffer[rowIdx][colIdx]); } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + value = matrix.buffer[rowIdx][colIdx]; //Stores value of selected place in Matrix in value variable + return value; } Matrix add(const Matrix matrix1, const Matrix matrix2) From 9eba090e45d4765bb025fb7c7a8e5ced52f74cf4 Mon Sep 17 00:00:00 2001 From: Niko Rost Date: Fri, 14 Nov 2025 16:43:17 +0100 Subject: [PATCH 4/6] Finished Set and Get Functions --- matrix.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/matrix.c b/matrix.c index 798ac2c..a60e891 100644 --- a/matrix.c +++ b/matrix.c @@ -23,15 +23,26 @@ void clearMatrix(Matrix *matrix) void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - matrix = {rowIdx, colIdx, value}; //Writes Value of value variable in the selected place in Matrix - printf("Test: Value at %d, %d : %d\n", rowIdx, colIdx, matrix.buffer[rowIdx][colIdx]); + if (rowIdx >= matrix.rows || colIdx >= matrix.cols){ + printf("Index out of bounds\n"); //Error Message because Index Input exceeds Matrix +} + else{ + matrix.buffer[rowIdx * matrix.cols + colIdx] = value; //Writes Value of value variable in the selected place in Matrix +} } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - value = matrix.buffer[rowIdx][colIdx]; //Stores value of selected place in Matrix in value variable - return value; + if (rowIdx >= matrix.rows || colIdx >= matrix.cols){ + printf("Index out of bounds\n"); + return 0; + } + else{ + + MatrixType value = matrix.buffer[rowIdx * matrix.cols + colIdx]; //Stores value of selected place of Matrix in value variable + return value; } + } Matrix add(const Matrix matrix1, const Matrix matrix2) { From abe4ecec657eece9b9436faa1ebd47419afbe64f Mon Sep 17 00:00:00 2001 From: Niko Rost Date: Mon, 17 Nov 2025 10:04:39 +0100 Subject: [PATCH 5/6] Finished Matrix add Function Completing the Set Get Add Branch --- matrix.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/matrix.c b/matrix.c index a60e891..efef3e9 100644 --- a/matrix.c +++ b/matrix.c @@ -46,7 +46,24 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co Matrix add(const Matrix matrix1, const Matrix matrix2) { - + Matrix MatrixErgebnis = createMatrix(matrix1.rows, matrix1.cols); //Creating Result Matrix + if(matrix1.cols != matrix2.cols || matrix1.rows != matrix2.rows){ + printf("Matrix dimensions do not match\n"); //Error Message if dimensions of Input Matrixes are not identical + MatrixErgebnis = clearMatrix(MatrixErgebnis); + return MatrixErgebnis; + } + else{ + + for (unsigned int i = 0; i < matrix1.rows; i++){ + for (unsigned int j = 0; j < matrix1.cols; j++){ + //Adding Matrix Elements of same row and col index together and store in new Matrix + MatrixErgebnis.buffer[i * matrix1.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i * matrix1.cols + j]; + + } + } + + } +return MatrixErgebnis; } Matrix multiply(const Matrix matrix1, const Matrix matrix2) From ac8c827b37b9670feefdb40d0a6a67232552e78a Mon Sep 17 00:00:00 2001 From: Tobias Grampp Date: Mon, 17 Nov 2025 10:32:14 +0100 Subject: [PATCH 6/6] Implemented Function clear Series in imageInput.c --- imageInput.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/imageInput.c b/imageInput.c index bb30de1..2e89d2a 100644 --- a/imageInput.c +++ b/imageInput.c @@ -19,4 +19,11 @@ GrayScaleImageSeries *readImages(const char *path) // TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt void clearSeries(GrayScaleImageSeries *series) { + for(size_t i = GrayScaleImageSeries.count - 1; i >= 0; i--) + { + free(GrayScaleImageSeries.images+GrayScaleImageSeries.count*sizeof(GrayScaleImage)*i); + free(GrayScaleImageSeries.labels+GrayScaleImageSeries.count*sizeof(unsigned char)*i); + } + GrayScaleImageSeries.images = NULL; + GrayScaleImageSeries.labels = NULL; } \ No newline at end of file