shrink&swell

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

shrink&swell

Post by galv »

This maybe belongs to "Digital Image Processing".

I was asking someone how to improve an image before I feed it to the OCR engine (for more accurate results) and he recommended the shrink&swell method. I can't find much on it, can I do it with IM or anything else? There seems there are lots of people that know image processing here.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: shrink&swell

Post by anthony »

It would help if we knew what a shrink-and-swell method was!

Google seems to indicate the term is for Boiler size changes, or Changes in soil depending on moisture, or in Clay Pottery! I would not be surprised if it also refers to the way a submarine shrinks in size as it goes deeper!

But what that has to do with image processing that I don't know.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: shrink&swell

Post by anthony »

Found one image processing reference in paper...
http://www.google.com/url?sa=t&source=w ... Uw&cad=rja
and in http://www.eurojournals.com/ejsr_28_1_02.pdf
This paper seems to be a summery of different scanned text improvement methods.

Shrink and Swell method looks like a form of convolution.

Hmmm The equations suggest it is a thresholded area average.. if so something like...

Code: Select all

   -morphology Convolve Square:$D   -threshold $T
Where $D is the "window size" and $T the threshold.
However IM does not require the 'window' to be Square. You can just as easily use a Diamond, Disk, area

See Convolve "Mean or Average Filtering"
http://www.imagemagick.org/Usage/convolve/#mean


NOTE: the above is also closely related to simply using a Morphology Smooth operation
http://www.imagemagick.org/Usage/morphology/#smooth

In that case you only need to pick the right 'kernel shape' of the right size (Square Diamond Disk)

And Please let us know of your results.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: shrink&swell

Post by fmw42 »

I suspect it means shrink and expand (minify/magnify). Basically doing something like morphology close to fill in dark areas that may be missed. But I am not sure what method would be used to shrink and expand. Possibly resize for both or possibly scale.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: shrink&swell

Post by anthony »

On further study it has two separate thresholdes. one to remove pixels and one to add pixels.

As such it is more like..

Code: Select all

convert  {image}  -morphology  Convolve  {area}  \
         \( +clone  -threshold $T1 -clone 0 -compose multiply -composite \)  -swap 0 +delete \
         \( +clone  -threshold $T2 -clone 0 -compose screen  -composite \)  -delete 0,1 \
         {result}
the $T1 is to make pixels black, while $T2 is for making pixels white.
I recommend a Disk such as Disk:4.3 be used for area.
Or perhaps just a simple blur instead of a area mean.

This is untested but is basically the method outlined by that paper!

Fred will probably make a script to do the above for you :-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply