Skip to content

Commit a3ed8f1

Browse files
authored
0.20171111
1 parent 6adac4f commit a3ed8f1

File tree

5 files changed

+276
-90
lines changed

5 files changed

+276
-90
lines changed

src/Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
PROGNAME = imthreshold-deskew imthreshold-rotate imthreshold-fadsmooth imthreshold-fautoinv imthreshold-fbgdiv imthreshold-fbgfglsep imthreshold-fdespeckle imthreshold-fdneuro imthreshold-fgreyworld imthreshold-fillumc imthreshold-finfo imthreshold-fkmeans imthreshold-flevell imthreshold-flevelmean imthreshold-flevelsigma imthreshold-fperon imthreshold-fposterize imthreshold-fpmean imthreshold-fretinex imthreshold-frs imthreshold-fselgauss imthreshold-fshrink imthreshold-funripple imthreshold-funsharp imthreshold-fwiener imthreshold-fwhitefill imthreshold-sbicub imthreshold-sbilin imthreshold-sbwmag2 imthreshold-scris imthreshold-shris imthreshold-snearest imthreshold-tabutaleb imthreshold-tbernsen imthreshold-tbht imthreshold-tbimod imthreshold-tdalg imthreshold-tdither imthreshold-tdjvul imthreshold-tent imthreshold-teqbright imthreshold-tgatos imthreshold-tgrad imthreshold-thalftone2 imthreshold-tjanni imthreshold-tkmeans imthreshold-tnib imthreshold-totsu imthreshold-trot imthreshold-tsauvola imthreshold-ttext imthreshold-ttsai imthreshold-twhiterohrer
1+
PROGNAME = imthreshold-deskew imthreshold-rotate imthreshold-fadsmooth imthreshold-fautoinv imthreshold-fbgdiv imthreshold-fbgfglsep imthreshold-fdespeckle imthreshold-fdneuro imthreshold-fdphist imthreshold-fgreyworld imthreshold-fillumc imthreshold-finfo imthreshold-fkmeans imthreshold-flevell imthreshold-flevelmean imthreshold-flevelsigma imthreshold-fperon imthreshold-fposterize imthreshold-fpmean imthreshold-fretinex imthreshold-frs imthreshold-fselgauss imthreshold-fshrink imthreshold-funripple imthreshold-funsharp imthreshold-fwiener imthreshold-fwhitefill imthreshold-sbicub imthreshold-sbilin imthreshold-sbwmag2 imthreshold-scris imthreshold-shris imthreshold-snearest imthreshold-tabutaleb imthreshold-tbernsen imthreshold-tbht imthreshold-tbimod imthreshold-tdalg imthreshold-tdither imthreshold-tdjvul imthreshold-tent imthreshold-teqbright imthreshold-tgatos imthreshold-tgrad imthreshold-thalftone2 imthreshold-tjanni imthreshold-tkmeans imthreshold-tnib imthreshold-totsu imthreshold-trot imthreshold-tsauvola imthreshold-ttext imthreshold-ttsai imthreshold-twhiterohrer
22
CPP = g++
33
CFLAGS = -DUNIX -O2 -Wall
44
LIBS = -lfreeimage
55
VER = 0
6-
VERB = 20171101
6+
VERB = 20171111
77
COMMON = libimthreshold.so.$(VER) libimthresholdfreeimage.so.$(VER)
88
PREFIX = /usr/local
99
INCPREFIX = $(PREFIX)/include
@@ -51,15 +51,18 @@ imthreshold-fbgdiv: fbgdiv.cpp $(COMMON)
5151
imthreshold-fbgfglsep: fbgfglsep.cpp $(COMMON)
5252
$(CPP) $(CFLAGS) $(LIBS) $^ -s -o $@
5353

54-
imthreshold-fdespeckle: fdespeckle.cpp $(COMMON)
54+
imthreshold-fcolset: fcolset.cpp $(COMMON)
5555
$(CPP) $(CFLAGS) $(LIBS) $^ -s -o $@
5656

57-
imthreshold-fcolset: fcolset.cpp $(COMMON)
57+
imthreshold-fdespeckle: fdespeckle.cpp $(COMMON)
5858
$(CPP) $(CFLAGS) $(LIBS) $^ -s -o $@
5959

6060
imthreshold-fdneuro: fdneuro.cpp $(COMMON)
6161
$(CPP) $(CFLAGS) $(LIBS) $^ -s -o $@
6262

63+
imthreshold-fdphist: fdphist.cpp $(COMMON)
64+
$(CPP) $(CFLAGS) $(LIBS) $^ -s -o $@
65+
6366
imthreshold-fgreyworld: fgreyworld.cpp $(COMMON)
6467
$(CPP) $(CFLAGS) $(LIBS) $^ -s -o $@
6568

src/fdphist.cpp

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// ==========================================================
2+
// Despeckle histogram filter (for BW only) based on the FreeImage library
3+
//
4+
// This code is taken from the CxImage Library at http://www.xdp.it/cximage.htm
5+
// and adapted for the FreeImage Library
6+
//
7+
8+
#include <unistd.h>
9+
#include <FreeImage.h>
10+
#include "imthresholdfreeimage.h"
11+
12+
////////////////////////////////////////////////////////////////////////////////
13+
14+
void ImthresholdFilterDphistTitle()
15+
{
16+
printf("ImThreshold.\n");
17+
printf("BookScanLib Project: http://djvu-soft.narod.ru/\n\n");
18+
printf("Despeckle histogram filter (for BW only) based on the FreeImage library.\n");
19+
printf("TerraNoNames: http://mykaralw.narod.ru/.\n\n");
20+
}
21+
22+
void ImthresholdFilterDphistUsage()
23+
{
24+
printf("Usage : imthreshold-fdphist [options] <input_file>(BW) <output_file>(BW)\n\n");
25+
printf("options:\n");
26+
printf(" -i invert (bool, optional, default = false)\n");
27+
printf(" -h this help\n");
28+
}
29+
30+
// ----------------------------------------------------------
31+
32+
int main(int argc, char *argv[])
33+
{
34+
// call this ONLY when linking with FreeImage as a static library
35+
#ifdef FREEIMAGE_LIB
36+
FreeImage_Initialise();
37+
#endif // FREEIMAGE_LIB
38+
39+
int opt;
40+
double kdp = 0.0;
41+
bool finv = false;
42+
bool fhelp = false;
43+
while ((opt = getopt(argc, argv, ":ih")) != -1)
44+
{
45+
switch(opt)
46+
{
47+
case 'i':
48+
finv = true;
49+
break;
50+
case 'h':
51+
fhelp = true;
52+
break;
53+
case ':':
54+
printf("option needs a value\n");
55+
break;
56+
case '?':
57+
printf("unknown option: %c\n", optopt);
58+
break;
59+
}
60+
}
61+
62+
ImthresholdFilterDphistTitle();
63+
64+
if(optind + 2 > argc || fhelp)
65+
{
66+
ImthresholdFilterDphistUsage();;
67+
return 0;
68+
}
69+
const char *src_filename = argv[optind];
70+
const char *output_filename = argv[optind + 1];
71+
72+
FreeImage_SetOutputMessage(FreeImageErrorHandler);
73+
74+
printf("Input= %s\n", src_filename);
75+
FIBITMAP *dib = ImthresholdGenericLoader(src_filename, 0);
76+
if (dib)
77+
{
78+
if (FreeImage_GetImageType(dib) == FIT_BITMAP)
79+
{
80+
FIBITMAP *despeckled;
81+
if (FreeImage_GetBPP(dib) == 1)
82+
{
83+
unsigned width = FreeImage_GetWidth(dib);
84+
unsigned height = FreeImage_GetHeight(dib);
85+
unsigned y;
86+
87+
BYTE** p_im;
88+
p_im = (BYTE**)malloc(height * sizeof(BYTE*));
89+
for (y = 0; y < height; y++) {p_im[y] = (BYTE*)malloc(width * sizeof(BYTE));}
90+
91+
ImthresholdGetDataBW(dib, p_im);
92+
if (finv) {IMTFilterInvertBW(p_im, height, width);}
93+
kdp = IMTFilterDphist(p_im, height, width);
94+
printf("Despeckle= %f\n", kdp);
95+
despeckled = FreeImage_Allocate(width, height, 1);
96+
ImthresholdSetDataBW(despeckled, p_im);
97+
for (y = 0; y < height; y++){free(p_im[y]);}
98+
free(p_im);
99+
} else {
100+
despeckled = ImthresholdFilterNone(dib);
101+
printf("%s\n", "Unsupported color mode.");
102+
}
103+
104+
if (despeckled)
105+
{
106+
FREE_IMAGE_FORMAT out_fif = FreeImage_GetFIFFromFilename(output_filename);
107+
if(out_fif != FIF_UNKNOWN)
108+
{
109+
FreeImage_Save(out_fif, despeckled, output_filename, 0);
110+
printf("Output= %s\n\n", output_filename);
111+
}
112+
FreeImage_Unload(despeckled);
113+
}
114+
} else {
115+
printf("%s\n", "Unsupported format type.");
116+
FreeImage_Unload(dib);
117+
}
118+
}
119+
120+
// call this ONLY when linking with FreeImage as a static library
121+
#ifdef FREEIMAGE_LIB
122+
FreeImage_DeInitialise();
123+
#endif // FREEIMAGE_LIB
124+
125+
return 0;
126+
}

src/fposterize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void ImthresholdFilterPosterizeUsage()
3939
{
4040
printf("Usage : imthreshold-fposterize [options] <input_file> <output_file>\n\n");
4141
printf("options:\n");
42-
printf(" -t N threshold (int, optional, default = 16)\n");
42+
printf(" -d N divide factor (int, optional, default = 16)\n");
4343
printf(" -h this help\n");
4444
}
4545

@@ -56,11 +56,11 @@ int main(int argc, char *argv[])
5656
int thres = 16;
5757
bool fhelp = false;
5858
double imsh = 0;
59-
while ((opt = getopt(argc, argv, ":t:h")) != -1)
59+
while ((opt = getopt(argc, argv, ":d:h")) != -1)
6060
{
6161
switch(opt)
6262
{
63-
case 't':
63+
case 'd':
6464
thres = atof(optarg);
6565
break;
6666
case 'h':

0 commit comments

Comments
 (0)