Skip to content

Commit

Permalink
0.20230714: Threshold: EdgeDiv (combine EdgePlus & BlurDiv)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Jul 14, 2023
1 parent 4bb7b05 commit c5d3fef
Show file tree
Hide file tree
Showing 33 changed files with 147 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CC = gcc
CPP = g++
CFLAGS = -DUNIX -I$(SRCS) -Wall -s
VER = 0
VERB = 20230707
VERB = 20230714
ifeq ($(OS),Windows_NT)
LIBS = FreeImage.lib
PLIBF = $(PNAME).$(VER).dll
Expand Down
4 changes: 4 additions & 0 deletions doc/imthreshold/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.20230714

Threshold: EdgeDiv (combine EdgePlus & BlurDiv)

0.20230707

Threshold: DjVuC
Expand Down
2 changes: 1 addition & 1 deletion doc/imthreshold/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.20230707
0.20230714
2 changes: 1 addition & 1 deletion man/man1/imthreshold-a4.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-a4
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-anytodjvu.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-anytodjvu
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-anytominidjvu.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-anytodjvu
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-bash-scripts.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-bash-scripts
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-deskew.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-deskew
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-fautoinv.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-fautoinv
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-fdespeckle.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-fdespeckle
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-filter.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-filter
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-finfo.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-finfo
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-fpmean.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-fpmean
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-math.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-math
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-rotate.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-rotate
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-sbwmag2.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-sbwmag2
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-separate.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-separate
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-shris.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-shris
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-size.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-size
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-tdjvul.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-tdjvul
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-tgatos.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-tgatos
Expand Down
5 changes: 4 additions & 1 deletion man/man1/imthreshold-tglobal.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-tglobal
Expand All @@ -11,6 +11,9 @@ imthreshold-tglobal [options] <input_image> <output_image>(BW)

.SH OPTIONS
.TP
-2
color sqr (bool, optional, default = false)
.TP
-b
color correct (bool, optional, default = false)
.TP
Expand Down
8 changes: 7 additions & 1 deletion man/man1/imthreshold-tlayer.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-tlayer
Expand All @@ -11,6 +11,12 @@ imthreshold-tlayer [options] <input_image> <output_image>

.SH OPTIONS
.TP
-2
color sqr (bool, optional, default = false)
.TP
-b
color correct (bool, optional, default = false)
.TP
-c N
contrast limit (int, optional, default = 128)
.TP
Expand Down
6 changes: 5 additions & 1 deletion man/man1/imthreshold-tlocal.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-tlocal
Expand All @@ -11,6 +11,9 @@ imthreshold-tlocal [options] <input_image> <output_image>(BW)

.SH OPTIONS
.TP
-2
color sqr (bool, optional, default = false)
.TP
-b
color correct (bool, optional, default = false)
.TP
Expand All @@ -29,6 +32,7 @@ name filter:
'chistian'
'dalg'
'edge'
'edgediv'
'edgeplus'
'gravure'
'mscale'
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-ttext.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-ttext
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold-twhiterohrer.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold-twhiterohrer
Expand Down
2 changes: 1 addition & 1 deletion man/man1/imthreshold.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ImThreshold" 1 0.20230707 "07 Jul 2023" "User Manual"
.TH "ImThreshold" 1 0.20230714 "14 Jul 2023" "User Manual"

.SH NAME
imthreshold
Expand Down
2 changes: 2 additions & 0 deletions src/imthreshold.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void IMTFilterMathOverlay (IMTpixel**, IMTpixel**, unsigned int, unsigned int, i
void IMTFilterMathPlus (IMTpixel**, IMTpixel**, unsigned, unsigned, int);
void IMTFilterMathScreen (IMTpixel**, IMTpixel**, unsigned int, unsigned int, int);
float IMTFilterMathSharpenBadMetric (IMTpixel**, IMTpixel**, unsigned, unsigned);
void IMTFilterMathSqr (IMTpixel**, unsigned, unsigned);
void IMTFilterMathThreshold (IMTpixel**, IMTpixel**, BYTE**, unsigned, unsigned, int);
float IMTFilterMirror (IMTpixel**, IMTpixel**, unsigned, unsigned);
float IMTFilterMirrorPart (IMTpixel**, IMTpixel**, unsigned, unsigned, float);
Expand Down Expand Up @@ -258,6 +259,7 @@ int IMTFilterTDithBayer (IMTpixel**, BYTE**, unsigned, unsigned, int);
int IMTFilterTDithDots (IMTpixel**, BYTE**, unsigned, unsigned, int);
int IMTFilterTDjVuL (IMTpixel**, BYTE**, IMTpixel**, IMTpixel**, unsigned, unsigned, unsigned, unsigned, unsigned, int, float, float, unsigned);
int IMTFilterTEdge (IMTpixel**, BYTE**, unsigned int, unsigned int, int, float);
int IMTFilterTEdgeDiv (IMTpixel**, BYTE**, unsigned int, unsigned int, int, float, float, float);
int IMTFilterTEdgePlus (IMTpixel**, BYTE**, unsigned int, unsigned int, int, float, float);
int IMTFilterTEntValue (IMTpixel**, unsigned, unsigned);
int IMTFilterTEnt (IMTpixel**, BYTE**, unsigned, unsigned);
Expand Down
25 changes: 25 additions & 0 deletions src/lib/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,31 @@ float IMTFilterMathSharpenBadMetric (IMTpixel** p_im, IMTpixel** m_im, unsigned

///////////////////////////////////////////////////////////////////////////////

void IMTFilterMathSqr (IMTpixel** p_im, unsigned height, unsigned width)
{
unsigned y, x, d;
float im;

for ( y = 0; y < height; y++ )
{
for ( x = 0; x < width; x++ )
{
for (d = 0; d < 3; d++)
{
im = (float)p_im[y][x].c[d];
im++;
im *= im;
im /= 256.0;
im -= 0.5;
p_im[y][x].c[d] = ByteClamp((int)im);
}
p_im[y][x] = IMTcalcS (p_im[y][x]);
}
}
}

///////////////////////////////////////////////////////////////////////////////

void IMTFilterMathThreshold (IMTpixel** p_im, IMTpixel** m_im, BYTE** d_im, unsigned height, unsigned width, int delta)
{
unsigned y, x;
Expand Down
53 changes: 25 additions & 28 deletions src/lib/threshold.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,29 +817,8 @@ int IMTFilterTBiModC (IMTpixel** p_im, BYTE** d_im, unsigned height, unsigned wi

int IMTFilterTBlurDiv (IMTpixel** p_im, BYTE** d_im, unsigned int height, unsigned int width, int radius, float sensitivity, float delta)
{
unsigned int y, x;
float origin, blur, edge, edgenorm, retval;
int threshold = 0;
IMTpixel** b_im = IMTalloc(height, width);

IMTFilterGaussBlur (p_im, b_im, height, width, radius);
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
origin = p_im[y][x].s;
blur = b_im[y][x].s;
edge = (blur + 1.0f) / (origin + 1.0f) - 0.5f;
edgenorm = sensitivity * edge + (1.0f - sensitivity);
retval = (edgenorm > 0.0f) ? (origin / edgenorm) : origin;
retval = (retval < 0.0f) ? 0.0f : (retval < 765.0f) ? retval : 765.0f;
b_im[y][x].s = (WORD)(retval + 0.5f);
}
}
threshold = IMTFilterTBiMod (b_im, d_im, height, width, delta);
IMTfree(b_im, height);

return threshold;
/* DEPRECATED */
return IMTFilterTEdgeDiv (p_im, d_im, height, width, radius, 0.0f, sensitivity, delta);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1915,10 +1894,10 @@ int IMTFilterTEdge (IMTpixel** p_im, BYTE** d_im, unsigned int height, unsigned

////////////////////////////////////////////////////////////////////////////////

int IMTFilterTEdgePlus (IMTpixel** p_im, BYTE** d_im, unsigned int height, unsigned int width, int radius, float sensitivity, float delta)
int IMTFilterTEdgeDiv (IMTpixel** p_im, BYTE** d_im, unsigned int height, unsigned int width, int radius, float sensitivity, float sensitivityblur, float delta)
{
unsigned int y, x;
float origin, blur, edge, edgeplus, retval;
float origin, blur, edge, edgeplus, edgenorm, retval;
int threshold = 0;
IMTpixel** b_im = IMTalloc(height, width);

Expand All @@ -1929,9 +1908,19 @@ int IMTFilterTEdgePlus (IMTpixel** p_im, BYTE** d_im, unsigned int height, unsig
{
origin = p_im[y][x].s;
blur = b_im[y][x].s;
edge = (origin + 1.0f) / (blur + 1.0f) - 0.5f;
edgeplus = origin * edge;
retval = sensitivity * edgeplus + (1.0f - sensitivity) * origin;
retval = origin;
if (sensitivity > 0.0f)
{
edge = (origin + 1.0f) / (blur + 1.0f) - 0.5f;
edgeplus = origin * edge;
retval = sensitivity * edgeplus + (1.0f - sensitivity) * origin;
}
if (sensitivityblur > 0.0f)
{
edge = (blur + 1.0f) / (retval + 1.0f) - 0.5f;
edgenorm = sensitivityblur * edge + (1.0f - sensitivityblur);
retval = (edgenorm > 0.0f) ? (origin / edgenorm) : origin;
}
retval = (retval < 0.0f) ? 0.0f : (retval < 765.0f) ? retval : 765.0f;
b_im[y][x].s = (WORD)(retval + 0.5f);
}
Expand All @@ -1944,6 +1933,14 @@ int IMTFilterTEdgePlus (IMTpixel** p_im, BYTE** d_im, unsigned int height, unsig

///////////////////////////////////////////////////////////////////////////////

int IMTFilterTEdgePlus (IMTpixel** p_im, BYTE** d_im, unsigned int height, unsigned int width, int radius, float sensitivity, float delta)
{
/* DEPRECATED */
return IMTFilterTEdgeDiv (p_im, d_im, height, width, radius, sensitivity, 0.0f, delta);
}

///////////////////////////////////////////////////////////////////////////////

int IMTFilterTEntValue (IMTpixel** p_im, unsigned height, unsigned width)
{
unsigned i, t, cn = 768;
Expand Down
12 changes: 11 additions & 1 deletion src/tglobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void ImthresholdFilterTGlobalUsage()
{
printf("Usage : imthreshold-tglobal [options] <input_image> <output_image>(BW)\n\n");
printf("options:\n");
printf(" -2 color sqr (bool, optional, default = false)\n");
printf(" -b color correct (bool, optional, default = false)\n");
printf(" -d N delta (int, optional, default = 0)\n");
printf(" -f str name filter:\n");
Expand Down Expand Up @@ -78,17 +79,21 @@ int main(int argc, char *argv[])
bool weight = false;
bool fnorm = false;
bool fmirror = false;
bool fcsqr = false;
bool fccor = false;
bool finv = false;
bool fhelp = false;
int threshold;
char *namefilter, *csp, *cspn;
namefilter = (char*)"bimod";
csp = (char*)"rgb";
while ((opt = getopt(argc, argv, ":bd:f:ik:m:np:q:s:wzh")) != -1)
while ((opt = getopt(argc, argv, ":2bd:f:ik:m:np:q:s:wzh")) != -1)
{
switch(opt)
{
case '2':
fcsqr = true;
break;
case 'b':
fccor = true;
break;
Expand Down Expand Up @@ -168,6 +173,11 @@ int main(int argc, char *argv[])
cspn = IMTFilterRGBtoCSP(p_im, height, width, csp, 1);
printf("ColorSpace= %s\n", cspn);

if (fcsqr)
{
IMTFilterMathSqr(p_im, height, width);
printf("ColorSqr= true\n");
}
if (fccor)
{
IMTFilterSCCor(p_im, height, width);
Expand Down
Loading

0 comments on commit c5d3fef

Please sign in to comment.