tipe/src/mnist/preview.c

44 lines
1.1 KiB
C
Raw Normal View History

2022-03-18 15:32:39 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
2022-09-30 15:44:28 +02:00
#include "include/mnist.h"
2022-03-19 16:54:16 +01:00
2022-04-26 16:44:45 +02:00
void print_image(unsigned int width, unsigned int height, int** image) {
2022-03-19 15:43:53 +01:00
char tab[] = {' ', '.', ':', '%', '#', '\0'};
2022-03-18 15:32:39 +01:00
2022-06-23 22:55:01 +02:00
for (int i=0; i < (int)width; i++) {
for (int j=0; j < (int)height; j++) {
2022-04-26 16:44:45 +02:00
printf("%c", tab[image[i][j]/52]);
2022-03-18 15:32:39 +01:00
}
printf("\n");
}
}
2022-04-26 16:44:45 +02:00
void preview_images(char* images_file, char* labels_file) {
int* parameters = read_mnist_images_parameters(images_file);
2022-03-18 15:32:39 +01:00
2022-04-26 16:44:45 +02:00
int number_of_images = parameters[0];
int width = parameters[1];
int height = parameters[2];
unsigned int* labels = read_mnist_labels(labels_file);
int*** images = read_mnist_images(images_file);
2022-03-19 16:54:16 +01:00
for (int i=0; i < number_of_images; i++) {
2022-03-20 15:00:53 +01:00
printf("--- Number %d : %d ---\n", i, labels[i]);
2022-04-26 16:44:45 +02:00
print_image(width, height, images[i]);
2022-03-20 13:19:25 +01:00
}
}
2022-03-18 15:32:39 +01:00
int main(int argc, char *argv[]) {
2022-03-20 13:19:25 +01:00
if (argc < 3) {
printf("Utilisation: %s [IMAGES FILE] [LABELS FILE]\n", argv[0]);
2022-03-18 15:32:39 +01:00
return 1;
}
2022-04-26 16:44:45 +02:00
preview_images(argv[1], argv[2]);
2022-03-18 15:32:39 +01:00
return 0;
}