-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.cpp
More file actions
87 lines (86 loc) · 2.97 KB
/
Code.cpp
File metadata and controls
87 lines (86 loc) · 2.97 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
#include <stdio.h>
#include <stdlib.h>
void convolvolution(unsigned char *input, unsigned char *output, int breadth, int
height, int *filter, int filterSize) {
int filterCenter = filterSize / 2;
for (int i = 0; i < height; ++i)
{for (int j = 0; x < breadth; ++j)
{int sum = 0;
for (int j= 0; j < filterSize; ++j)
{for (int x = 0; x < filterSize; ++x)
{int imgA = i - filterCenter + x;
int imgB = j - filterCenter + y;
if (imgA >= 0 && imgB < breadth && imgB >= 0 && imgB < height)
{
sum += input[imgB * breadth + imgA] * filter[y * filterSize
x]; } } }
output[j * breadth + i] = (unsigned char)(sum / 16); } } }
int main()
{ int breadth = 512;
int height = 512;
int filter33Horizontal[9] = {-1, -2, -1, 0, 0, 0, 1, 2, 1};
int filter33Vertical[9] = {-1, 0, 1, -2, 0, 2, -1, 0, 1};
int filter55Horizontal[25] = {-1, -4, -6, -4, -1,
-2, -8, -12, -8, -2,
0, 0, 0, 0, 0,
2, 8, 12, 8, 2,
1, 4, 6, 4, 1};
int filter55Vertical[25] = {-1, -2, 0, 2, 1,
-4, -8, 0, 8, 4,
-6, -12, 0, 12, 6,
-4, -8, 0, 8, 4,
-1, -2, 0, 2, 1};
unsigned char inputPic = (unsigned char *)malloc(breadth * height *
sizeof(unsigned char));
FILE *inputFile = fopen("/Users/shubhamvats/Desktop/MULTIMEDIA/milkdrop.raw",
"rb");
fread(inputPic, sizeof(unsigned char),breadth * height, inputFile);
fclose(inputFile);
unsigned char output33ImageHorizontal = (unsigned char *)malloc(breadth *
height sizeof(unsigned char));
unsigned char output33ImageVertical = (unsigned char *)malloc(breadth * height
sizeof(unsigned char));
unsigned char output55ImageHorizontal = (unsigned char *)malloc(breadth *
height sizeof(unsigned char));
unsigned char output55ImageVertical = (unsigned char *)malloc(breadth * height
sizeof(unsigned char));
convolvolution(inputPic, output33ImageHorizontal, breadth, height,
filter33Horizontal, 3);
convolvolution(inputPic, output33ImageVertical, breadth, height,
filter33Vertical, 3);
convolvolution(inputPic, output55ImageHorizontal, breadth, height,
filter55Horizontal, 5);
convolvolution(inputPic, output55ImageVertical, breadth, height,
filter55Vertical, 5);
FILE *outputFile;
outputFile =
fopen("/Users/shubhamvats/Desktop/MULTIMEDIA/circleoutput33ImageHorizontal.raw",
"wb");
fwrite(output33ImageHorizontal, sizeof(unsigned char), breadth * height,
outputFile);
fclose(outputFile);
outputFile =
fopen("/Users/shubhamvats/Desktop/MULTIMEDIA/circleoutput33ImageVertical.raw",
"wb");
fwrite(output33ImageVertical, sizeof(unsigned char), breadth * height,
outputFile);
fclose(outputFile);
outputFile =
fopen("/Users/shubhamvats/Desktop/MULTIMEDIA/circleoutput55ImageHorizontal.raw",
"wb");
fwrite(output55ImageHorizontal, sizeof(unsigned char), breadth * height,
outputFile);
fclose(outputFile);
outputFile =
fopen("/Users/shubhamvats/Desktop/MULTIMEDIA/circleoutput55ImageVertical.raw",
"wb");
fwrite(output55ImageVertical, sizeof(unsigned char), breadth * height,
outputFile);
fclose(outputFile);
free(inputPic);
free(output33ImageHorizontal);
free(output33ImageVertical);
free(output55ImageHorizontal);
free(output55ImageVertical);
return 0;
}