-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage-processing.c
78 lines (68 loc) · 1.7 KB
/
image-processing.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
/*Your are given n*n pixel grid of an image represented in the matrix form. You have to calculate the convulation of every pixel with a circular kernel of radius r i.e the convulation is the mean of the pixels falling in a circle. The circle is centered at the pixel.
Input Format
First line of the input contains the value of n i.e the size of the grid.
Next n lines contain the values of the grid.
Next line contains the value of r i.e the radius of the kernel.
Output Format
Print the convulation matrix.
input
3
1 1 2
2 1 1
1 2 1
1
output
1.333333 1.250000 1.333333
1.250000 1.400000 1.250000
1.666667 1.250000 1.333333*/
// solution:
#include <stdio.h>
int distance(int i1, int j1, int i2, int j2)
{
return ((i1 - i2) * (i1 - i2) + (j1 - j2) * (j1 - j2));
}
int main()
{
// Insert your code here.
int n;
scanf("%d", &n);
double mat[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
scanf("%lf", &mat[i][j]);
}
}
double r;
scanf("%lf", &r);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
double sum = 0.0;
double count = 0.0;
for (int a = 0; a < n; a++)
{
for (int b = 0; b < n; b++)
{
if (distance(i, j, a, b) <= (r * r))
{
sum += mat[a][b];
count++;
}
}
}
printf("%lf", sum / count);
if (j < n - 1)
{
printf(" ");
}
}
if (i < n - 1)
{
printf("\n");
}
}
return 0;
}