-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFostroBinaryFilter.cpp
More file actions
55 lines (43 loc) · 1.1 KB
/
FostroBinaryFilter.cpp
File metadata and controls
55 lines (43 loc) · 1.1 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
#include "FostroBinaryFilter.h"
FostroBinaryFilter::FostroBinaryFilter(int width, int height) : FostroFilter(width, height) {
}
FostroBinaryFilter::~FostroBinaryFilter() {
}
FostroImage* FostroBinaryFilter::applyFilter(FostroImage* image, int c) {
FostroPixel* pixel;
float val = 0;
float checkVal = 0;
FostroImage* newImage = new FostroImage(*image, "tmpThreshold.png");
for (unsigned long x = 0; x < image->getHeight(); x++) {
for (unsigned long y = 0; y < image->getWidth(); y++) {
pixel = newImage->getPixel(x,y);
switch (c) {
case RED:
checkVal = pixel->getRedVal();
break;
case GREEN:
checkVal = pixel->getGreenVal();
break;
case BLUE:
checkVal = pixel->getBlueVal();
break;
case GRAY:
checkVal = pixel->getGrayscaleIntensity();
break;
}
if (checkVal >= threshold) {
val = MAX_PIXEL_VAL;
} else {
val = 0;
}
pixel->setRedVal(val);
pixel->setGreenVal(val);
pixel->setBlueVal(val);
pixel->calcGrayscaleIntensity();
}
}
return newImage;
}
void FostroBinaryFilter::setThreshold(float val) {
threshold = val;
}