Image outlines that preserve grayscale values

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
cryptochrome
Posts: 8
Joined: 2012-07-26T11:24:42-07:00
Authentication code: 15

Image outlines that preserve grayscale values

Post by cryptochrome »

Suppose I have a grayscale image with a bunch of disconnected blobs, and all the pixels in a particular blob have the same (non-zero) grayscale value, and each blob has a different grayscale value associated with it. The blobs may have holes in them. Pixels not in a blob have a grayscale value of zero.

I would like an image of the outlines (say 1 pixel wide) of the blobs that preserves the grayscale values, e.g., the pixels for the outline of blob 7 have a grayscale value of 7. Pixels not in an outline should have a grayscale value of zero.

Using convert with "-edge 1" gives me the outlines, but does not preserve the grayscale values. I've searched around for how to do this with masking or compose, but haven't found or figured out a solution. I'm an IM novice.

I'm using IM 6.6.9-7 2012-02-22 Q16 on linux. Thanks for the help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image outlines that preserve grayscale values

Post by fmw42 »

I suggest you use -morphology edgin to get your grayscale edges. -morphology edgein octagon

see
http://www.imagemagick.org/Usage/morphology/#edgein
cryptochrome
Posts: 8
Joined: 2012-07-26T11:24:42-07:00
Authentication code: 15

Re: Image outlines that preserve grayscale values

Post by cryptochrome »

fmw42 wrote:I suggest you use -morphology edgin to get your grayscale edges. -morphology edgein octagon

see
http://www.imagemagick.org/Usage/morphology/#edgein
That works great, thanks.
Post Reply