Documentation of -scale does not match implementation

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Locked
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Documentation of -scale does not match implementation

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

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Documentation of -scale does not match implementation

Post 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)

Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: Documentation of -scale does not match implementation

Post 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

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Documentation of -scale does not match implementation

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

Locked