[vtkusers] Resampling an image to compare with other one

Ricardo A Corredor J ra.corredor at gmail.com
Sun Sep 27 00:24:53 EDT 2009


Hi David and Paul

Thanks for your answer ;) I really appreciate it ... I think i will work
changing the factors with Paul's suggestions...

I'll try it !!


-------
RaC



On Sat, Sep 26, 2009 at 11:13 PM, Paul Arner <paularner at msn.com> wrote:

>
>
> From: "Paul Arner" <paularner at msn.com>
> Sent: Saturday, September 26, 2009 9:56 PM
> To: "David Gobbi" <david.gobbi at gmail.com>
> Subject: Re: [vtkusers] Resampling an image to compare with other one
>
>  Hi RaC-
>>
>> If I understand this correctly,  you wanted to take image B (W = 120, H =
>> 80) to image A: (W = 80, H = 120),
>>
>> so the x-(width) scale should be (119/79) and the y-(height) scale should
>> be (79/119), as David argues below.
>>
>> From the description, you were using (120/80) = 3/2 and (80/120) = 2/3.
>>
>> (B max column value is 119), so    119 * 2/3 = 79.333 ~ 79, so the width
>> is correct, but
>>
>> (B max row value is 79), so 79 * 3/2 = 118.5 ~ 118, not 119 so the height
>> is not correct, as you observed.
>>
>>
>>
>> Paul
>>
>> --------------------------------------------------
>> From: "David Gobbi" <david.gobbi at gmail.com>
>> Sent: Saturday, September 26, 2009 8:57 PM
>> To: <ra.corredor at gmail.com>
>> Cc: <vtkusers at vtk.org>
>> Subject: Re: [vtkusers] Resampling an image to compare with other one
>>
>>
>>  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
>>>>
>>>>
>>>>  _______________________________________________
>>> 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
>>>
>>>  _______________________________________________
> 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
>



-- 
----
RaC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090926/9a0f35c2/attachment.htm>


More information about the vtkusers mailing list