Pixelate part of the image

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
jordi
Posts: 7
Joined: 2018-04-19T03:49:17-07:00
Authentication code: 1152

Pixelate part of the image

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

Re: Pixelate part of the image

Post 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
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Pixelate part of the image

Post 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.
Post Reply