-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_processing.cpp
More file actions
130 lines (111 loc) · 2.91 KB
/
Copy pathimage_processing.cpp
File metadata and controls
130 lines (111 loc) · 2.91 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include "file.h"
#include "pgm.h"
#include "ppm.h"
#include "imat.h"
#include "dip.h"
using namespace std;
/*
* Here image is considered a 2D array. Like ....
* ------------>x/width
* |############
* |############
* y/height
*
* main function creates an interface to interact with DIP class and process an image
*/
int typeExtensionIndx(char *fileName);
File * fileBuilder(char *fileName);
int main(int argc, char **argv)
{
if(argc<4){
cout<<"<input file> <operation & parameter> <output file>"<<endl<<endl;
cout<<"operation list\n1.resize\n2.neg\n3.gamma\n4.smooth\n\n";
cout<<"OPERATION AND PARAMETER LIST"<<endl;
cout<<"----------------------------"<<endl;
cout<<"1.resize <b(for bilinear approach)\\(for nearest neighbor approach)> <width> <height>"<<endl;
cout<<"2.neg"<<endl;
cout<<"3.TH <threshold value>"<<endl;
cout<<"4.gamma <gamma value>"<<endl;
cout<<"5.heq"<<endl;
cout<<"6.filter <filter type>"<<endl;
return 0;
}
DIP imagePrcsr;
File *srcImgFile = fileBuilder(argv[1]);
IMat *img = srcImgFile->extract();
if(strcmp(argv[2],"resize")==0){
if(argc==7){
if(argv[3][0]=='b'){
imagePrcsr.bilresize(img,atoi(argv[4]),atoi(argv[5]));
File *destImgFile = fileBuilder(argv[6]);
destImgFile->save(argv[6],img);
}
else if(argv[3][0]=='n'){
imagePrcsr.nnresize(img,atoi(argv[4]),atoi(argv[5]));
File *destImgFile = fileBuilder(argv[6]);
destImgFile->save(argv[6],img);
}
else{
cout<<"unknown parameter"<<endl;
}
}
else{
cout<<"wrong cmd format"<<endl;
}
}
else if(strcmp(argv[2],"neg")==0 && argc==4){
imagePrcsr.neg(img);
File *destImgFile = fileBuilder(argv[3]);
destImgFile->save(argv[3],img);
}
else if(strcmp(argv[2],"heq")==0 && argc==4){
imagePrcsr.histoequalize(img);
File *destImgFile = fileBuilder(argv[3]);
destImgFile->save(argv[3],img);
}
else if(strcmp(argv[2],"TH")==0 && argc==5){
imagePrcsr.threshold(img,atoi(argv[3]));
File *destImgFile = fileBuilder(argv[4]);
destImgFile->save(argv[4],img);
}
else if(strcmp(argv[2],"gamma")==0 && argc==5){
imagePrcsr.gammacorrection(img,atof(argv[3]));
File *destImgFile = fileBuilder(argv[4]);
destImgFile->save(argv[4],img);
}
else if(strcmp(argv[2],"filter")==0 && argc==5){
imagePrcsr.filtering(img,atoi(argv[3]));
File *destImgFile = fileBuilder(argv[4]);
destImgFile->save(argv[4],img);
}
else{
cout<<"wrong cmd format"<<endl;
}
return 0;
}
int typeExtensionStrIndx(char *fileName)
{
int ans;
for(int l=strlen(fileName)-1;l>0;l--)
{
if(fileName[l]=='.'){
ans=l;
}
}
return ans+1;
}
File * fileBuilder(char *fileName)
{
File *file;
if(strcmp(&fileName[typeExtensionStrIndx(fileName)],"ppm")==0){
file=(File *)new PPM(fileName);
}
else if(strcmp(&fileName[typeExtensionStrIndx(fileName)],"pgm")==0){
file=(File *)new PGM(fileName);
}
return file;
}