-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBasic_CPU_Implementation.cpp
More file actions
76 lines (61 loc) · 1.51 KB
/
Basic_CPU_Implementation.cpp
File metadata and controls
76 lines (61 loc) · 1.51 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
#include<bits/stdc++.h>
#define imgH 100
#define imgW 100
#define patchW 3
using namespace std;
void printImg(float img[imgH][imgW])
{
for(int i=0; i<imgH; i++)
{
for(int j=0; j<imgW; j++)
{
cout<<img[i][j]<<" ";
}
cout<<endl;
}
return;
}
int main()
{
float img[imgH][imgW] = {0}, C[imgH][imgW] = {0};
float h = 1;
float imgTemp[imgH][imgW] = {0};
for(int i=0; i<imgH; i++)
for(int j=0; j<imgW; j++)
{
img[i][j] = 1.2;
}
//printImg(img);
clock_t t = clock();
for(int i=0; i<imgH - patchW + 1; i++)
for(int j=0; j<imgW - patchW + 1; j++)
{
for(int k=i; k<imgH - patchW + 1; k++)
for(int l=0; l<imgW - patchW + 1; l++)
{
if(l != j)
{
float v = 0;
for(int p=k; p<k+patchW; p++)
for(int q=l; q<l+patchW; q++)
{
v += (img[i+p-k][j+q-l] - img[p][q]) * (img[i+p-k][j+q-l] - img[p][q]);
}
float w = exp(-v/(h*h));
imgTemp[i][j] += w * img[k][l];
C[i][j] += w;
imgTemp[k][l] += w * img[i][j];
C[k][l] += w;
}
}
}
for(int i=0; i<imgH - patchW + 1; i++)
for(int j=0; j<imgW - patchW + 1; j++)
{
img[i][j] = imgTemp[i][j]/C[i][j];
}
t = clock() - t;
cout<<"Time elapsed for H = "<<imgH<<" and W = "<<imgW<<" is: "<<(1000*((double)t/CLOCKS_PER_SEC))<<" milliseconds";
//printImg(img);
return 0;
}