Page 1 of 3

getting the edges of an image

Posted: 2011-05-07T03:37:34-07:00
by sin
hi,

I am using Imagemagick on windows. how can i get the edges of an image such that the output should have
- white background
- sharp edges of the image
- edges should be in black color
- in the total image only the edges should be black and remaining else should be in white.

please tel me how can i get this?

Re: getting the edges of an image

Posted: 2011-05-07T09:25:43-07:00
by fmw42
It is very hard to prescribe some technique without seeing the image to which it will applied! Can you post a link to your image so that others can test with it? Find some free image hosting web site, post your image there, then link it here.

Please also read the following about posting including your IM version and platform.

Thanks.

Re: getting the edges of an image

Posted: 2011-05-08T05:45:14-07:00
by sin
fmw42 wrote:It is very hard to prescribe some technique without seeing the image to which it will applied! Can you post a link to your image so that others can test with it? Find some free image hosting web site, post your image there, then link it here.

Please also read the following about posting including your IM version and platform.

Thanks.

okay. lets take the image in this link as an example
http://www.google.co.in/imgres?imgurl=h ... sch&itbs=1

it is an image of christmas tree. the output should be as the image in the below link
http://www.google.co.in/imgres?imgurl=h ... sch&itbs=1

ofcourse, the second image is not similar to the first one but the output should be as the second. also input can have any color as background unlike white in the first image but the output must have only white background and i need only the outline of the image(everything inside the image should be white as seen in the second image)

so please tell me how can i do this using imagemagick!!!

Re: getting the edges of an image

Posted: 2011-05-08T10:51:06-07:00
by fmw42
Your first link is malformed, chopped off or for some reason does not work.

Re: getting the edges of an image

Posted: 2011-05-08T11:57:57-07:00
by sin
fmw42 wrote:Your first link is malformed, chopped off or for some reason does not work.


the first link is working. it is the image of a christmas tree with green filled inside.

Re: getting the edges of an image

Posted: 2011-05-08T12:21:58-07:00
by fmw42

Code: Select all

Not Found

The requested URL /openclipart/clipart/recreation/holiday/christmas/christmas_tree_02_l.png was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I searched google and found another image. So here are two possible approaches.

Image

Convert to grayscale, extract edges, flatten alpha channel to black:
convert christmas_tree_01.png -colorspace gray -edge 2 -background black -flatten christmas_tree_01_gray_edge2_flat.png
Image

Extract alpha channel, extract edge from alpha channel:
convert christmas_tree_01.png -alpha extract -edge 2 christmas_tree_01_alpha_edge2.png
Image

see
http://www.imagemagick.org/script/comma ... s.php#edge
http://www.imagemagick.org/Usage/transform/#edge
http://www.imagemagick.org/Usage/masking/#alpha_extract

Re: getting the edges of an image

Posted: 2011-05-09T07:53:21-07:00
by sin
yeah..correct :). but I want the black thing into white and white into black.

what i mean to say is I want the image in such a way that not only its background should be in white color but also the color inside the tree should be white. that is, I want only the outline of the tree(in the black color) and rest of the image should be black.

Re: getting the edges of an image

Posted: 2011-05-09T09:57:39-07:00
by fmw42
Simply add -negate.

convert christmas_tree_01.png -alpha extract -edge 2 -negate christmas_tree_01_alpha_edge2n.png

Image

Re: getting the edges of an image

Posted: 2011-05-13T04:35:06-07:00
by sin
i am using Imagemagick 6.6.9 for windows. in that im not getting this alpha extraction command. when i try to execute this command it is showing an error of unrecognisable alpha...

how could i overcoem this problem?????

Re: getting the edges of an image

Posted: 2011-05-13T10:06:50-07:00
by fmw42
this command

convert christmas_tree_01.png -alpha extract -edge 2 -negate christmas_tree_01_alpha_edge2n.png

should work fine on any IM platform that is using IM 6.6.9.x

I am not sure what is happening on your Windows system and am not a Windows user. Perhaps some other Windows user could verify if this works or not.

Alternate should be

convert christmas_tree_01.png -channel a -separate -edge2 -negate christmas_tree_01_alpha_edge2n.png

Re: getting the edges of an image

Posted: 2011-05-13T19:06:23-07:00
by sin
when i tried the above alternate command the output image is completely blank. I am using Windows 7 operating systems but i don't know why i am facing this type of problem.

but i want this command to work. it is key to our project. already some work has been halted. so please help me in accomplishing this?

Re: getting the edges of an image

Posted: 2011-05-13T19:34:52-07:00
by fmw42
I am sorry, I don't use Windows and don't know why you are having trouble. The above commands work fine for me on my Mac OSX IM 6.6.9.8 Q16. Perhaps you need to re-install IM. At this point, some other Windows user will have to try to help you or one of the IM developers.

What is your exact command and what is the exact error message?

Is it possible you have two version of IM installed and they are getting confused?

type

convert -version

what does it tell you?

Is it possible you are using the Windows convert command instead of the IM convert command -- you may need to rename the IM convert command to im_convert?

Re: getting the edges of an image

Posted: 2011-05-14T03:43:38-07:00
by HugoRune
I cannot reproduce this problem.

> convert christmas_tree_01.png -alpha extract -edge 2 -negate christmas_tree_01_alpha_edge2n.png
works as expected on my system (Windows XP)

Code: Select all

>convert -version
Version: ImageMagick 6.6.9-8 2011-05-04 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
I also tried with 6.6.8, same result.

Re: getting the edges of an image

Posted: 2011-05-14T04:16:21-07:00
by Bonzo
Works OK with 6.5.9 on Vista OK as well.

Re: getting the edges of an image

Posted: 2011-05-14T07:41:54-07:00
by sin
but why it is not working for my operating system(windows 7 32-bit)? :( :(
when i type the above commands in my pc for the above image it is showing a blank image(complete black or complete white).