[vtkusers] Resampling an image to compare with other one

David Gobbi david.gobbi at gmail.com
Sat Sep 26 22:57:15 EDT 2009


Hi RaC,

This has to do with the peculiar mathematics of image resizing.  To
simplify things, I'll only discuss the image widths, since the height
is treated in exactly the same way.

Image A has a columns in the range [0,79], and image B has columns
[0,119].  In order to stretch image A to the size of image B, you need
to set a magnification factor that will stretch the rightmost column
of A out to the rightmost column of B.  The correct factor to apply is
119/79 which is 1.506329.  If you feel doubtful about this, then just
try it.  Note that the leftmost column stays in the same place, as it
should, because 0*(119/79) = 0.

So if you apply a magnification factor of 2, then [0,79]*2 = [0,158]
which is why vtkImageResample will give you and image that is 159
pixels across.

To make a long story short: when you are resizing images or doing any
other sort of geometrical changes to them, you have to measure the
width of the image as the distance between the leftmost pixel and the
rightmost pixel, which is equal to the number of pixels subtract one.

Basically, VTK does not include the "borders" of the images in its
data coordinate system.  In this way it is different from other
coordinate systems that do include the image border, like texture
coordinates.  The way that VTK does coordinates is the same as medical
images, e.g. like CT or MRI, while the other way is commonly used in
computer graphics and digital photography.

  David


On Sat, Sep 26, 2009 at 4:27 PM,  <ra.corredor at gmail.com> wrote:
> Hi
>
> I have two images of different sizes. Image A:80x120 Image B:120x80. I must
> compare both in the same size, so I have to resample or resize one of the
> images with the size values of the other one. When I use the
> vtkImageResample with B, the width changes to 80, but the height to 119 !!
> ... And when I use different factor values in the method
> SetAxisMagnificationFactor, I note these results:
> Factor Obtained Expected Height Value
> 0,5 40 40
> 1 80 80
> 1,5 119 120
> 2 159 160
> 2,01 159 161
> 2,1 166 168
> 2,7 214 216
> 3 238 240
> 3,5 277 280
> 4 317 320
> 4,1 324 328
> So, when the factor increases, the number of pixels obtained with the
> SetAxisMagnificationFactor is less than the expected value.
>
> Do you know how can I resize the B image keeping the extent of the A image
> and not losing some rows or columns in the process??
>
>
> Thanks!!
>
> RaC
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list