Skip to content

Commit c134395

Browse files
committed
1.2025.05.05: threshold: N.I.C.K.: new adjustment method
1 parent bad85a3 commit c134395

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

src/imageproc/Binarize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ BinaryImage binarizeBradley(
619619
} // binarizeBradley
620620

621621
/*
622-
* nick = mean - k * sqrt(stdev * stdev + mean * mean), k = 0.05
622+
* nick = mean - k * sqrt(stdev * stdev + cnick * mean * mean), k = 0.10
623623
*/
624624
BinaryImage binarizeNick(
625625
GrayImage const& src,
@@ -634,8 +634,8 @@ BinaryImage binarizeNick(
634634
return BinaryImage();
635635
}
636636

637-
GrayImage threshold_map(grayNickMap(src, radius, k));
638-
BinaryImage bw_img(binarizeFromMap(src, threshold_map, delta, bound_lower, bound_upper));
637+
GrayImage threshold_map(grayNickMap(src, radius, k, delta));
638+
BinaryImage bw_img(binarizeFromMap(src, threshold_map, 0, bound_lower, bound_upper));
639639

640640
return bw_img;
641641
}

src/imageproc/Binarize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ IMAGEPROC_EXPORT BinaryImage binarizeBradley(
205205
IMAGEPROC_EXPORT BinaryImage binarizeNick(
206206
GrayImage const& src,
207207
int radius = 100,
208-
float k = 0.05f,
208+
float k = 0.10f,
209209
int delta = 0,
210210
unsigned char lower_bound = 0,
211211
unsigned char upper_bound = 255);

src/imageproc/GrayImage.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,12 +906,13 @@ GrayImage grayBradleyMap(
906906
} // grayBradleyMap
907907

908908
/*
909-
* nick = mean - k * sqrt(stdev * stdev + mean * mean), k = 0.05
909+
* nick = mean - k * sqrt(stdev * stdev + cnick * mean * mean), k = 0.10
910910
*/
911911
GrayImage grayNickMap(
912912
GrayImage const& src,
913913
int const radius,
914-
float const k)
914+
float const k,
915+
int const delta)
915916
{
916917
if (src.isNull())
917918
{
@@ -925,6 +926,7 @@ GrayImage grayNickMap(
925926

926927
if (radius > 0)
927928
{
929+
float cnick = (50.0f - delta) * 0.01f;
928930
GrayImage gdeviation = grayMapDeviation(src, radius);
929931
if (gdeviation.isNull())
930932
{
@@ -944,7 +946,7 @@ GrayImage grayNickMap(
944946
{
945947
float const mean = gmean_line[x];
946948
float const deviation = gdeviation_line[x];
947-
float const circle = sqrtf(deviation * deviation + mean * mean);
949+
float const circle = sqrtf(deviation * deviation + cnick * mean * mean);
948950
float threshold = mean - k * circle;
949951

950952
threshold = (threshold < 0.0f) ? 0.0f : ((threshold < 255.0f) ? threshold : 255.0f);

src/imageproc/GrayImage.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ IMAGEPROC_EXPORT GrayImage grayBradleyMap(
203203
IMAGEPROC_EXPORT GrayImage grayNickMap(
204204
GrayImage const& src,
205205
int radius = 100,
206-
float k = 0.05f);
206+
float k = 0.10f,
207+
int delta = 0);
207208
IMAGEPROC_EXPORT GrayImage grayGradMap(
208209
GrayImage const& src,
209210
int radius = 10,

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
#define SCANTAILOR_VERSION_H_
2121

2222
#define STFAMILY "experimental"
23-
#define VERSION "1.2025.04.30" // Must be "x.x.x.x" or an empty string.
23+
#define VERSION "1.2025.05.05" // Must be "x.x.x.x" or an empty string.
2424

2525
#endif

0 commit comments

Comments
 (0)