-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserial_code.cpp
More file actions
60 lines (48 loc) · 1.31 KB
/
Copy pathserial_code.cpp
File metadata and controls
60 lines (48 loc) · 1.31 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
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <string>
using namespace std;
// g++ -Wall -o serial_code serial_code.cpp
// time ./serial_code oimage.txt mask.txt output-serial.txt
int main(int argc, char** argv)
{
if (argc != 4)
{ cout<<" You Need to Pass 3 Parameteres (Input File, Mask File & Output File) "<<endl;
return 0;
}
clock_t Start = clock();
string input_file(argv[1]), mask_file(argv[2]), output_file(argv[3]);
FILE *input = fopen (input_file.c_str(), "r");
FILE *mask = fopen (mask_file.c_str(), "r");
FILE *output = fopen (output_file.c_str(),"w");
if (input == NULL || mask == NULL)
{
cout << "Input File or Mask File not found" << endl;
return 0;
}
int m[3][3];
for (int i=0 ; i<3 ; i++)
for (int j=0 ; j<3 ; j++)
fscanf(mask, "%d ", &m[i][j]);
int row,col,px;
fscanf(input, "%d %d", &row, &col);
fprintf(output, "%d %d\n", row, col);
for (int i=0 ; i<row ; i++)
{ for (int j=0 ; j<col ; j++)
{ fscanf (input, "%d", &px);
px /= 28;
if( px > m[i%3][j%3] )
px = 1;
else
px = 0;
fprintf (output, "%d ", px);
}
fprintf (output ,"\n");
}
fcloseall();
clock_t Finish = clock();
cout << "\n\n Elapsed Time = " << float(Finish-Start)/CLOCKS_PER_SEC << endl;
cout<<endl<<endl;
return 0;
}