comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » POLY_2D proken. Film at 11.
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
POLY_2D proken. Film at 11. [message #12626] Fri, 21 August 1998 00:00 Go to previous message
Craig DeForest is currently offline  Craig DeForest
Messages: 2
Registered: October 1996
Junior Member
I found a rather interesting bug in poly_2d, the IDL built-in to
do scaling of image data. The bilinear and spline interpolation
features are designed inconsistently with the sampling feature. The
bug is both in 4.x and 5.x versions of IDL.

Sampling works correctly: when scaling an original image by an integer
factor, each pixel is scaled an integer number of times. But bilinear
and cubic interpolation do not work the same way -- there is a
1/2-pixel offset in the output compared to linear sampling.
Apparently, the interpolation algorithms wrongly regard each (old)
pixel's value as resident at the *corner* of the (old) pixel, and not
at the *center* of the (old) pixel.

Here's some example code:
------------------------------------------------------------ ----------
pro break_poly_2d

; Generate a symmetrical image of a crosshairs
a = bytarr(9,9)
a(4,*) = 255
a(*,4) = 255
window,0,xsiz=9,ysiz=9
tv,a

; Scale it up by a factor of 10 using the sampling algorithm
; The output looks nice so far...
b = poly_2d(a,[0,0.1,0,0],[0,0,0.1,0],0,90,90)
window,1,xsiz=90,ysiz=90
tv,b

; Scale it up by a factor of 10 using the bilinear interpolation
; algorithm. Shudder at the lack of consistency.
c = poly_2d(a,[0,0.1,0,0],[0,0,0.1,0],1,90,90)
window,2,xsiz=90,ysiz=90
tv,c

; Scale it up by a factor of 10 using the bilinear interpolation
; algorithm, but offset to account for the pixel-corner bug.
; Recoil in horror at the sloppy treatment of the boundary condition.
d = poly_2d(a,[-0.5,0.1,0,0],[-0.5,0,0.1,0],1,90,90)
window,3,xsiz=90,ysiz=90
tv,d

; Scale it up by a factor of 10 using the cubic spline.
; Laugh that at least it's broken consistently with the
; bilinear case.
e = poly_2d(a,[-0.5,0.1,0,0],[-0.5,0,0.1,0],2,90,90)
window,4,xsiz=90,ysiz=90
tv,d

end
------------------------------------------------------------ ----------

The best one can do is to say something inane like:

P1=P
P1(0) = P1(0)-0.5*keyword_set(method)
Q1=Q
Q1(0) = Q1(0)-0.5(keyword_set(method)
out = poly_2d(in,P1,Q1,method,xsize,ysize)

instead of

out = poly_2d(in,P,Q,method,xsize,ysize)

but even then you get wacky results near the lower and left hand
boundaries of <out>.



--
I work for Stanford, *NOT* the government. My opinions are my own.

If you're a robot, please reply to the address in the header.
If you're human, try " zowie (at) urania . nascom . nasa . gov "
[Message index]
 
Read Message
Read Message
Previous Topic: Re: dlm creating an array?
Next Topic: Rotate an image using objects

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 20:40:12 PDT 2025

Total time taken to generate the page: 1.19864 seconds