Is it possible to define a kernel within a kernel?

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
galwaylibrary
Posts: 5
Joined: 2012-05-24T02:45:58-07:00
Authentication code: 13

Is it possible to define a kernel within a kernel?

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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' 
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply