enable executing dilation & erosion N times...
...with optional parameter N instead of repeating the command
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
#define SSOCR2_DEFINES_H
|
||||
|
||||
/* version number */
|
||||
#define VERSION "2.17.0"
|
||||
#define VERSION "2.18.0"
|
||||
|
||||
/* states */
|
||||
#define FIND_DARK 0
|
||||
|
||||
@@ -105,8 +105,12 @@ void usage(char *name, FILE *f)
|
||||
fprintf(f, " use -l help for list of KEYWORDS\n");
|
||||
fprintf(f, " -S, --ascii-art-segments print recognized segments a ASCII art\n");
|
||||
fprintf(f, " -X, --print-as-hex change output format to hexadecimal\n");
|
||||
fprintf(f, "\nCommands: dilation dilation algorithm (with mask of 1 pixel)\n");
|
||||
fprintf(f, " erosion erosion algorithm (with mask of 9 pixels)\n");
|
||||
fprintf(f, "\nCommands: dilation [N] [N times] dilation algorithm"
|
||||
"\n (set_pixels_filter with mask"
|
||||
" of 1 pixel)\n");
|
||||
fprintf(f, " erosion [N] [N times] erosion algorithm\n"
|
||||
" (set_pixels_filter with mask"
|
||||
" of 9 pixels)\n");
|
||||
fprintf(f, " closing [N] closing algorithm\n");
|
||||
fprintf(f, " ([N times] dilation then [N times] erosion)\n");
|
||||
fprintf(f, " opening [N] opening algorithm\n");
|
||||
|
||||
@@ -179,32 +179,15 @@ Imlib_Image set_pixels_filter(Imlib_Image *source_image, double thresh,
|
||||
return new_image;
|
||||
}
|
||||
|
||||
Imlib_Image dilation(Imlib_Image *source_image, double thresh, luminance_t lt)
|
||||
{
|
||||
return set_pixels_filter(source_image, thresh, lt, 1);
|
||||
}
|
||||
|
||||
Imlib_Image erosion(Imlib_Image *source_image, double thresh, luminance_t lt)
|
||||
{
|
||||
return set_pixels_filter(source_image, thresh, lt, 9);
|
||||
}
|
||||
|
||||
Imlib_Image closing(Imlib_Image *source_image,double thresh,luminance_t lt,int n)
|
||||
Imlib_Image set_pixels_filter_iter(Imlib_Image *source_image, double thresh,
|
||||
luminance_t lt, int mask, int iter)
|
||||
{
|
||||
int i;
|
||||
Imlib_Image temp_image1, temp_image2;
|
||||
/* dilation n times */
|
||||
imlib_context_set_image(*source_image);
|
||||
temp_image1 = temp_image2 = imlib_clone_image();
|
||||
for(i=0; i<n; i++) {
|
||||
temp_image2 = dilation(&temp_image1, thresh, lt);
|
||||
imlib_context_set_image(temp_image1);
|
||||
imlib_free_image();
|
||||
temp_image1 = temp_image2;
|
||||
}
|
||||
/* erosion n times */
|
||||
for(i=0; i<n; i++) {
|
||||
temp_image2 = erosion(&temp_image1, thresh, lt);
|
||||
for(i=0; i<iter; i++) {
|
||||
temp_image2 = set_pixels_filter(&temp_image1, thresh, lt, mask);
|
||||
imlib_context_set_image(temp_image1);
|
||||
imlib_free_image();
|
||||
temp_image1 = temp_image2;
|
||||
@@ -212,27 +195,42 @@ Imlib_Image closing(Imlib_Image *source_image,double thresh,luminance_t lt,int n
|
||||
return temp_image2;
|
||||
}
|
||||
|
||||
Imlib_Image opening(Imlib_Image *source_image,double thresh,luminance_t lt,int n)
|
||||
Imlib_Image dilation(Imlib_Image *source_image, double thresh, luminance_t lt,
|
||||
int n)
|
||||
{
|
||||
int i;
|
||||
Imlib_Image temp_image1, temp_image2;
|
||||
/* erosion n times */
|
||||
imlib_context_set_image(*source_image);
|
||||
temp_image1 = temp_image2 = imlib_clone_image();
|
||||
for(i=0; i<n; i++) {
|
||||
temp_image2 = erosion(&temp_image1, thresh, lt);
|
||||
imlib_context_set_image(temp_image1);
|
||||
imlib_free_image();
|
||||
temp_image1 = temp_image2;
|
||||
}
|
||||
return set_pixels_filter_iter(source_image, thresh, lt, 1, n);
|
||||
}
|
||||
|
||||
Imlib_Image erosion(Imlib_Image *source_image, double thresh, luminance_t lt,
|
||||
int n)
|
||||
{
|
||||
return set_pixels_filter_iter(source_image, thresh, lt, 9, n);
|
||||
}
|
||||
|
||||
Imlib_Image closing(Imlib_Image *source_image, double thresh, luminance_t lt,
|
||||
int n)
|
||||
{
|
||||
Imlib_Image temp_image, return_image;
|
||||
/* dilation n times */
|
||||
for(i=0; i<n; i++) {
|
||||
temp_image2 = dilation(&temp_image1, thresh, lt);
|
||||
imlib_context_set_image(temp_image1);
|
||||
imlib_free_image();
|
||||
temp_image1 = temp_image2;
|
||||
}
|
||||
return temp_image2;
|
||||
temp_image = dilation(source_image, thresh, lt, n);
|
||||
/* erosion n times */
|
||||
return_image = erosion(&temp_image, thresh, lt, n);
|
||||
imlib_context_set_image(temp_image);
|
||||
imlib_free_image();
|
||||
return return_image;
|
||||
}
|
||||
|
||||
Imlib_Image opening(Imlib_Image *source_image, double thresh, luminance_t lt,
|
||||
int n)
|
||||
{
|
||||
Imlib_Image temp_image, return_image;
|
||||
/* erosion n times */
|
||||
temp_image = erosion(source_image, thresh, lt, n);
|
||||
/* dilation n times */
|
||||
return_image = dilation(&temp_image, thresh, lt, n);
|
||||
imlib_context_set_image(temp_image);
|
||||
imlib_free_image();
|
||||
return return_image;
|
||||
}
|
||||
|
||||
/* set pixels with (brightness) value lower than threshold that have more than
|
||||
|
||||
@@ -51,11 +51,17 @@ int is_pixel_set(int value, double threshold);
|
||||
Imlib_Image set_pixels_filter(Imlib_Image *source_image, double thresh,
|
||||
luminance_t lt, int mask);
|
||||
|
||||
/* perform set pixel filter operation iter times */
|
||||
Imlib_Image set_pixels_filter_iter(Imlib_Image *source_image, double thresh,
|
||||
luminance_t lt, int mask, int iter);
|
||||
|
||||
/* shortcut for dilation */
|
||||
Imlib_Image dilation(Imlib_Image *source_image, double thresh, luminance_t lt);
|
||||
Imlib_Image dilation(Imlib_Image *source_image, double thresh, luminance_t lt,
|
||||
int n);
|
||||
|
||||
/* shortcut for erosion */
|
||||
Imlib_Image erosion(Imlib_Image *source_image, double thresh, luminance_t lt);
|
||||
Imlib_Image erosion(Imlib_Image *source_image, double thresh, luminance_t lt,
|
||||
int n);
|
||||
|
||||
/* shortcut for closing */
|
||||
Imlib_Image closing(Imlib_Image *source_image, double thresh, luminance_t lt,
|
||||
|
||||
+16
-2
@@ -170,14 +170,28 @@ Each hexadecimal number printed is the logical
|
||||
.I or
|
||||
of the set segments.
|
||||
.SH COMMANDS
|
||||
.SS dilation
|
||||
.SS dilation [N]
|
||||
Filter image using dilation algorithm.
|
||||
Any pixel with at least one neighbour pixel set in the source image will be
|
||||
set in the filtered image.
|
||||
.SS erosion
|
||||
If a number
|
||||
.B N
|
||||
>
|
||||
.I 1
|
||||
is specified, the dilation algorithm is executed
|
||||
.B N
|
||||
times.
|
||||
.SS erosion [N]
|
||||
Filter image using erosion algorithm.
|
||||
Any pixel with every neighbour pixel set in the source image will be set
|
||||
in the filtered image.
|
||||
If a number
|
||||
.B N
|
||||
>
|
||||
.I 1
|
||||
is specified, the erosion algorithm is executed
|
||||
.B N
|
||||
times.
|
||||
.SS closing [N]
|
||||
Filter image using closing algorithm, i.e. erosion and then dilation.
|
||||
If a number
|
||||
|
||||
@@ -463,14 +463,40 @@ int main(int argc, char **argv)
|
||||
if(optind < argc-1) /* then process commands */ {
|
||||
for(i=optind; i<argc-1; i++) {
|
||||
if(strcasecmp("dilation",argv[i]) == 0) {
|
||||
if(flags & VERBOSE) fputs(" processing dilation\n", stderr);
|
||||
new_image = dilation(&image, thresh, lt);
|
||||
int n=atoi(argv[i+1]);
|
||||
if((n>0) && (i+1<argc-1)) {
|
||||
if(flags & VERBOSE) {
|
||||
fprintf(stderr, " processing dilation %d", n);
|
||||
if(flags & DEBUG_OUTPUT) {
|
||||
fprintf(stderr, " (from string %s)", argv[i+1]);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
i++;
|
||||
new_image = dilation(&image, thresh, lt, n);
|
||||
} else {
|
||||
if(flags & VERBOSE) fputs(" processing dilation (1)\n", stderr);
|
||||
new_image = dilation(&image, thresh, lt, 1);
|
||||
}
|
||||
imlib_context_set_image(image);
|
||||
imlib_free_image();
|
||||
image = new_image;
|
||||
} else if(strcasecmp("erosion",argv[i]) == 0) {
|
||||
if(flags & VERBOSE) fputs(" processing erosion\n", stderr);
|
||||
new_image = erosion(&image, thresh, lt);
|
||||
int n=atoi(argv[i+1]);
|
||||
if((n>0) && (i+1<argc-1)) {
|
||||
if(flags & VERBOSE) {
|
||||
fprintf(stderr, " processing erosion %d", n);
|
||||
if(flags & DEBUG_OUTPUT) {
|
||||
fprintf(stderr, " (from string %s)", argv[i+1]);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
i++;
|
||||
new_image = erosion(&image, thresh, lt, n);
|
||||
} else {
|
||||
if(flags & VERBOSE) fputs(" processing erosion (1)\n", stderr);
|
||||
new_image = erosion(&image, thresh, lt, 1);
|
||||
}
|
||||
imlib_context_set_image(image);
|
||||
imlib_free_image();
|
||||
image = new_image;
|
||||
|
||||
Reference in New Issue
Block a user