Page 1 of 2

how to draw an outline for a given image

Posted: 2016-08-15T15:07:37-07:00
by acpaps
Can anyone suggest me how to draw outline for an image in C#, image is of any shape.
Thanks.

Re: how to draw an outline for a given image

Posted: 2016-08-15T15:19:17-07:00
by fmw42
Please always provide your IM version and platform. What do you mean by outline? edges in an image? or just the outside borders?

Please show an example of what you want.

Please read the top-most post in this forum at viewtopic.php?f=1&t=9620.

I have moved this topic to the User's forum.

Re: how to draw an outline for a given image

Posted: 2016-08-15T17:16:31-07:00
by acpaps
Thanks for the reply, for now i am not using any IM version, would like to know if by using IM is it possible to draw border by removing extra white spaces around image. I am trying to detect actual image and draw border/outline around that image (shape can be varied based on input).
For example, for a flower image. I would like to draw outline around that flower.
Sorry I didn't find any tool to attach images here that shows an example of what I need.

Re: how to draw an outline for a given image

Posted: 2016-08-15T18:01:07-07:00
by fmw42
Can you provide an example image? You can post to some free hosting service such as dropbox.com and put the URL here. Is the background of your flower image outside the flower a constant color or near-constant color. If not, background removal is rather hard with a cluttered background. Imagemagick does not have any direct function for the latter or the following.

See
http://clippingmagic.com/
https://www.microsoft.com/en-us/researc ... rabCut.pdf
http://docs.opencv.org/3.1.0/d8/d83/tut ... #gsc.tab=0

Re: how to draw an outline for a given image

Posted: 2016-08-16T16:31:54-07:00
by acpaps
Thank you for the reply, yes background color is constant color.
For example, take your profile pic as input. I need to draw outline only around hat and magic wand, and remove extra white space around that.

Re: how to draw an outline for a given image

Posted: 2016-08-16T17:43:28-07:00
by snibgo
Trimming off a constant-colour border is trivial: "-trim" does the job.

Drawing an edge around something is easy: "-edge 1".

There are many variations on these basic techniques.

For many example of simple usage of ImageMagick, see the usage pages: http://www.imagemagick.org/Usage/ .

Re: how to draw an outline for a given image

Posted: 2016-08-16T20:38:54-07:00
by fmw42
Here is a simple example in command line. I do not know C#

input:
Image

Code: Select all

convert A_image.gif -colorspace gray -edge 1 -fuzz 1% -trim +repage A_image_edge.gif
Image

The -fuzz 1% is not needed here since the background is exactly constant. But if you started with JPG, then the background would not be a perfectly flat colored. So you can use -fuzz XX% to allow some percent difference in the background color.

Re: how to draw an outline for a given image

Posted: 2016-08-18T12:15:15-07:00
by acpaps
Thank you so much for the reply.
I need to remove edge exactly to shape 'A' leaving inside triangle as it is. need to have border around 'A' shape.
Thank you, will do more research on how to use.

Re: how to draw an outline for a given image

Posted: 2016-08-18T14:45:31-07:00
by fmw42
Fill the hole with blue:

Code: Select all

convert A_image.gif -fuzz 85% -fill "rgb(0,0,128)" -draw "color 75,75 floodfill" -alpha off -colorspace gray -edge 1 -fuzz 1% -trim +repage A_image_edge2.gif
Image

Or add a 1 pixel border of background white, floodfill the outside of the letter A with red from the top left corner, shave off the 1 pixel border, change non-red to white and red to black, extract edge, trim off the excess region around the outside of the A.

Unix syntax:

Code: Select all

convert A_image.gif -bordercolor white -border 1 \
-fuzz 5% -fill "red" -draw "color 0,0 floodfill" -alpha off \
-shave 1x1 \
-fill white +opaque red -fill black -opaque red \
-edge 1 \
-fuzz 1% -trim +repage \
A_image_edge3.gif
Image


I used unix syntax, since you did not reply to my request to provide your IM version and platform! Syntax differs

Re: how to draw an outline for a given image

Posted: 2016-08-18T19:04:22-07:00
by fmw42
Please supply your image. You can upload to some place such as dropbox.com and put the URL here. Then we can better understand what you are trying to do.

Re: how to draw an outline for a given image

Posted: 2016-08-19T15:06:17-07:00
by acpaps
Please check the images
I have this
Image

and I need this
Image

cropped image is in image shape not regular rectangle or square

Re: how to draw an outline for a given image

Posted: 2016-08-19T16:04:27-07:00
by fmw42
I have asked for you IM version and platform, but you have not provided it. Please always provide that. Please read the top-most post in this forum at viewtopic.php?f=1&t=9620.


If on IM 6, then

Code: Select all

convert 781c0085d6.jpg -bordercolor white -border 1 -fuzz 20% -fill none -draw "matte 0,0 floodfill" -shave 1x1 result.png
If on IM 7, then

Code: Select all

magick 781c0085d6.jpg -bordercolor white -border 1 -fuzz 20% -fill none -draw "alpha 0,0 floodfill" -shave 1x1 result.png

Re: how to draw an outline for a given image

Posted: 2016-08-19T16:55:20-07:00
by acpaps
Thanks for the reply I will try the code...
About IM version, I am not using any IM version for now. I wanted to know if it possible with IM.
I would like to use C# version if possible.

Re: how to draw an outline for a given image

Posted: 2016-08-19T17:07:51-07:00
by acpaps
Is it possible to get rid of the black color part that is outside of the image
here is the result i got (I am using IM7 for this result)
Image

Re: how to draw an outline for a given image

Posted: 2016-08-19T17:28:31-07:00
by fmw42
What was your exact code? What is your IM version and platform? Why do you not answer this question?

Please read the top-most post in this forum at viewtopic.php?f=1&t=9620.


What do you get from

Code: Select all

convert -version
Your output should be transparent. If you tried to save as JPG, then that is the issue. JPG does not support transparency. Use PNG or TIFF.