-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.c
82 lines (67 loc) · 2.06 KB
/
image.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "image.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned char **alocamatriz(struct PGMstructure *imginfo)
{
unsigned char **mat;
int i;
mat = malloc(imginfo->height * sizeof(unsigned char *));
for (i = 0; i < imginfo->height; i++)
mat[i] = malloc(imginfo->width * sizeof(unsigned char));
return mat;
}
void copyPixels(FILE *imagein, struct PGMstructure *imginfo, unsigned char **mat, int format) {
int i, j;
if (format == 5)
{
for (i = 0; i < imginfo->height; i++)
{
for (j = 0; j < imginfo->width; j++)
{
mat[i][j] = getc(imagein);
}
}
}
if (format == 2)
{
int value;
for (i = 0; i < imginfo->height; i++)
{
for (j = 0; j < imginfo->width; j++)
{
fscanf(imagein, "%d", &value);
mat[i][j] = (unsigned char)value;
}
}
}
}
void printMenu(int *mode) {
printf("Choose mode:\n1. Negativo\n2. Limiar\n3. Ruido\n4. Mediana\n5. LBP\n6. Rota90\n");
scanf("%i", mode);
}
int getImageFormat(FILE *imagein) {
int format = getc(imagein);
fscanf(imagein, "%d", &format);
return format;
}
void processComment(FILE *imagein){
// Ignore the first line in the input file
while (getc(imagein) != '\n');
if (getc(imagein) == '#') // If it is the case, ignore the second line in the input file
while (getc(imagein) != '\n');
else
fseek(imagein, -1, SEEK_CUR);
}
void getImageValues(FILE *imagein, struct PGMstructure *imginfo) {
fscanf(imagein, "%d", &imginfo->width);
fscanf(imagein, "%d", &imginfo->height);
fscanf(imagein, "%d", &imginfo->maxVal);
while (getc(imagein) != '\n');
}
void printImageHeader(FILE *imageout, struct PGMstructure *imginfo, int format, int mode) {
if (mode == 6)
fprintf(imageout, "%s%i%s%i %i%s%i%s", "P", format, "\n# CREATOR: Image Processor Version 1.1\n", imginfo->height, imginfo->width, "\n", imginfo->maxVal, "\n");
else
fprintf(imageout, "%s%i%s%i %i%s%i%s", "P", format, "\n# CREATOR: Image Processor Version 1.1\n", imginfo->width, imginfo->height, "\n", imginfo->maxVal, "\n");
}