Page 1 of 1

shrink&swell

Posted: 2010-09-28T17:53:16-07:00
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.

Re: shrink&swell

Posted: 2010-09-28T19:03:43-07:00
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.

Re: shrink&swell

Posted: 2010-09-28T19:21:06-07:00
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.

Re: shrink&swell

Posted: 2010-09-28T19:22:22-07:00
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.

Re: shrink&swell

Posted: 2010-09-28T20:01:32-07:00
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 :-)