Page 1 of 1

Edge() with unacceptable artefacts

Posted: 2014-02-22T12:12:02-07:00
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/

Re: Edge() with unacceptable artefacts

Posted: 2014-02-22T13:26:49-07:00
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

Re: Edge() with unacceptable artefacts

Posted: 2014-02-22T13:51:39-07:00
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.

Re: Edge() with unacceptable artefacts

Posted: 2014-02-23T05:17:13-07:00
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.

Re: Edge() with unacceptable artefacts

Posted: 2014-02-23T12:14:49-07:00
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.

Re: Edge() with unacceptable artefacts

Posted: 2014-02-24T11:08:29-07:00
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.

Re: Edge() with unacceptable artefacts

Posted: 2014-02-24T13:17:17-07:00
by fmw42
I do not know Perlmagic, but did you try (just a guess)

$image->Morphology(kernel=>'edgein diamond:1', channel=>"all");

Re: Edge() with unacceptable artefacts

Posted: 2014-02-25T07:52:46-07:00
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.

Re: Edge() with unacceptable artefacts

Posted: 2015-03-24T15:37:58-07:00
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');