FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
parallelFinalProject/convolution.cpp at main · rbebb/parallelFinalProject · GitHub
rbebb
/
parallelFinalProject
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
parallelFinalProject
/
convolution.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (41 loc) · 1.42 KB
Breadcrumbs
parallelFinalProject
/
convolution.cpp
Copy path
File metadata and controls
48 lines (41 loc) · 1.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
iostream
>
#
include
<
cstdlib
>
#
include
<
string
>
#
include
<
omp.h
>
#
include
"
convolution.hpp
"
using
namespace
std
;
/*
*
* Function that applies a supplied kernel to a supplied image.
*
* @param *img buffer containing image data
* @param *dims array of length 2 holding height and width of the image
* @param **kernel odd-sized square matrix holding transformation kernel
* @param k width of the kernel
* @return *filtered filtered image
*/
int
*
convolute_image
(
int
*img,
int
*dims,
double
**kernel,
int
k) {
double
a;
int
*filtered;
filtered = (
int
*)
malloc
(dims[
0
] * dims[
1
] *
sizeof
(
int
));
#
pragma
omp parallel for shared(filtered) private(a)
for
(
int
i =
0
; i < dims[
0
]; i++) {
for
(
int
j =
0
; j < dims[
1
]; j++) {
a =
0.0
;
for
(
int
ki = -(k/
2
); ki <= (k/
2
); ki++) {
for
(
int
kj = -(k/
2
); kj <= (k/
2
); kj++) {
if
((i + ki <
0
) || (j + kj <
0
) || (i + ki > dims[
0
] -
1
) || (j + kj > dims[
1
] -
1
)) {
continue
;
}
else
{
double
kval = kernel[kj + (k/
2
)][ki + (k/
2
)];
double
ival = img[(i + ki) * dims[
1
] + (j + kj)];
a += kval * ival;
}
}
}
if
(a >
255
) a =
255
;
if
(a <
0
) a =
0
;
filtered[(i * dims[
1
]) + j] = (
int
) a;
}
}
return
filtered;
}
Back
|
FazBrowse Home
|
New Git URL