-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiltersCpu.cpp
57 lines (51 loc) · 1.8 KB
/
filtersCpu.cpp
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
#include <iostream>
#include <vector>
using namespace std;
inline void filterBlueSimple(unsigned char* img, int width, int height, int channels) {
// Altere os canais vermelho e verde para zero
for (int i = 0; i < width * height * channels; i += channels) {
img[i] = 0; // Canal vermelho
img[i + 1] = 0; // Canal verde
}
}
inline void filterGrayScaleSimple(unsigned char* img, int width, int height, int channels) {
for (int i = 0; i < width * height * channels; i += channels) {
int gray = (img[i] + img[i + 1] + img[i + 2]) / 3;
img[i] = gray; // Canal vermelho
img[i + 1] = gray; // Canal verde
img[i + 2] = gray;
}
}
inline void filterDarknessSimple(unsigned char* img, int width, int height, int channels) {
// simple darkness
for (int i = 0; i < width; i++) {
for (int y = 0; y < height; y++) {
for (int c = 0; c < 3; c++) {
if (img[(y * width + i) * 3 + c] >= 50) {
img[(y * width + i) * 3 + c] -= 50;
}
else if (img[(y * width + i) * 3 + c] <= 50) {
img[(y * width + i) * 3 + c] = 0;
}
}
}
}
}
inline void filterSaltAndPepperSimple(unsigned char* img, int width, int height, int channels) {
// salt and pepper noise
for (int i = 0; i < width; i++) {
for (int y = 0; y < height; y++) {
for (int c = 0; c < 3; c++) {
int num = rand() % 100;
if (num < 4) {
if (num % 2 == 0) {
img[(y * width + i) * 3 + c] = 255;
}
else {
img[(y * width + i) * 3 + c] = 0;
}
}
}
}
}
}