Figure 1: Distorted image (sample iagbe_10 I. Gurke)
as measured by the Photonics CCD detector at ESRF.
Consider that you have measured a scattering pattern as shown in Fig. 1. Such a pattern surely cannot be used for a quantitative analysis, since the Photonics CCD detector distorts the image considerably. The image distortion can be quantified after placing a screen with regular holes in front of the detector and measuring the detector response.
Figure 2: ''Warped matrix image'' (spat3_0.sdt): Image distortion
from the detector is documented by recording the response of a punched
screen placed in front of the detector.
The corresponding image is shown in Fig. 2. Both images are originally in ``sdt format'' and have been read using sdtread.pro. Images are visualized using sf_show.pro, and the EPS files used for this presentation have been generated by use of eps_show.pro.
wave>a=sdtread('iagbe_10')
wave>loadct,5
wave>sf_show,a,3
wave>eps_show,a,'WarpedPatt'
wave>p=sdtread('spat3_0')
wave>sf_show,p,0
wave>eps_show,p,'WarpedScreen'
wave>sf_xdwrite,a,'iagbe_10'
Figure 3: Mask generated from the warp matrix image
After masking the warped matrix image at an intensity level of 4500
wave>m = p
wave>m.map = p.map GT 4500
wave>sf_show,m,3
we obtain a somewhat grainy mask m (cf. Fig. 3). ``grainy mask'' means a morphological feature.
Figure 4: After making a ``warped matrix mask'' from the ``warped
matrix image''.
Application of the morphological opening (sf_opening,m) removes the grains. We obtain the clear mask shown in Fig. 4. Since even this mask is imperfect, it would be difficult to automize the next step. So we use an interactive routine (sf_prewarp.pro) to generate a warp point list. During this process the user has to supply the indices of the warp matrix points and their warped positions in the mask by ``clicking a mouse button''.
wave>warp=sf_prewarp(m)
wave>sf_warpwrite,warp,'spat3_0'
Figure 5: During the prewarping process. Each mouse button
click is echoed in the image.
As can be seen in Fig. 5, the procedure works from bottom to top and from left to right, as in a normal coordinate system. Each click of the left mouse button adds an element to the warp list. Clicking the right button advances to the line above. Clicking both left and right button returns to a mini command interpreter allowing some fine control. At the end of the process, the warp mask may look like the one shown in Fig. 6, when all of the detectible warp points have been considered.
Figure 6: After the prewarping process
The output of sf_prewarp is a special ``warp structure'', which can be written to a file using the procedure sf_warpwrite. Such a file can be read using the function sf_warpread. Warp structures contain the information necessary to ``unwarp'' images using the pv-wave library functions POLYWARP and POLY-2D. The whole unwarping procedure has been coded in a single function sf_unwarp. Let the scattering pattern which shall be unwarped be represented by a structure named ``a'' and the warp list be represented by a structure ``warp'', then the unwarping is simply done by a call
u=sf_unwarp(a,warp,50,50,850,600,/ShiftMat)
and u is the unwarped ``iagbe_10'' as shown in Fig. 7.
Figure 7: In the unwarped image the geometrical distortion
from the detector is removed.
One can easily check the validity of the unwarping process by applying it to the warp matrix itself and visualizing the result, as is shown in the next figure.
wave>pu=sf_unwarp(p,warp,50,50,850,600,/ShiftMat)
wave>sf_show,pu
Figure 8: The corrected warp screen matrix shows the perfect
quadratic grid imprinted in the metal screen.
The resolution of the corrected image is determined by the distance of the holes in the calibration screen and the values of the 3rd and 4th parameters in the call of sf_unwarp (in the example the resolution is 50 pixels per unit hole distance in x-direction and 50 pixels in unit hole distance in y-direction).
The size of the corrected image is supplied in the 5th and 6th parameter. Thus one may extend the image "to the right and to the top" by simply enlarging the image.
The position of the corrected image is defined by the warp list itself. The element with the true coordinates (0,0) will be in the lower left corner of the unwarped picture. But by supplying the keyword "/ShiftMat" sf_unwarp will shift the matrix a little bit, so that even some area "to the left and to the bottom" of the warp cushion displayed in the distorted image of the calibration screen will be visible in the corrected image.