-
Notifications
You must be signed in to change notification settings - Fork 0
/
processadordeimagem.c
102 lines (87 loc) · 2.23 KB
/
processadordeimagem.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "image.h"
#include "filtros.h"
int main(int argc, char *argv[])
{
FILE *imagein, *imageout;
// Aloca estrutura imginfo
struct PGMstructure *imginfo = malloc(sizeof(struct PGMstructure));
unsigned char **mat; // matrix
char *infpath, *outfpath;
infpath = malloc(sizeof(char) * 500); // input file name
outfpath = malloc(sizeof(char) * 500); // output file name
// control variables
int format;
int i;
int mode;
int mediana;
float limiar;
//read command line
if (argc > 1) {
int c = 0;
while(++c < argc) {
if (strcmp(argv[c], "-i") == 0) {
infpath = argv[c+1];
c++;
}
else if (strcmp(argv[c], "-o") == 0) {
outfpath = argv[c+1];
c++;
}
else {
printf("ERROR");
exit(1);
}
}
}
// Abre arquivo de entrada e armazena em imagein
imagein = fopen(infpath, "r+");
if (imagein == NULL)
{
printf("Error opening file");
exit(8);
}
format = getImageFormat(imagein); // read format p5 or p2
processComment(imagein); // ignore comments
printMenu(&mode); // print menu
getImageValues(imagein, imginfo); // read image dimensions
mat = alocamatriz(imginfo); // alloc matrix
copyPixels(imagein, imginfo, mat, format); // copy image to matrix
imageout = fopen(outfpath, "w+"); // open output file
printImageHeader(imageout, imginfo, format, mode); // print image header
// FILTROS
switch(mode) {
case 1:
Negativo(&imageout, imginfo, mat, format);
break;
case 2:
printf("\nLimiar: ");
scanf("%f", &limiar);
Limiar(&imageout, imginfo, mat, format, limiar);
break;
case 3:
Ruido(&imageout, imginfo, mat, format);
break;
case 4:
printf("\nMediana: ");
scanf("%i", &mediana);
Mediana(&imageout, imginfo, mat, format, mediana);
break;
case 5:
Lbp(&imageout, imginfo, mat, format);
break;
case 6:
Rota90(&imageout, imginfo, mat, format);
break;
}
// free
fclose(imagein);
fclose(imageout);
free(imginfo);
for (i = 0; i < imginfo->width; i++)
free(mat[i]);
free(mat);
return 0;
}