Weihang Jian
Weihang Jian

Reputation: 8735

Why Imagemagick's morphology dilation algorithm differs from mathematical definition?

Origin Image

0 0 0
0 1 0
0 0 0

generated by:

$ convert -size 3x3 xc:black -fill white -draw 'point 1,1' origin.png

Dilation Process

Use a 2x1 rectangle as the kernel with central point (0,0):

processed by:

$ convert origin.png -morphology Dilate Rectangle:2x1+0+0 output.png

Expected Output

0 0 0
1 1 0
0 0 0

Actual Output

0 0 0
0 1 1
0 0 0

Question

Why the output is unexpected? I wonder how ImageMagick processes dilation.

Here is my understanding:

When the kernel's central point iterates to the position (0,1) of the original image:

I thought (0,1) should have been 1 after AND operations.

Upvotes: 0

Views: 355

Answers (1)

fmw42
fmw42

Reputation: 53091

The "center point" of a 2x1 kernel is between pixels. So you have to choose which one is the official "origin". It is arbitrary. But you can set the origin in ImageMagick when defining the kernel. See https://imagemagick.org/Usage/morphology/#user

For example for a 2x1 kernel, it could be either

2x1+0+0: 0,1

or

2x1+1+0: 0,1


Upvotes: -1

Related Questions