Page 1 of 1

Is it possible to define a kernel within a kernel?

Posted: 2012-06-06T02:34:11-07:00
by galwaylibrary
Hi,

I am using the following command to make four black pixels white.

mogrify -morphology thicken '6x6+2+2:\
1,1,1,1,1,1,
1,1,1,1,1,1,
1,1,0,0,1,1,
1,1,0,0,1,1,
1,1,1,1,1,1,
1,1,1,1,1,1' page20.png

If I am right, the command will only work on the origin pixel which is the first zero on the third row, reading from left to right. Can I make the command operate on all four pixels in one go?

I have tried using the 'statistic' command but it is not producing the affect I am seeking.

Any help would be much appreciated.

Regards
John

Re: Is it possible to define a kernel within a kernel?

Posted: 2012-06-06T09:20:17-07:00
by fmw42
Anthony may be able to answer your question. But there may be other ways to do what you want. Can you post a link to your image and explain a bit more about what you are trying to do in that image.

Re: Is it possible to define a kernel within a kernel?

Posted: 2012-06-06T21:51:32-07:00
by anthony
Make the pixels around the pixel undefined...

Code: Select all

mogrify -morphology thicken '7x7:
1,1,1,1,1,1,1,
1,1,1,1,1,1,1,
1,1,-,-,-,1,1,
1,1,-,0,-,1,1,
1,1,-,-,-,1,1,
1,1,1,1,1,1,1,
1,1,1,1,1,1,1' page20.png
Remember a thicken kernel is really a Hit-n-Miss Kernel, which simply turns on the pixel that is selected. This kernel will now match
any of the corners of the 2x2 block, unfortunatally it will also match just the center of a 3x3 block.

The alternative if to generate a kernel for each of the four pixels by generating a sequext of rotated the kernels!
http://www.imagemagick.org/Usage/morpho ... ed_kernels -- just add a '>' flag to your original kernel.
Note this will need 4 passes through the image so is 4 times slower!

Code: Select all

mogrify -morphology thicken '6x6+2+2>:
1,1,1,1,1,1,
1,1,1,1,1,1,
1,1,0,0,1,1,
1,1,0,0,1,1,
1,1,1,1,1,1,
1,1,1,1,1,1'  page20.png
You can check the kernels using the '"showkernel" define, or the "kernel2image" script
http://www.imagemagick.org/Usage/morphology/#showkernel

Code: Select all

kernel2image -10.2 -ms -mg -ml '' '6x6+2+2>: 
1,1,1,1,1,1,
1,1,1,1,1,1,
1,1,0,0,1,1,
1,1,0,0,1,1,
1,1,1,1,1,1,
1,1,1,1,1,1'