Page 1 of 1

Inverse blur/sharpen kernel

Posted: 2016-06-18T03:59:01-07:00
by VanGog
Is it possible to create kernel which will blur the parts of image which are sharp and also will sharpen the areas which are blur?

For instance in this image I have marked regions with text which should be sharpen more (red frame) and areas which should be sharpen less (orange regions). The bottom right should be blurred.

Image

Re: Inverse blur/sharpen kernel

Posted: 2016-06-18T04:35:50-07:00
by snibgo
Use "-compose Blur" with a mask that is white where you want to blur, and black where you don't want to blur (and gray in the middle).

For selective sharpening, do a selective blur but then extrapolate from the blur, past the input image.

Re: Inverse blur/sharpen kernel

Posted: 2019-03-09T16:49:02-07:00
by Vilius
Hi,
I was looking for the solution of almost the same problem. I need to selectively sharpen some pictures (in batch modus) -- like here http://digiretus.com/selective-sharpening-in-photoshop/ in Photoshop. The top of the photograph should be sharpened and towards the bottom the factor should gradually decrease. I am able to prepare N-S gradient mask however I don't understand what snibgo means with extrapolate from the blur, past the input image.
Could someone provide a small example?

Re: Inverse blur/sharpen kernel

Posted: 2019-03-09T17:25:53-07:00
by fmw42
See https://imagemagick.org/Usage/mapping/#blur for the basic variable blur. I am not sure what snibgo meant either, but I do not think it applies to your case. The basic variable blur should do what you want. For sharpening, I think you can create the blurred version and then subtract some fraction of it from the original (sort of unsharp masking)

Alternately and more efficiently, make a sharpened copy of your image and use the gradient as a mask to blend to the two images. See https://imagemagick.org/Usage/compose/#compose for the masked composite operation.

See also https://imagemagick.org/Usage/photos/#tilt_shift

Re: Inverse blur/sharpen kernel

Posted: 2019-03-09T20:22:23-07:00
by snibgo
snibgo wrote:... extrapolate from the blur, past the input image.
This is unsharp masking, but in this case with a selective (ie variable) blur, so the sharpening is also selective.

When we have an image and a blurred version of that image, the result could be an interpolation between those two versions, anywhere between the blur and the original. Or it could be an extrapolation, past the original, which increases sharpness.

See Selective blur "Toytown effect".

Re: Inverse blur/sharpen kernel

Posted: 2019-03-10T04:19:53-07:00
by Vilius
Many thanks for your answers.

Do you mean something like:

w=$(convert image -format "%w" info:); h=$(convert image -format "%h" info:); convert -composite image \( +clone image -unsharp 0x3+1+0 \) \( +clone -size 1x$h gradient: -fx "atan(u*Pi)/atan(Pi)-.1" -negate -scale "$wx$h !" \) result.jpg

?
I will start to experiment with the parameters.

Re: Inverse blur/sharpen kernel

Posted: 2019-03-10T08:35:38-07:00
by snibgo
Something like that, yes.

In the bad old days, IM commands could list the operations in any order you want, and IM would process the operations one after the other in whatever order it wanted.

These days, IM will process the operations in the same order they are given. So "-composite" before any images have been read won't do anything, because there are no images to composite.