Controling pixelisation amount

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
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Controling pixelisation amount

Post by hellocatfood »

I want to pixelate a number of files of different sizes with a given percentage e.g. 90%. The current recommendation of down/upscaling images does indeed pixelate images, but running -scale 10% -scale 1000% on a folder of images doesn't pixelate them all in the same way i.e. the pixel "tiles" are different sizes.

I've asked for help elsewhere and was given this script

Code: Select all

#!/bin/bash

AMOUNT=$(echo "1.001 - $1" | bc -l)
INFILE=$2
OUFILE=$3

COEFF1=$(echo "100 * $AMOUNT" | bc -l)
COEFF2=$(echo "100 / $AMOUNT" | bc -l)

convert -scale $COEFF1% -scale $COEFF2% $INFILE $OUFILE
(You would save this to pixelate.sh and run ./pixelate 0.9 infile.jpg outfile.jpg (where 0.9 is the percentage amount)

Although this method is effective, it changes the dimensions of images that have a dimension that ends in an odd number. Is there a way to reliably pixelate an image with a specified percentage that will not modify the image dimensions?

Also, will ImageMagick ever gain a simple -pixelate option?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Controling pixelisation amount

Post by fmw42 »

Although this method is effective, it changes the dimensions of images that have a dimension that ends in an odd number. Is there a way to reliably pixelate an image with a specified percentage that will not modify the image dimensions?
What would you have the algorithm do if you could do it "right", if your image was not a multiple of the tile size? How would you handle the extra data that was not a full tile?

With regard to the algorithm that does what you want but truncates, what information would you put into the extra column or row for the ones that are truncated by your process? The easiest thing is just add back the last row or column again to the end of your image. It is simple enough to test your image if even or odd dimension and if odd just replicate the last row or column and append it to your image.
Last edited by fmw42 on 2012-07-19T15:26:15-07:00, edited 1 time in total.
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: Controling pixelisation amount

Post by hellocatfood »

I guess you're right about what to do with the extra data.

I'll take you suggestion of adding the last row/column to the end of the image
Post Reply