How to reduce noisy pixels around rounded corners?

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
laurens_at_hol
Posts: 20
Joined: 2011-11-16T08:53:16-07:00
Authentication code: 8675308

How to reduce noisy pixels around rounded corners?

Post by laurens_at_hol »

Hi,

I use following commandline options to create rounded corners on an input photo. The rounded image is then placed on a white background.
Problem now is that there is a little bit of noise visible on the outside of the rounded corners. A few colored pixels near the rounded corners are visible on the white background.
Somehow in the composing process the pixels outside the corners are added. How can this be prevented? Can the rounded corners be made without the noisy pixels around them?

Code: Select all

convert rose: -define jpeg:size=827x827 -density 150 +profile 8bim -thumbnail 827x827 -format "roundrectangle 0,0 %[fx:w-1],%[fx:h-1] 20,20" -write info:tmp.mvg \( +clone -alpha transparent -background none -fill '#FFFFFF' -stroke none -strokewidth 0 -draw @tmp.mvg \) -compose DstIn -composite -gravity center -background '#FFFFFF' -compose Over -extent 1063x1063 rounded_rose.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to reduce noisy pixels around rounded corners?

Post by snibgo »

Adjusting your command for Windows 7, IM 6.8.7-0, I get no noisy pixels.

Can you post an output image? Put in somewheree like dropbox.com and paste the URL here.
snibgo's IM pages: im.snibgo.com
laurens_at_hol
Posts: 20
Joined: 2011-11-16T08:53:16-07:00
Authentication code: 8675308

Re: How to reduce noisy pixels around rounded corners?

Post by laurens_at_hol »

Here I zoomed in 500% on a corner of the rose image with rounded corners:
http://screencast.com/t/WD0fCa6JGn
I used some red arrows to point out some of the noise pixels.

I also tested now with png output instead of jpg I was using earlier.
http://screencast.com/t/WxSNTd8jnl
The png looks clean. No visible noise around the corners.

The output filesize is much bigger though and the performance with png is more time and memory consuming.
So I would love to hear some other optimizations!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to reduce noisy pixels around rounded corners?

Post by snibgo »

Okay. With my conversion I can't see any bad pixels there, but using Gimp's eyedropper I can see that some pixels there are not exactly white -- for example they are rgb(249,248,254).

Jpeg is lossy which means it will in general change pixel values. This is most noticeable in areas of constant colour. The effect can be reduced by using a higher "-quality" setting. For example if I put "-quality 100" before the output filename the worst pixel is rgb(255,255,253).

The only way to guarantee that white stays white is by not compressing, or use only lossless compression. Png compression is lossless, and most "-compress" options for tiff are also lossless.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: How to reduce noisy pixels around rounded corners?

Post by glennrp »

snibgo wrote:Okay. With my conversion I can't see any bad pixels there, but using Gimp's eyedropper I can see that some pixels there are not exactly white.
I converted the image using -gamma .02 to make the artifacts visible. The JPEG quality is already pretty high (92) when using IM-6.8.7-5; perhaps the reporter was
using an older version that uses quality 75 by default.
laurens_at_hol
Posts: 20
Joined: 2011-11-16T08:53:16-07:00
Authentication code: 8675308

Re: How to reduce noisy pixels around rounded corners?

Post by laurens_at_hol »

Ok, so I'm using png output now. There are no noise pixels added around the corners, but now I have the problem of aliasing.
The corners are not as smooth as I would like them to have (visible in the screenshot posted earlier).
I tested a bit with -blur but I was not getting smooth (anti-aliased) corners.

Could someone help me modify my convert command so that the corners are smooth, without adding other visible pixels around the corner areas?
Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to reduce noisy pixels around rounded corners?

Post by snibgo »

I think IM's anti-aliasing is accurate. To see it without, use "+antialias". Yeah, using "+" to turn is off seems weird, but that's the way it works.

If you don't like it with or without antialasing, can you create what you want in Gimp or similar? If you show us that, maybe we can do it with IM.
snibgo's IM pages: im.snibgo.com
Post Reply