[vtkusers] Rotating image data

David Gobbi david.gobbi at gmail.com
Fri Jul 9 12:48:47 EDT 2010


All operations by vtkImageReslice are done on the CPU.  Around 80% of
the code in vtkImageReslice consists of special-case optimizations,
and it is quite efficient for a CPU-based interpolator, but is still
purely CPU and not GPU.

I use a hybrid approach where I use vtkImageReslice for operations
that require a regridding of the image (e.g. extracting oblique
slices) and use either vtkImageReslice or the camera for doing
operations like pan and zoom, according to a complex set of rules that
determine what to do according to the chosen quality/speed tradeoff.

More-or-less, the only thing that matters in terms of getting the
correct visual result is the coordinate transformation between pixels
on your screen and the voxels in your image.  The basic image display
pipeline should consist of vtkImageReslice, vtkImageActor, and then
the Camera/Renderer/RenderWindow.  By understanding the coordinate
transformation that occurs at each stage, you can change which part of
the pipeline does what in order to get the best efficiency.

   David




On Fri, Jul 9, 2010 at 10:28 AM, Lic. José M. Rodriguez Bacallao
<jmrbcu at gmail.com> wrote:
> does all operation performed by vtkImageReslice are costly?
> I don't remember where, but in some book I did read that I should
> never modify the pixel matrix (some vtk book), just the camera but as
> I see, you did modify the camera, is this ok, why?
>
> On Fri, Jul 9, 2010 at 10:31 AM, David Gobbi <david.gobbi at gmail.com> wrote:
>> I'd better add an errata to what I wrote:
>>
>> 3) Each (x,y,z) point is transformed by the ResliceAxes matrix, and
>> then the ResliceTransform, in that order.
>>
>> I had the two operations reversed.
>>
>>   David
>>
>>
>> On Fri, Jul 9, 2010 at 8:21 AM, David Gobbi <david.gobbi at gmail.com> wrote:
>>> Really, vtkImageReslice is the only straightforward way to rotate an
>>> image in VTK.  It does change the pixel matrix, the basic job of
>>> ImageReslice is to resample an image through a transform.
>>>
>>> The operation of vtkImageReslice is like so:
>>> 1) The output Extent/Origin/Spacing of vtkImageReslice define an
>>> output voxel grid.
>>> 2) Reslice loops through all output voxels, and computes the (x,y,z)
>>> data coords for each voxel in turn.
>>> 3) Each (x,y,z) point is transformed by the ResliceTransform, and then
>>> the ResliceAxes matrix, in that order.
>>> 4) The reslice's input data is interpolated at the transformed (x',y',z') point.
>>> 5) The interpolated value from the input at coordinate (x',y',z') is
>>> used to set the value of the output voxel at (x,y,z).
>>>
>>> Lots of people have trouble with (1).  Because vtkImageReslice isn't a
>>> vtkProp it doesn't know anything about how it's output will be
>>> displayed, it doesn't know how to properly set its own output voxel
>>> grid.  So you should usually set the output Spacing/Origin/Extent
>>> manually.  If you don't, then vtkImageReslice will try to "guess" what
>>> a reasonable output grid would be, and it will usually guess wrong,
>>> because it doesn't know anything about how the image will eventually
>>> be displayed.
>>>
>>> I've had a plan for a long time now to write a vtkProp3D based around
>>> vtkImageReslice that will do all the mathematical trickery needed to
>>> make VTK more friendly for 3D image display.  In my own image display
>>> applications, I set up some low-level observers that keep track of the
>>> camera position and the window size, and then have those observers set
>>> the vtkImageReslice parameters so that the image displays exactly the
>>> way that it should.
>>>
>>>   David
>>>
>>>
>>>
>>>
>>> On Fri, Jul 9, 2010 at 7:52 AM, Lic. José M. Rodriguez Bacallao
>>> <jmrbcu at gmail.com> wrote:
>>>> this may be a silly question:
>>>> 1- which is the correct preffered way to rotate(transform) an image,
>>>> with the camera or with vtkImageReslice?
>>>> 2- does vtkImageReslice change/transform the pixel matrix?
>>>>
>>>>
>>>> On Fri, Jul 9, 2010 at 7:34 AM, Jothy <jothybasu at gmail.com> wrote:
>>>>> Some sort of padding befor rotation should help.
>>>>>
>>>>> Jothy
>>>>>
>>>>> On Fri, Jul 9, 2010 at 12:32 PM, Srinivasa Rao <srinivas at rsageventures.com>
>>>>> wrote:
>>>>>>
>>>>>> Hi All,
>>>>>>    I am trying to rotate vtkImageData using vtkTransform and
>>>>>> vtkImageReslice, i used following code to do the job.
>>>>>>
>>>>>> vtkImageData * rotateImage(vtkImageData *data, QPointF center, int angle)
>>>>>> {
>>>>>>         vtkTransform *imageTransform = vtkTransform::New();
>>>>>>         imageTransform->PostMultiply();
>>>>>>         imageTransform->Translate(center.x(), center.y(), 0.0);
>>>>>>         imageTransform->RotateZ(angle);
>>>>>>        imageTransform->Translate(-center.x(), -center.y(), 0.0);
>>>>>>         // Now create filter and set previously created transformation
>>>>>>         vtkImageReslice *algo = vtkImageReslice::New();
>>>>>>         algo->SetInput(data);
>>>>>>         algo->SetInformationInput(data);
>>>>>>         algo->SetResliceTransform(imageTransform);
>>>>>>         algo->SetInterpolationModeToLinear();
>>>>>>         algo->Update();
>>>>>>         return algo->GetOutput();
>>>>>> }
>>>>>>
>>>>>> When i try to rotate image data, after rotation the data which is outside
>>>>>> the image is getting lost.
>>>>>> Is there a way around to rotate image data without data loss..
>>>>>> thanks in advance.
>>>>>> regards,
>>>>>> srinivas.
>>>>>> _______________________________________________
>>>>>> 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
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Lic. José M. Rodriguez Bacallao
>>>> Centro de Biofisica Medica
>>>> -----------------------------------------------------------------
>>>> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.
>>>>
>>>> Recuerda: El arca de Noe fue construida por aficionados, el titanic
>>>> por profesionales
>>>> -----------------------------------------------------------------
>>>> _______________________________________________
>>>> 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
>>>>
>>>
>>
>
>
>
> --
> Lic. José M. Rodriguez Bacallao
> Centro de Biofisica Medica
> -----------------------------------------------------------------
> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.
>
> Recuerda: El arca de Noe fue construida por aficionados, el titanic
> por profesionales
> -----------------------------------------------------------------
>



More information about the vtkusers mailing list