-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef SP2_GRAPHICS_IMAGE_THRESHOLD_H | ||
#define SP2_GRAPHICS_IMAGE_THRESHOLD_H | ||
|
||
#include <sp2/graphics/image.h> | ||
|
||
|
||
namespace sp::image { | ||
|
||
static inline sp::Image8 threshold(const sp::Image8& input, int threshold_value, int neg=0, int pos=255) { | ||
sp::Image8 output{input.getSize()}; | ||
auto ptr_i = input.getPtr(); | ||
auto ptr_o = output.getPtr(); | ||
for(auto n=0; n<input.getSize().x*input.getSize().y;n++) { | ||
if (*ptr_i >= threshold_value) | ||
*ptr_o = pos; | ||
else | ||
*ptr_o = neg; | ||
ptr_i++; | ||
ptr_o++; | ||
} | ||
return output; | ||
} | ||
|
||
static inline sp::Image8 adaptiveThreshold(const sp::Image8& input, int blocksize, int offset, int neg=0, int pos=255) { | ||
auto output = sp::image::gaussianBlur(input, blocksize); | ||
auto ptr_i = input.getPtr(); | ||
auto ptr_o = output.getPtr(); | ||
for(auto n=0; n<input.getSize().x*input.getSize().y;n++) { | ||
if (*ptr_i > *ptr_o + offset) | ||
*ptr_o = pos; | ||
else | ||
*ptr_o = neg; | ||
ptr_i++; | ||
ptr_o++; | ||
} | ||
return output; | ||
} | ||
|
||
}//namespace sp::image | ||
|
||
|
||
#endif//SP2_GRAPHICS_IMAGE_THRESHOLD_H |