summaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
Diffstat (limited to 'image')
-rw-r--r--image/image.c53
-rw-r--r--image/image.h25
-rw-r--r--image/main.exebin0 -> 147685 bytes
3 files changed, 78 insertions, 0 deletions
diff --git a/image/image.c b/image/image.c
new file mode 100644
index 0000000..99d1341
--- /dev/null
+++ b/image/image.c
@@ -0,0 +1,53 @@
+#include "image.h"
+
+
+image *loadCSV(FILE *fp){
+ image *im = malloc(sizeof(image));
+ char line[MAXCHARS];
+ fgets(line, MAXCHARS, fp);
+ im->label = atoi(strtok(line, ","));
+ matrix *m = newMatrix(28, 28);
+ for(int i = 0; i < 28; ++i){
+ for(int j = 0; j < 28; ++j){
+ m->data[i][j] = strtod(strtok(NULL, ","), NULL)/256;
+ }
+ }
+ im->img = m;
+ return im;
+}
+
+void freeImage(image **im){
+ freeMatrix(&((*im)->img));
+ free(*im);
+ *im = NULL;
+}
+
+void printImage(image *im){
+ printf("%d, %d\n", im->img->rows, im->img->cols);
+ printf("%d\n", im->label);
+ for(int i = 0; i < im->img->rows; ++i){
+ for(int j = 0; j < im->img->cols; ++j){
+ printf("%c ", (im->img->data[i][j] > 0) ? '1' : 0 );
+ }
+ printf("\n");
+ }
+}
+/*int main(){
+
+ FILE *fp = fopen("../mnist_train.csv", "r");
+ char line[MAXCHARS];
+ fgets(line, MAXCHARS, fp);
+ image *im = loadMnist_train(fp);
+
+ printf("%d, %d\n", im->img->rows, im->img->cols);
+ printf("%d\n", im->label);
+ for(int i = 0; i < im->img->rows; ++i){
+ if(i%28 == 0)
+ printf("\n");
+ for(int j = 0; j < im->img->cols; ++j){
+ printf("%c ", (im->img->data[i][j] > 0) ? '1' : 0 );
+ }
+ }
+
+ return 0;
+}*/
diff --git a/image/image.h b/image/image.h
new file mode 100644
index 0000000..a5446a8
--- /dev/null
+++ b/image/image.h
@@ -0,0 +1,25 @@
+#pragma once
+#ifndef IMAGE_H
+#define IMAGE_H
+
+#define __MINGW_FEATURES__ 1
+
+#include <string.h>
+#include "../../matrix/matrix.h"
+
+#define MNIST_SIZE 784
+#define MAXCHARS 10000
+
+
+typedef struct image{
+ int label;
+ matrix *img;
+} image;
+
+image *loadCSV(FILE *fp);
+
+void freeImage(image **im);
+
+void printImage(image *im);
+
+#endif
diff --git a/image/main.exe b/image/main.exe
new file mode 100644
index 0000000..4d6969d
--- /dev/null
+++ b/image/main.exe
Binary files differ