Page 1 of 1

Draw/add a 3 pixel pure white frame around a picture?

Posted: 2012-07-02T00:51:21-07:00
by bensto
How can I draw/add a 3 pixel wide pure white frame around an existing *.jpg or *.png picture

D:\mypicture\holidayjune\pic123.jpg

or

D:\mypicture\holidayjune\pic123.png

Keep in mind that the picture could not be rectangle but round/elliptic as well.

Ben

Re: Draw/add a 3 pixel pure white frame around a picture?

Posted: 2012-07-02T02:39:55-07:00
by Bonzo

Code: Select all

 -bordercolor White -border 3x3
Note the image will grow by 6px in the width and height.

Re: Draw/add a 3 pixel pure white frame around a picture?

Posted: 2012-07-02T10:29:42-07:00
by fmw42
Keep in mind that the picture could not be rectangle but round/elliptic as well.
I assume you mean you want a border around the non-background region.

Convert the image into a binary mask, which you can do, since the outside of the region is a known color, via -fuzz XX% -threshold or -fuzzXX% -floodfill (or use -draw to do the floodfill). The either blur and threshold the mask or use -morphology dilate/erode (depending upon polarity). Get the difference between the mask before and after thresholding. Make a copy and color it. Then composite the images together.

If you post a link to example image, we can see what you really want and perhaps provide the code.

Re: Draw/add a 3 pixel pure white frame around a picture?

Posted: 2012-07-02T11:04:28-07:00
by fmw42
In unix, this would be something like either of the following:

Image

convert rounded_corners.png -bordercolor none -border 10 \
\( -clone 0 -alpha extract -morphology edgeout octagon:3 \) \
\( -clone 1 -fuzz 20% -fill red -opaque white -fill red -opaque black \) \
+swap -compose over -composite -trim +repage rounded_corners_border1.png

Image


convert rounded_corners.png -bordercolor none -border 10 \
\( +clone -alpha extract \) \
\( +clone -alpha extract -blur 3x65000 -level 0x50% -threshold 0 \) \
\( +clone -clone 1 -compose difference -composite \) \
\( +clone -fuzz 20% -fill red -opaque white \) \
-delete 1,2 +swap -compose over -composite -trim +repage rounded_corners_border2.png

Image

Re: Draw/add a 3 pixel pure white frame around a picture?

Posted: 2012-07-02T23:57:59-07:00
by anthony
Note that the gaps are pixels which are not quite 50% transparent! (more opaque than transparent), so was throught to be 'foreground'. Remember morphology is typically a binary image operator.

The solution for anti-aliased edges is not so simple!
See Image Transformations, Edge Detection, Edge Outlines from Anti-Aliased Shapes
http://www.imagemagick.org/Usage/transform/#edge_jitter

It includes techniques to try and anti-alias binary images.

THE best technique I have found so far is to extract the shape, convert to a vector image, then draw that shape appropriately.
Edging using a Raster to Vector Converter
http://www.imagemagick.org/Usage/transform/#edge_vector
Once you have the vector stroke it with a width of 6, then overlay the original image (cutting it to 3).
It is of course the more computationally intensive too :lol: