Page 1 of 1

Documentation of -scale does not match implementation

Posted: 2012-11-30T11:07:45-07:00
by Jason S
As observed in this thread, the documation of convert's -scale option is incorrect or out of date. It says it's equivalent to a box filter, but it evidently uses a pixel averaging algorithm that is only equivalent to a box filter when enlarging or shrinking by an integral factor. I think the documentation should be changed.
(Tested with version 6.8.0-6.)

Re: Documentation of -scale does not match implementation

Posted: 2012-11-30T17:05:59-07:00
by fmw42
Jason S wrote:As observed in this thread, the documation of convert's -scale option is incorrect or out of date. It says it's equivalent to a box filter, but it evidently uses a pixel averaging algorithm that is only equivalent to a box filter when enlarging or shrinking by an integral factor. I think the documentation should be changed.
(Tested with version 6.8.0-6.)
Nice link about "mixing" vs box filter!


In the following tests (IM 6.8.0.7 Q16), it would appear that when magnifying, Jason S. is correct. However, when minifying, -scale and -filter box -resize, seem to be equivalent. Perhaps I have missed a case.

Jason, can you verify or point me to a case similar to my example that fails to show them equivalent for minifying?


Magnifying 100/4 is an integer

convert -size 2x2 xc:black xc:white +append \( +clone -rotate 180 \) -append \
-scale 100x100 1tmp1.gif

convert -size 2x2 xc:black xc:white +append \( +clone -rotate 180 \) -append \
-filter box -resize 100x100 1tmp2.gif

compare -metric rmse 1tmp1.gif 1tmp2.gif null:
0 (0)


Magnifying 75/4 is not an integer

convert -size 2x2 xc:black xc:white +append \( +clone -rotate 180 \) -append \
-scale 75x75 1tmp3.gif

convert -size 2x2 xc:black xc:white +append \( +clone -rotate 180 \) -append \
-filter box -resize 75x75 1tmp4.gif

compare -metric rmse 1tmp3.gif 1tmp4.gif null:
5333.23 (0.0813798)


Minifying 100/10 is an integer

convert -size 50x50 xc:black xc:white +append \( +clone -rotate 180 \) -append \
-scale 10x10 2tmp1.gif

convert -size 50x50 xc:black xc:white +append \( +clone -rotate 180 \) -append \
-filter box -resize 10x10 2tmp2.gif

compare -metric rmse 2tmp1.gif 2tmp2.gif null:
0 (0)


Minifying 100/15 is not an integer

convert -size 50x50 xc:black xc:white +append \( +clone -rotate 180 \) -append \
-scale 15x15 2tmp3.gif

convert -size 50x50 xc:black xc:white +append \( +clone -rotate 180 \) -append \
-filter box -resize 15x15 2tmp4.gif

compare -metric rmse 2tmp3.gif 2tmp4.gif null:
0 (0)

Re: Documentation of -scale does not match implementation

Posted: 2012-11-30T20:11:39-07:00
by Jason S
fmw42 wrote:can you verify or point me to a case similar to my example that fails to show them equivalent for minifying?
Here's an example where they are clearly different.

line100.png:
Image

convert line100.png -scale 73x73 line73scale.png
Image

convert line100.png -filter box -resize 73x73 line73box.png
Image

Re: Documentation of -scale does not match implementation

Posted: 2012-11-30T20:19:48-07:00
by fmw42
OK. Thanks. It is rather subtle, but is different.

Similarly with:

convert -size 100x100 gradient: \
-scale 73x73 4tmp3.gif

convert -size 100x100 gradient: \
-filter box -resize 73x73 4tmp4.gif

compare -metric rmse 4tmp3.gif 4tmp4.gif null:
1102.9 (0.0168292)

Although visually I do not see any difference when flickering between them.



I think we will need to hear back from the IM developers about the algorithmic difference.