Page 2 of 2

Re: [SOLVED] downsize w/ Point staying aligned w/ nearest t

Posted: 2012-05-23T20:32:31-07:00
by anthony
NicolasRobidoux wrote:Here is a really compact solution:

Code: Select all

magick INPUT.IMG -filter Box -define filter:blur=0 -distort Resize WIDTHxHEIGHT OUTPUT.IMG
It will only do what I want when WIDTH divides the width of the input image exactly, and likewise with the HEIGHT, but this is the situation that I care about.
Of course it relies on ImageMagick enlarging the blur just enough to make sure that there is at least one point in the "Box" (which here is a disk).
Well that isn't 'point' (unless I get a different image to you) looks more like a triangle filter (bilinear interpolation)
But then that is what you are getting... blur =0, means support = 0, so no pixels ever get 'hit' and you get a fall back to interpolation type 'point' lookup.

Really Resize with filter point probably should use the new IMv7 operator -interpolative-resize (resize using interpolation only)
But historically filter point (actually a near zero support impulse filter) produces a nearest neighbour interpolation.

ASIDE: I do want to add some other 'unusual' interpolations.

For example a mixed nearest-neighbour and average interpolator. That is if the sample point is 'close' to a pixel, use that, other-wise use average of the nearest pixels.

Another idea is, exact matches uses pixels, otherwise use background color. This can be used to integer 'scale' an image such that the result is much like splicing extra rows and columns of pixels to spread the original pixel. This also would be useful for the unusual EWA Box filter with two small a support.
http://www.imagemagick.org/Usage/resize ... terpolated
uses this interpolation filter in this situation would result in the areas between 'dots' bein the user given background color, rather than the interpolated blended color.

Re: [SOLVED] downsize w/ Point staying aligned w/ nearest t

Posted: 2012-05-24T05:13:41-07:00
by NicolasRobidoux
In my limited testing,

Code: Select all

magick INPUT.IMG -filter triangle -interpolative-resize WIDTHxHEIGHT OUTPUT.IMG
and

Code: Select all

magick INPUT.IMG -filter Box -define filter:blur=0 -distort Resize WIDTHxHEIGHT OUTPUT.IMG
give exactly the same results when "exact integer ratio" downsampling. And the former does not require abusing IM internals.

Thank you Anthony!

Re: [SOLVED] downsize w/ Point staying aligned w/ nearest t

Posted: 2012-05-24T05:16:10-07:00
by NicolasRobidoux
anthony wrote:...
For example a mixed nearest-neighbour and average interpolator. That is if the sample point is 'close' to a pixel, use that, other-wise use average of the nearest pixels.
...
"Nearest neighbour with ties resolved by averaging" (which, again, is not what you want if you are using nearest neighbour to resize etc without adding new colours) can be described this way.

Re: [SOLVED] nearest neighbour downsize w/ averaged ties

Posted: 2012-05-24T17:37:52-07:00
by anthony
Not exactly ties. more like "Nearest Neighbour, but with averaged 'near-ties'.

That is, using a 'tensor' method, if within 0.25 of the real pixel, use that pixels value, otherwise use average of the two pixels. One pass in X one in Y. So you get spots of real color, surrounded by 50% blended averages.

The other variation would replace the average areas with 'background' color.