Intensity methods of morphology command -- can there be colors of the same 'intensity'?

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
vadim
Posts: 7
Joined: 2015-07-02T10:05:21-07:00
Authentication code: 1151

Intensity methods of morphology command -- can there be colors of the same 'intensity'?

Post by vadim »

I.e. can we have 2 colors, whose boundary will not be affected by intensity variants of morphology command? What's the exact formula for 'intensity'? It seems to be not

Code: Select all

0.299*red + 0.587*green + 0.114*blue
because with

Code: Select all

convert +antialias -size 200x200 xc:rgb(0%,100%,0%) -fill rgb(100%,70.263980%,0%) -font Cambria-Bold -pointsize 70 -gravity center -draw "text 10,10 'Hello'" -morphology dilatei disk:3 test_1.png
text is shrunk, but with

Code: Select all

convert +antialias -size 200x200 xc:rgb(0%,100%,0%) -fill rgb(100%,70.263981%,0%) -font Cambria-Bold -pointsize 70 -gravity center -draw "text 10,10 'Hello'" -morphology dilatei disk:3 test_1.png
text is widened. But, even if the formula is not a great secret, is there a case, in source code, that specially deals with equal intensities? Or maybe boundary between different colors will never stay in place?

Code: Select all

convert -version
Version: ImageMagick 6.9.1-1 Q16 x86 2015-03-20 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: DPC Modules OpenMP
Delegates (built-in): bzlib cairo freetype jbig jng jp2 jpeg lcms lqr openexr pa
ngocairo png ps rsvg tiff webp xml zlib
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Intensity methods of morphology command -- can there be colors of the same 'intensity'?

Post by snibgo »

The intensity calculation depends on the current "-intensity" setting. For example, insert "-intensity RMS" before the morphology.

See http://www.imagemagick.org/script/comma ... #intensity

I don't know if the code treats two equal intensities but different colours any differently to equal colours. I suspect it doesn't. [EDIT: You could test this with "-intensity Brightness" that doesn't involve floating-point arithmetic.]
snibgo's IM pages: im.snibgo.com
vadim
Posts: 7
Joined: 2015-07-02T10:05:21-07:00
Authentication code: 1151

Re: Intensity methods of morphology command -- can there be colors of the same 'intensity'?

Post by vadim »

Thanks a lot, it works exactly as you said. Boundaries between colors of the same intensity are not affected, and, yes, "Brightness" will suit perfectly, because image uses limited palette, and colors can be mapped to any set before processing and back afterwards.
vadim
Posts: 7
Joined: 2015-07-02T10:05:21-07:00
Authentication code: 1151

Re: Intensity methods of morphology command -- can there be colors of the same 'intensity'?

Post by vadim »

An update:
Boundaries between colors of the same intensity are not affected
Actually, the whole image is shifted, and result doesn't look right to me. Here is an exaggerated example:

Code: Select all

convert +antialias -size 200x200 xc:#00FF00 -fill #FF0000 -draw "rectangle 50,50,150,150" -fill black -draw "rectangle 80,20,120,180" test_1.png

convert test_1.png -intensity Brightness -morphology dilatei octagon:20 test_2.png
test_1.png:
Image
test_2.png:
Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Intensity methods of morphology command -- can there be colors of the same 'intensity'?

Post by snibgo »

I would expect it to be symmetrical, as the ordinary "dilate" is. Perhaps this is a bug.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Intensity methods of morphology command -- can there be colors of the same 'intensity'?

Post by fmw42 »

convert test_1.png -intensity Brightness -morphology dilatei octagon:20 test_2.png
This may just be a typo in your post, but dilate is misspelled as dilatei.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Intensity methods of morphology command -- can there be colors of the same 'intensity'?

Post by snibgo »

Whose post has "lidatei"? "dilatei" is short for "DilateIntensity".
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Intensity methods of morphology command -- can there be colors of the same 'intensity'?

Post by fmw42 »

snibgo wrote:Whose post has "lidatei"? "dilatei" is short for "DilateIntensity".
I have dislexia (of the fingers) when I type. :wink: It is fixed now in my comment.

Sorry, I had no idea IM accepted that abbreviation. I thought it was an extra character at the end.
Post Reply