Skip to content

Commit

Permalink
Subtract Gaussian blur for normal black & white conversion as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed Jan 12, 2025
1 parent 374f0fc commit 7f4ee0d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions cbits/simplecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ unsigned char const * const single_to_multichannel(
*
* @param width Width of the image.
* @param height Height of the image.
* @param use_double_threshold Use double thresholding.
* @param use_double_threshold Whether to use double thresholding.
* @param data Pointer to the pixel data.
* @return Pointer to the monochrome image data.
*/
Expand Down Expand Up @@ -492,9 +492,10 @@ unsigned char const * const apply_gaussian_blur(
* @param data Pointer to the pixel data.
* @return Pointer to the blurred image data.
*/
unsigned char const * const bw_smooth_smart(
unsigned char const * const bw_smart(
unsigned int width,
unsigned int height,
bool use_double_threshold,
unsigned char const * const data
) {
unsigned char const * const grayscale_data = grayscale(width, height, data);
Expand Down Expand Up @@ -534,7 +535,7 @@ unsigned char const * const bw_smooth_smart(
free((void *)blurred_data);

unsigned char const * const final_data = otsu_threshold_rgba(
width, height, true, high_freq_data
width, height, use_double_threshold, high_freq_data
);

free(high_freq_data);
Expand Down
3 changes: 2 additions & 1 deletion cbits/simplecv.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ unsigned char const * const otsu_threshold_rgba(
unsigned char const * const data
);

unsigned char const * const bw_smooth_smart(
unsigned char const * const bw_smart(
unsigned int width,
unsigned int height,
bool use_double_threshold,
unsigned char const * const data
);
4 changes: 2 additions & 2 deletions source/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -929,13 +929,13 @@ correctAndWrite transformBackend inPath outPath ((bl, _), (tl, _), (tr, _), (br,
savePngImage outPath (ImageRGBA8 grayImg)
--
BlackWhiteExport -> do
bwImgPtr <- SCV.otsu_threshold_rgba width height False resutlImg
bwImgPtr <- SCV.bwSmart width height False resutlImg
bwImgForeignPtr <- newForeignPtr_ (castPtr bwImgPtr)
let bwImg = imageFromUnsafePtr width height bwImgForeignPtr
savePngImage outPath (ImageRGBA8 bwImg)
--
BlackWhiteSmoothExport -> do
bwImgPtr <- SCV.bwSmoothSmart width height resutlImg
bwImgPtr <- SCV.bwSmart width height True resutlImg
bwImgForeignPtr <- newForeignPtr_ (castPtr bwImgPtr)
let bwImg = imageFromUnsafePtr width height bwImgForeignPtr
savePngImage outPath (ImageRGBA8 bwImg)
Expand Down
3 changes: 2 additions & 1 deletion source/SimpleCV.chs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ instance Storable Matrix3x3 where
} -> `Ptr CUChar' castPtr -- ^ Transformed image data
#}

{#fun bw_smooth_smart as ^
{#fun bw_smart as ^
{ `Int' -- ^ width
, `Int' -- ^ height
, `Bool' -- ^ whether to use double thresholding
, identity `Ptr CUChar' -- ^ Original image data
} -> `Ptr CUChar' castPtr -- ^ Anti-aliased black and white image data
#}

0 comments on commit 7f4ee0d

Please sign in to comment.