Page 1 of 2

How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T14:58:11-07:00
by tigerhawk
Hello,

First time posting on here. Fairly new to the workings of ImageMagick so please go easy on me. Been struggling trying to solve this problem for ages.

Here's the problem...

I have lots of images with transparent white backgrounds that have a few jaggy pointy bits round the edges here and there and I would like to remove these annoying areas altogether by perhaps using geometry to pinpoint each exact location then converting the pixels to transparent white or deleting the pixels altogether.

How would I do this? Any ideas anyone?

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T15:44:03-07:00
by snibgo
Perhaps with a blur on the transparency.

If you want a less vague answer, you'll need to be less vague. Sample input and output images? What version of IM? On what platform?

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T15:53:35-07:00
by fmw42
Perhaps what you want is the new -define for the -trim function. But you must be using ImageMagick 7. See

https://imagemagick.org/script/command- ... s.php#trim
viewtopic.php?f=4&t=35579

Be sure that you have transparency all around the image. If not add -bordercolor none -border 1 to your command

_______________________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T16:08:16-07:00
by tigerhawk
Further to my recent post...

My ImageMagick version is: 7.0.8-14 Q16 (64-bit) (2018-10-24)

Running on Windows 8.1 Pro

Thank you for your time and patience.

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T16:15:22-07:00
by tigerhawk
If it helps any - the bits that I need to alter or remove come in all sorts of colors.

Thanks again for your time and patience.

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T16:28:59-07:00
by tigerhawk
This is a scaled down version but hopefully you'll get the idea.

The pointy bits inside the red circles I need to smooth out somehow.

https://pasteboard.co/I7JmpMO.png

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T17:24:49-07:00
by fmw42
Sorry, that is a different issue all together. Post your original image without the red circles

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T17:37:31-07:00
by tigerhawk

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T19:36:01-07:00
by fmw42
try the following:

Code: Select all

convert image.png -gravity north -splice 0x100 ^
( -clone 0 -blur 0x100 -threshold 50% -negate ) ^
-alpha off -compose copy_opacity -composite ^
-background white -compose over -flatten ^
-gravity north -chop 0x100 ^
result.png
If in a .bat file, then % need to be doubled to %%.

The image you uploaded has no transparency or it was lost when you uploaded.

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T20:45:55-07:00
by tigerhawk
That worked a treat but unfortunately I am unable to get it to work properly for the full image as that was just a section I uploaded.

Can you be so kind to do the exact same thing you did but this time for the full image.

The complete image is a head and I need to make the bit above the ears nice and rounded.

Here's the link to the file: https://pasteboard.co/I7L0ZXl.png

Thank you for your time and patience.

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-29T22:11:26-07:00
by fmw42
Try this. I extract the alpha channel. Then process it that same way. Then I make a mask that is white above the ears and black below. Then I use the mask to composite the alpha channel and the processed alpha channel together into one image. Then I use that to replace the alpha channel in the original image.

Code: Select all

convert image.png ^
( -clone 0 -alpha extract ) ^
( -clone 1 -blur 0x100 -threshold 61% ) ^
( -clone 1 -fill black -colorize 100 ( -size 2872x1524 xc:white ) -compose over -composite ) ^
( -clone 1-3 -compose over -composite -threshold 50% ) ^
-delete 1-3 ^
-alpha off -compose copy_opacity -composite ^
result.png

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-30T02:37:41-07:00
by tigerhawk
It's getting there.

But the part just above the ear on both sides 230px high and 30px wide needs to be addressed somehow.

Can the 30px that's been chopped off be returned or alternatively perhaps the 30px can removed right down to the ear.

Plus there's also the 50px vertical line at coordinates 2870, 1362px

Thanks again for your time and patience.

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-30T09:36:29-07:00
by fmw42
Sorry, that is the best I can do. You probably need to vectorize the image and then process the vectorized image to smooth it. Then re-rasterize it. So potrace, for example, for vectorizing.

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-30T10:16:32-07:00
by tigerhawk
I'm so sad that I cannot fix this properly. Is there not a way to zap the unwanted pixels and make them disappear?

Re: How do I smooth out or delete pointy bits on the edge of an image

Posted: 2019-03-30T14:07:25-07:00
by fmw42
You would have to manually draw a mask image that was smooth at the top of the head. Then composite the mask with the image to trim away those pixels.

I suggest that you use and interactive tools such as GIMP or Photoshop to paint it smooth.