> >I was expecting something like "0 0 0 1 1 1 1 2 2 2",
> >and the result was "0 0 0 0 0 1 1 1 2 2" !
> >
> >The result is not symmetrical !
> >
> >Can You give me some explanation ?
>
> This looks to me like a classic error of open/closed intervals:
>
> Pictorially, you felt you started with:
>
> +-----+-----+
> | | |
> | 0 | 2 |
> | | |
> +-----+-----+
>
> That is, you thought of your images as two rectangles (each only one pixel
> on a side), entirely covered with a single value (0 or 2).
>
> Streching this, you expected:
>
> +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
> | | | | | | | | | | |
> | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 2 | 2 | 2 |
> | | | | | | | | | | |
> +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
>
> However, I suspect that the code treated the source as:
>
> +-----+-
> | |
> |0 |2
> | |
> +-----+-
>
> That is, as values on a half open interval, where 0 was at the left edge,
> and the right edge, just beyond the one pixel enclosed, was 2.
No, AffineTransformOp does treat the source as:
+-----+-----+
| | |
| 0 | 2 |
| | |
+-----+-----+
And the pixel centers, which are considered to be at the coordinates 0.5,
1.5, 2.5, ..., etc., are used for coordinate mapping and interpolation.
Moreover, in case of bilinear interpolation, the source image is extended
by copying its border pixels as needed.
The problem came from the native code underlying AffineTransformOp which
was developed for performance and with somewhat sacrifice on precision.
For scaling 5x in X direction with bilinear interpolation,
Input pixels 0 2
Theoretical output 0.00 0.00 0.00 0.40 0.80 1.20 1.60 2.00 2.00 2.00
Current output 0 0 0 0 0 1 1 1 2 2
But if you use 200 instead of 2 for the second pixel value, then
Input pixels 0 200
Theoretical output 0.00 0.00 0.00 40.0 80.0 120. 160. 200. 200. 200.
Current output 0 0 0 39 79 119 159 199 200 200
You can see +-1 errors apart from the theoretical values in some cases
with the current implementation. We are trying to improve this code, and
might eventually split it into two implementations for QUALITY and SPEED,
respectively.
Hope this helps,
-James Cheng
mediaLib Engineer
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".