How to smooth image after blurring?

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?".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Contact:

Re: How to smooth image after blurring?

Post by snibgo »

With Q16 IM, without "+depth", stair-stepping between areas is inevitable, as the output is 8 bits/channel/pixel and there are only 38 different tones.

With Q16 or better, with "+depth", we have more than 9000 tones, and I can't see any problem. Perhaps I don't understand the issue.

Using "-gaussian-blur" instead of "-blur" makes a slight difference, further reducing the number of adjacent pixels that are equal, and spreading them more evenly throughout the image.

Test script (Windows BAT syntax):

Code: Select all

%IM%convert ^
  before_blur.jpg -blur 0x50 ^
  +depth ^
  sm_blur2.png

%IM%convert ^
  sm_blur2.png ^
  -unique-colors info:

%IM%convert ^
  sm_blur2.png ^
  ( +clone ) ^
  -geometry +1+0 ^
  -compose Difference -composite ^
  -fill White +opaque Black ^
  -format %%[fx:mean] +write info: ^
  x0.png

%IM%convert ^
  sm_blur2.png ^
  ( +clone ) ^
  -geometry +0+1 ^
  -compose Difference -composite ^
  -fill White +opaque Black ^
  -format %%[fx:mean] +write info: ^
  x1.png
snibgo's IM pages: im.snibgo.com
rui_liu
Posts: 7
Joined: 2015-08-27T11:28:35-07:00
Authentication code: 1151
Contact:

Re: How to smooth image after blurring?

Post by rui_liu »

Thank you very much guys, probably I need to redesign my app to see which of the method fits my need.

Currently, I think probably using a light blur looks best (0x10), but since it will keep the original image recognised, I need to find a way to use it as background, since the background is not square, and I don't want to stretch the image.

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

Re: How to smooth image after blurring?

Post by fmw42 »

rui_liu wrote: I need to find a way to use it as background, since the background is not square, and I don't want to stretch the image.
I do not understand why this is a problem? Blurring the image does not change its size. Can you explain further.

If your image is not the right size, use -resize (with the ^ option) to change the size such that on dimension fits perfectly and the other is slightly too large. Then crop to fit your overlay image.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 6 guests