[SOLVED]How avoid smudged edges produced from B&W silhouette

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
yougo
Posts: 7
Joined: 2013-03-07T04:42:24-07:00
Authentication code: 6789

[SOLVED]How avoid smudged edges produced from B&W silhouette

Post by yougo »

Hi,

I am using IM version 6.6.9-7 in Ubuntu Linux.
I have an image that I pre-processed using the following command:

Code: Select all

convert $image_file -colorspace Gray $gray_image

Code: Select all

convert $gray_image -threshold 80% $bw_image

Code: Select all

convert $bw_image -morphology Smooth Octagon:3  $clean_bw_image
I now want to take the resulting B&W silhouette and generate the edge.
I have tried the following commands:

Code: Select all

convert $bw_image -edge 2 -negate $edge_bw_image
convert $clean_bw_image -negate -edge 2 -negate $edge_bw_image
convert $clean_bw_image -edge 1 -negate $edge_bw_image
convert $clean_bw_image -negate -morphology EdgeIn Diamond -negate $edge_bw_image
convert $clean_bw_image -negate -morphology Edge Diamond -negate $edge_bw_image
As far as I can see, the B&W silhouette prior to edge detection, has a clean border with
no speckles or smudges. However, after edge detection the edges is smeared with
pixels. Is there any way I can generate "clean" edges? The examples in the IM site
don't seem to have this problem.

The following link show the files in question:
Original image:https://www.dropbox.com/s/o2wtirbc4ym3i25/original.jpg
Image after pre-processing:https://www.dropbox.com/s/vgafcn8noa1yl8n/clean_bw.jpg
The (smudgy) result:https://www.dropbox.com/s/w1wdvod9jh4wuv0/edge_bw.jpg

TIA,
Hugo
Last edited by yougo on 2013-03-08T04:18:47-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to avoid smudged edges produced from B&W silhouette

Post by fmw42 »

I suspect your version of IM is buggy and certainly very old (140 versions old). The following works fine for me under IM 6.8.3.7 Q16 Mac OSX Snow Leopard.


convert original.jpg -set colorspace RGB -colorspace gray -threshold 80% -morphology smooth octagon:3 -negate -morphology edgeout diamond:1 result.jpg


I suggest you upgrade your version of IM
yougo
Posts: 7
Joined: 2013-03-07T04:42:24-07:00
Authentication code: 6789

Re: How to avoid smudged edges produced from B&W silhouette

Post by yougo »

I have gone through the hoops and made a "local" installation of the latest version of IM.
The results don't show those artifacts anymore. That seemed to solve the issue.

BTW, why do we need the " -set colorspace RGB"?
I made several tests and their seem to be no differences in the output.

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

Re: [SOLVED]How avoid smudged edges produced from B&W silhou

Post by fmw42 »

BTW, why do we need the " -set colorspace RGB"?
Perhaps that is not needed when you use -threshold. But for versions of IM after IM 6.8.0.3 grayscale images are treated as linear and will display darker than they did before that version. To make them look the same as before (non-linear grayscale) on has to tell IM that the image is not nonlinear sRGB color before converting to grayscale or it will apply a gamma transformation to make it darker.

See
viewtopic.php?f=4&t=21269

Also
viewtopic.php?f=3&t=22758
yougo
Posts: 7
Joined: 2013-03-07T04:42:24-07:00
Authentication code: 6789

Re: [SOLVED]How avoid smudged edges produced from B&W silhou

Post by yougo »

Thank you.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [SOLVED]How avoid smudged edges produced from B&W silhou

Post by anthony »

the smugs look more like JPEG errors you get from trying to save binary images using a JPEG image encoding.

JPEG does not handle sharp edges very well due to its lossy compression algorithm.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
yougo
Posts: 7
Joined: 2013-03-07T04:42:24-07:00
Authentication code: 6789

Re: [SOLVED]How avoid smudged edges produced from B&W silhou

Post by yougo »

Anthony,

Ok, I will test test this with the png formats although results from the latest IM were not too bad.

Thanks,
Post Reply