getting the edges of an image

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?".
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

getting the edges of an image

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: getting the edges of an image

Post 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.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: getting the edges of an image

Post 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!!!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: getting the edges of an image

Post by fmw42 »

Your first link is malformed, chopped off or for some reason does not work.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: getting the edges of an image

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: getting the edges of an image

Post 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
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: getting the edges of an image

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: getting the edges of an image

Post by fmw42 »

Simply add -negate.

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

Image
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: getting the edges of an image

Post 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?????
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: getting the edges of an image

Post 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
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: getting the edges of an image

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: getting the edges of an image

Post 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?
HugoRune
Posts: 90
Joined: 2009-03-11T02:45:12-07:00
Authentication code: 8675309

Re: getting the edges of an image

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: getting the edges of an image

Post by Bonzo »

Works OK with 6.5.9 on Vista OK as well.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: getting the edges of an image

Post 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).
Post Reply