Compare commits
12
Commits
nico
..
fe0728da3e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe0728da3e | ||
|
|
dafd526828 | ||
|
|
e67fb83d8f | ||
|
|
2f6a3a4391 | ||
|
|
e60586a42b | ||
|
|
7dd22e8319 | ||
|
|
e4d2215465 | ||
|
|
c58801f245 | ||
|
|
12fd42ce7d | ||
|
|
d479ed4000 | ||
|
|
a70da6d7ca | ||
|
|
695f0c087c |
No files matched your search
+7
-21
@@ -1,21 +1,7 @@
|
||||
I2_Wortsalat/Start_Mac/wordsalad_initial
|
||||
I2_Wortsalat/Start_Mac/.DS_Store
|
||||
I2_Wortsalat/.DS_Store
|
||||
I2_Wortsalat/Start_Mac/input.o
|
||||
.gitignore
|
||||
I2_Wortsalat/Start_Mac/game.o
|
||||
I2_Wortsalat/Start_Mac/runTests
|
||||
.o
|
||||
.a
|
||||
.idea/editor.xml
|
||||
.idea/vcs.xml
|
||||
.idea/workspace.xml
|
||||
I2_Wortsalat/.idea/editor.xml
|
||||
I2_Wortsalat/.idea/I2_Wortsalat.iml
|
||||
I2_Wortsalat/.idea/modules.xml
|
||||
I2_Wortsalat/Start_Mac/main.o
|
||||
I2_Wortsalat/Start_Mac/.DS_Store
|
||||
I2_Wortsalat/Start_Mac/.DS_Store
|
||||
I2_Wortsalat/Start_Mac/wordsalad
|
||||
I2_Wortsalat/Start_Mac/graphicalGame.o
|
||||
.DS_Store
|
||||
# Alles ignorieren
|
||||
*
|
||||
|
||||
# Ausnahmen: bestimmte Dateitypen in allen Verzeichnissen
|
||||
!**/*.c
|
||||
!**/*.h
|
||||
!**/*Makefile
|
||||
@@ -8,15 +8,116 @@
|
||||
|
||||
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||
|
||||
/* ---------------- Hilfsfunktionen ---------------- */
|
||||
|
||||
static int readHeader(FILE *file, unsigned short *count, unsigned short *width, unsigned short *height)
|
||||
{
|
||||
unsigned short headerlength = strlen(FILE_HEADER_STRING);
|
||||
char buffer[headerlength + 1];
|
||||
if (fread(buffer, 1, headerlength, file) != headerlength)
|
||||
return 0;
|
||||
|
||||
buffer[headerlength] = '\0';
|
||||
|
||||
if (strcmp(buffer, FILE_HEADER_STRING) != 0)
|
||||
return 0;
|
||||
|
||||
if (fread(count, sizeof(unsigned short), 1, file) != 1)
|
||||
return 0;
|
||||
|
||||
if (fread(width, sizeof(unsigned short), 1, file) != 1)
|
||||
return 0;
|
||||
|
||||
if (fread(height, sizeof(unsigned short), 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 short count, width, height;
|
||||
|
||||
if (!readHeader(file, &count, &width, &height)) {
|
||||
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));
|
||||
|
||||
if (!series || !series->images || !series->labels)
|
||||
{
|
||||
free(series->images);
|
||||
free(series->labels);
|
||||
free(series);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
series->images[i].width = width;
|
||||
series->images[i].height = height;
|
||||
series->images[i].buffer = malloc(width * height * sizeof(GrayScalePixelType));
|
||||
|
||||
//malloc prüfen
|
||||
if (!series->images[i].buffer)
|
||||
{
|
||||
clearSeries(series);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//Image einlesen + prüfen
|
||||
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;
|
||||
}
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
|
||||
void clearSeries(GrayScaleImageSeries *series)
|
||||
{
|
||||
if(series)
|
||||
{
|
||||
for(unsigned int i = 0; i < series->count; i++)
|
||||
{
|
||||
free(series->images[i].buffer);
|
||||
}
|
||||
|
||||
free(series->images);
|
||||
free(series->labels);
|
||||
free(series);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "imageInput.h"
|
||||
|
||||
|
||||
static void prepareImageFile(const char *path, unsigned short int width, unsigned short int height, unsigned int short numberOfImages, unsigned char label)
|
||||
static void prepareImageFile(const char *path, unsigned short int width, unsigned short int height, unsigned int short numberOfImages, unsigned char label, unsigned short greyScaleTest)
|
||||
{
|
||||
FILE *file = fopen(path, "wb");
|
||||
|
||||
@@ -17,6 +17,14 @@ static void prepareImageFile(const char *path, unsigned short int width, unsigne
|
||||
|
||||
if(zeroBuffer != NULL)
|
||||
{
|
||||
if(greyScaleTest)
|
||||
{
|
||||
for(unsigned int i = 0; i < (numberOfImages * width * height); i++)
|
||||
{
|
||||
zeroBuffer[i] = (GrayScalePixelType)i;
|
||||
}
|
||||
}
|
||||
|
||||
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
|
||||
fwrite(&numberOfImages, sizeof(numberOfImages), 1, file);
|
||||
fwrite(&width, sizeof(width), 1, file);
|
||||
@@ -41,7 +49,7 @@ void test_readImagesReturnsCorrectNumberOfImages(void)
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
const unsigned short expectedNumberOfImages = 2;
|
||||
const char *path = "testFile.info2";
|
||||
prepareImageFile(path, 8, 8, expectedNumberOfImages, 1);
|
||||
prepareImageFile(path, 8, 8, expectedNumberOfImages, 1, 0);
|
||||
series = readImages(path);
|
||||
TEST_ASSERT_NOT_NULL(series);
|
||||
TEST_ASSERT_EQUAL_UINT16(expectedNumberOfImages, series->count);
|
||||
@@ -54,7 +62,7 @@ void test_readImagesReturnsCorrectImageWidth(void)
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
const unsigned short expectedWidth = 10;
|
||||
const char *path = "testFile.info2";
|
||||
prepareImageFile(path, 8, expectedWidth, 2, 1);
|
||||
prepareImageFile(path, expectedWidth, 8, 2, 1, 0);
|
||||
series = readImages(path);
|
||||
TEST_ASSERT_NOT_NULL(series);
|
||||
TEST_ASSERT_NOT_NULL(series->images);
|
||||
@@ -70,7 +78,7 @@ void test_readImagesReturnsCorrectImageHeight(void)
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
const unsigned short expectedHeight = 10;
|
||||
const char *path = "testFile.info2";
|
||||
prepareImageFile(path, expectedHeight, 8, 2, 1);
|
||||
prepareImageFile(path, 8, expectedHeight, 2, 1, 0);
|
||||
series = readImages(path);
|
||||
TEST_ASSERT_NOT_NULL(series);
|
||||
TEST_ASSERT_NOT_NULL(series->images);
|
||||
@@ -87,7 +95,7 @@ void test_readImagesReturnsCorrectLabels(void)
|
||||
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
const char *path = "testFile.info2";
|
||||
prepareImageFile(path, 8, 8, 2, expectedLabel);
|
||||
prepareImageFile(path, 8, 8, 2, expectedLabel, 0);
|
||||
series = readImages(path);
|
||||
TEST_ASSERT_NOT_NULL(series);
|
||||
TEST_ASSERT_NOT_NULL(series->labels);
|
||||
@@ -119,6 +127,27 @@ void test_readImagesFailsOnWrongFileTag(void)
|
||||
remove(path);
|
||||
}
|
||||
|
||||
void test_readImagesReadsCorrectGrayScales(void)
|
||||
{
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
const char *path = "testFile.info2";
|
||||
|
||||
prepareImageFile(path, 8, 8, 1, 1, 1);
|
||||
series = readImages(path);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(series);
|
||||
TEST_ASSERT_NOT_NULL(series->images);
|
||||
TEST_ASSERT_EQUAL_UINT16(1, series->count);
|
||||
|
||||
for (unsigned int i = 0; i < (8 * 8); i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_UINT8((GrayScalePixelType)i, series->images->buffer[i]);
|
||||
}
|
||||
|
||||
clearSeries(series);
|
||||
remove(path);
|
||||
}
|
||||
|
||||
void setUp(void) {
|
||||
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
||||
}
|
||||
@@ -138,6 +167,7 @@ int main()
|
||||
RUN_TEST(test_readImagesReturnsCorrectLabels);
|
||||
RUN_TEST(test_readImagesReturnsNullOnNotExistingPath);
|
||||
RUN_TEST(test_readImagesFailsOnWrongFileTag);
|
||||
RUN_TEST(test_readImagesReadsCorrectGrayScales);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
@@ -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,6 +7,13 @@ typedef float MatrixType;
|
||||
|
||||
// TODO Matrixtyp definieren
|
||||
|
||||
typedef struct
|
||||
{
|
||||
MatrixType *buffer;
|
||||
int rows;
|
||||
int cols;
|
||||
} Matrix;
|
||||
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
||||
void clearMatrix(Matrix *matrix);
|
||||
|
||||
Submodule I2_Neuronales_Netz deleted from ff67cfdff5.
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user