Page 1 of 1

Pixelate part of the image

Posted: 2018-05-03T04:12:31-07:00
by jordi
Hi,

I would like to know if it's possible to pixelate just a part of an image using a mask.

I know I could first create a downscaled image of the original, then just upscale and merge the original and the processed using a mask, but the question is, just as with blur effect, can I pixelate out of the box using imagemagick ?

Code: Select all

convert -scale 5% -scale 2000% original.jpg pixelated.jpg
convert original.jpg pixelated.jpg mask.jpg -composite pixelated.jpg

Code: Select all

convert original.jpg : -mask \( mask_or.jpg -alpha off -negate \)
            -blur 0x8   +mask  blur.jpg
can I do it like this ?

Also that would allow me to make the pixelation using a polygon instead of a mask

Image




Version: ImageMagick 7.0.7-14 Q16 x86_64
cli
OS : mac

Thanks in advance

Re: Pixelate part of the image

Posted: 2018-05-03T04:33:14-07:00
by snibgo
If you had linked to individual inputs, we could use those as examples.

"-scale 10% -scale 1000%" is a pixellating method.

For any effect that we want masked, we can apply the effect to the entire image, then composite that over the original with the mask, like this (Windows BAT syntax):

Code: Select all

magick ^
  in.png ^
  ( +clone -scale 10%% -scale 1000%% ) ^
  mask.png ^
  -compose Over -composite ^
  out.png

Re: Pixelate part of the image

Posted: 2018-05-03T09:12:38-07:00
by fmw42
If the part that you want to pixelate is a rectangle/square, you can use -region to do the -scale 10% -scale 1000% operation. See https://www.imagemagick.org/Usage/masking/#regions

Code: Select all

magick in.png -region WxH+X+Y -scale 10% -scale 1000% +region out.png
This works in IM 6 but for some reason, not in IM 7. I have reported a bug.