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.)
Documentation of -scale does not match implementation
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Documentation of -scale does not match implementation
Nice link about "mixing" vs box filter!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.)
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
Here's an example where they are clearly different.fmw42 wrote:can you verify or point me to a case similar to my example that fails to show them equivalent for minifying?
line100.png:
convert line100.png -scale 73x73 line73scale.png
convert line100.png -filter box -resize 73x73 line73box.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Documentation of -scale does not match implementation
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.
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.