Edge() with unacceptable artefacts

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
gubach
Posts: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Edge() with unacceptable artefacts

Post by gubach »

Hello,

I want to make edge images from geometric gray scale images (with a Perlmagick subprogram) but I get
unacceptable artefacts. I used the edge-function in non geometric contexts a lot and I did not care
about the artefacts there but in the geometric context it becomes unacceptable. Is the edge-function
in IM so bad or how could I avoid the artefacts? It would be an ugly media discontinuity to use
Win PS for the edge generation (which works perfectly) in an otherwise Linux IM workflow.

example (I have tried to smooth the arefacts, but none the less it is unacceptable):
source image: http://www.flickr.com/photos/gbachelier/12701896523/
edge image: http://www.flickr.com/photos/gbachelier/12701729855/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Edge() with unacceptable artefacts

Post by snibgo »

The artefacts are caused by fine detail in the source image. Perhaps that detail shouldn't be there, and the data should be black and white, but some fool has saved it as JPG.

You can remove the fine detail with threshold. As a command:

Code: Select all

convert 12701896523_c359b7a3e6_o.jpg -threshold 50% -edge 2 e.png
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Edge() with unacceptable artefacts

Post by fmw42 »

try using -morphology edgein diamond:1, it works for me on IM 6.8.8.7 Q16 Mac OSX Snow Leopard in command line.

Code: Select all

convert 12701896523_c48135e0f9_k.jpg -morphology edgein diamond:1 result.png
It produced a cleaner edge than using -edge.

The issue is that your image is not binary (it has antialiasing or fuzzy edges) and needs to be thresholded appropriately before using -edge.
gubach
Posts: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Re: Edge() with unacceptable artefacts

Post by gubach »

Code: Select all

convert 12701896523_c48135e0f9_k.jpg -morphology edgein diamond:1 result.png
yes this works much!! better. Thank you very much!

Now I need to integrate it in PerlMagick, but the description of the method Morphology on http://www.imagemagick.org/script/perl-magick.php

Morphology kernel=>string, channel=>{All, Default, Alpha, Black, Blue, CMYK, Cyan, Gray, Green, Index, Magenta, Opacity, Red, RGB, Yellow}, iterations=>integer

makes it not obvious for me how the right syntax may be. Perhaps: $image->Morphology(kernel=>'edgein', diamond=>'1');

Thanks for further help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Edge() with unacceptable artefacts

Post by fmw42 »

Sorry, I do not know PerlMagick. But I suspect you need another command. That seems to suggest that it is asking for which channel to operate on. There must be a higher level command that calls this command. Otherwise, the docs are wrong.
gubach
Posts: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Re: Edge() with unacceptable artefacts

Post by gubach »

I tried a workaround where I write the image, construct a $systemstring with "-morphology edgein diamond:", call the system from Perl with $systemstring and Read the result image to work with it in my processing pipeline. After some initial tries this ugly workaround is now working, but I posted a question how to map "-morphology edgein diamond:1" in PerlMagick to avoid this.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Edge() with unacceptable artefacts

Post by fmw42 »

I do not know Perlmagic, but did you try (just a guess)

$image->Morphology(kernel=>'edgein diamond:1', channel=>"all");
gubach
Posts: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Re: Edge() with unacceptable artefacts

Post by gubach »

fmw42 wrote: $image->Morphology(kernel=>'edgein diamond:1', channel=>"all");
no, I got a "Failed to parse kernel number #0" error and image is unchanged.
gubach
Posts: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Re: Edge() with unacceptable artefacts

Post by gubach »

PerlMagick for

Code: Select all

convert img.png -morphology edgein diamond:1 result.png
is

Code: Select all

$img->Morphology(method=>'edgein', kernel=>'diamond', channel=>'all', iterations=>'1'); 
Post Reply