-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotate_anticlockwise.c
127 lines (77 loc) · 2.54 KB
/
Rotate_anticlockwise.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
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
/* This the program do anticlockwise rotation of a image and puting all images(after each anticlockwise rotation, starting from image itself) in a single image in anticlockwise fasion of quadrants starting from left bottomost quadrant
NAME - RAJENDRA SINGH */
#include<stdio.h>
int main()
{
FILE *p, *q; /* declaration of pointers to the file */
int success,r,i=0,j=0, d[5], w;
int a[500][500]; /* declaration of orignal image matrix*/
int b[1000][1000]; /* declaration of final image matrix*/
char inputfile[30], outputfile[30], magicno[5];
printf("Enter the name of file to open\n"); //*asking for the input file name
scanf(" %s", inputfile);
printf("Enter the name of output file\n"); //*asking for the output file name
scanf(" %s", outputfile);
p=fopen(inputfile,"r"); //* opening the file in only readable type
if(p==0)
{
printf("Error occur in opening file\n");
return 1;
}
fscanf(p, "%s", magicno); //* This is for scaning the magic no.,width and hight, maximum intensity value
fscanf(p, "%d %d", &d[0], &d[1]);
fscanf(p, "%d", &d[2]);
for(i=0; i<d[1]; i++) //* for scaning the image matrix
{
for(j=0; j<d[0]; j++)
{
fscanf(p,"%d", &a[i][j]);
}
}
fclose(p); //*closeing the above file since scaning over
//*Below is the program for defining the final image matrix from our scaned orignal image
for(i=0; i<d[1]; i++) /* for defining the left upper quadrant of final image from orignal image*/
{
for(j=0; j<d[0]; j++)
{
b[i][j]= a[d[1]-i][i];
}
}
for(i=0; i<d[0]; i++) /* for defining the right upper quadrant of final image from orignal image*/
{
for(j=d[0]; j<(d[0]+ d[1]); j++)
{
b[i][j]= a[d[0]-i][(d[0] + d[1])-j];
}
}
for(i=d[1]; i<(d[1] + d[0]); i++) /* for defining the left bottom quadrant of final image from orignal image*/
{
for(j=0; j<d[0]; j++)
{
b[i][j]= a[i-d[1]][j];
}
}
for(i=d[1]; i<(d[1] + d[0]); i++) /* for defining the right bottom quadrant of final image from orignal image*/
{
for(j=d[0]; j<(d[0]+ d[1]); j++)
{
b[i][j]= a[j-d[0]][(d[0]+d[1])-1];
}
}
q=fopen(outputfile, "w"); //*opening the new file in only writable type
if (q==0)
{
fprintf(q,"File dint open correctly\n");
}
fprintf(q,"%s\n%d %d\n%d\n", magicno, d[0], d[1], d[2]);
for(i=0; i<(d[1]+d[0]); i++) //*printing the final image matrix
{
for(j=0; j<(d[0]+d[1]); j++)
{
fprintf(q,"%d ", b[i][j]);
}
fprintf(q,"\n");
}
fclose(q); //*closeing the above file
return 0;
}