Blur part of image in Imagemagick
Asked Answered
C

2

7

What convert command do I use to blur part of an image. For now I am using

convert source.jpg -fill white  -draw "polyline 671,395 665,356 812,331 818,370"  result.jpg

It creates white four points shape on the image, but I need blur all of this part of the image.

Thanks!

Carmel answered 1/11, 2017 at 22:3 Comment(4)
Try using convert source.jpg -region WxH+X+Y -blur 0x3 result.jpg where W is width, H is height, X is x offset from top-left and Y is y offset from top-left.Whew
Mark, thanks but i need custom four points shapeCarmel
Oh sorry, I saw rectangle in your question and didn’t check! It’s late here, so I’ll do it another way tomorrow unless @fmw42 does it first 😄Whew
Anyway thanks Mark, I will update my question so that there are no misunderstandingsCarmel
R
11

In ImageMagick, you can use any mask to limit the blur.

Create a black and white mask image: black inside your quadrilateral and white elsewhere of the size of your image. Then use that as a mask for doing blurring. See http://www.imagemagick.org/Usage/masking/#read_mask.

Input:

enter image description here

(Unix syntax)

convert \
logo.jpg \
\( -clone 0 -fill white -colorize 100 -fill black \
-draw "polygon 332,180 427,105 481,238 399,279" \
-alpha off -write mpr:mask +delete \) \
-mask mpr:mask -blur 0x5 +mask logo_blur.jpg

Blurred Result

enter image description here

Rauch answered 2/11, 2017 at 1:36 Comment(4)
It should be mentioned that you can soften the edges of the finished blurred area by blurring the mask, too. Just add "-blur 0x5" before "-write mpr:mask" to get that result.Shanley
@Rauch one more question. If I want create several blurred shapes on image, how can I do it with one command?Carmel
Just add another polygon and its coordinates inside the -draw. So `-draw "polygon coordinate_set1 polygon coordinate_set2"Rauch
As long as you want the same amount of blur on all the shapes, you can simply add more "-draw" operations in the original command, or even create more shapes within the single "-draw" operation like "-draw "polygon 10,10 50,10 50,50 10,10 polygon 80,80 100,80 100,100 80,80"Shanley
G
4

Use -region http://www.imagemagick.org/Usage/masking/#region_warping

convert a.png -region 150x150+599+261 -implode 1.5 +region b.png
Gerigerianna answered 9/8, 2019 at 12:52 Comment(2)
That method does not allow blurring in any shape other than a rectangle.Rauch
This does not blur, but convert a.png -region 150x150+599+261 -blur 0x100 +region b.png does.Browder

© 2022 - 2024 — McMap. All rights reserved.