How to draw a shape around pixels?

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
IGSo
Posts: 3
Joined: 2019-11-07T03:39:20-07:00
Authentication code: 1152

How to draw a shape around pixels?

Post by IGSo » 2019-11-07T03:55:47-07:00

Hi,

I am working on a project where I compare a bunch of images with one "good" image. The differences (if any) are small (around 10-20 px) so I would like to add a ring/square to be able to see them easier. The image attached is an example of the result I want to achieve. I know how to get the output showing the differences in a certain colour, but how can I draw a ring around the pixel "islands"?
I tried with

Code: Select all

-morphology Dilate Ring
but that takes every single pixel.

Thank you for your help.

PS: I am using IM7 on Cygwin for Windows 10.

Image

snibgo
Posts: 12301
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to draw a shape around pixels?

Post by snibgo » 2019-11-07T04:55:44-07:00

I suggest something like:

Code: Select all

magick in.png -fill None -stroke Red -draw "translate 100,100 roundRectangle -25,-25,25,25,10,10" out.png
I have split the dimensions of the shape from its location ("translate"). So the same shape can easily be drawn centred at any location.

See https://www.imagemagick.org/script/comm ... s.php#draw for other shapes.
snibgo's IM pages: im.snibgo.com

IGSo
Posts: 3
Joined: 2019-11-07T03:39:20-07:00
Authentication code: 1152

Re: How to draw a shape around pixels?

Post by IGSo » 2019-11-07T08:11:25-07:00

Thank you @snibgo.
But that would draw a rectangle with rounded corners in a coordinate of my choice, right? What I don't know is how to tell IM to draw the shape where it finds the difference between the images.
Right now I have an image which is the result of comparing two similar images. This image has small pixel areas that I would like to draw a shape around. Sorry if I didn't make myself understood.

Thank you again for you answer.

snibgo
Posts: 12301
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to draw a shape around pixels?

Post by snibgo » 2019-11-07T08:29:10-07:00

IGSo wrote:Right now I have an image which is the result of comparing two similar images. This image has small pixel areas that I would like to draw a shape around.
"-connected-components" can find the bounding rectangles of connected areas. That can create a text list of the rectangles, which a script can use to build the "-draw" commands.
snibgo's IM pages: im.snibgo.com

IGSo
Posts: 3
Joined: 2019-11-07T03:39:20-07:00
Authentication code: 1152

Re: How to draw a shape around pixels?

Post by IGSo » 2019-11-08T03:59:29-07:00

Thank you. It sounds way too advanced for a newbie like me but I will read about "-connected-components" and I will see how far I get. Thank you for leading me in the right direction.

Cheers

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to draw a shape around pixels?

Post by fmw42 » 2019-11-08T10:41:19-07:00

If you get stuck, post your difference image and perhaps we can help. See https://imagemagick.org/script/connected-components.php

Post Reply