[ITK-users] [vtkusers] Undo vtkImageFlip effects

Marcos fotosentido at gmail.com
Mon Sep 14 15:53:18 EDT 2015


I got it. I was checking vtkImageChangeInformation but it's not necessary.


I would explain it, hoping it will be useful for others. I had to look in
several pages.

flipperX->SetResliceAxesDirectionCosines(1,0,0, 0,change,0, 0,0,1);


where change is a -1 or a 1, switching the flip effect.



But this flips is around the origin, which is not the center of the image.
How to calculate the center:

        double origin[3];

        imageData->GetOrigin(origin);


        double spacing[3];

        imageData->GetSpacing(spacing);


        int dim[3];

        imageData->GetDimensions(dim);


        double center[3];

        for(int i = 0; i < 3; i++)

        {

            center[i] = origin[i] + ((dim[i] - 1 ) * spacing[i]) / 2;

        }


Now that we have the center, we set it as the origin:

imageData->SetOrigin(center);



And we connect the imageData to our filter in the pipeline.

flipperX = vtkSmartPointer<vtkImageReslice>::New();

flipperX->SetInputData(imageData);

flipperX->Update();


After that, every time we want a flip, we just have invoke the first
command of this post with the desired change value. And update().


For many people these things are not so obvious, it would be great to
have more examples about applying filters like this. Flipping images
is a common thing.


Thank you for your help, David.



2015-09-14 20:55 GMT+02:00 Marcos <fotosentido at gmail.com>:

> I set the fourth component of the fourth column to 1:
>
>
> matriz->SetElement(3,3,1);
>
>
> ant the rotation is the same as with 3x3. Even with multiframe images, all frames are upside down (good) but not centered.
>
>
> The problem is locating the center of the image, even with multiframe.
>
>
> Any ideas? Thanks.
>
>
> 2015-09-14 20:36 GMT+02:00 Marcos <fotosentido at gmail.com>:
>
>> Well, I tried with an 3x3 matrix, and, as you said it flipped around the
>> origin I guess.
>>
>> So I guess I have to locate the center or use 4x4 matrix.
>>
>> I was trying to use 4x4 matrix, creating a vtkMatrix4x4, but I don't know
>> what values to insert.
>> I checked the ImageSlicing example but not sure what I have to do.
>>
>> Reviewing related topics I found an answer of yours:
>>
>> "The first three columns are the the direction cosine vectors (for
>> these, the 4th component should be zero).  The three direction cosine
>> vectors should be perpendicular to each other.
>>
>> The fourth column (whose 4th component must be 1.0) gives a translation,
>> defined with respect to the coordinate system of the input of
>> vtkImageReslice."
>>
>>
>> So I tried this code:
>>
>> //flipperX->SetResliceAxesDirectionCosines(1,0,0, 0,-1,0, 0,0,1);
>>
>>     vtkSmartPointer<vtkMatrix4x4> matriz = vtkSmartPointer<vtkMatrix4x4>::New();
>>
>>     matriz->SetElement(0,0,1);
>>
>>     matriz->SetElement(0,1,0);
>>
>>     matriz->SetElement(0,2,0);
>>
>>     matriz->SetElement(0,3,0);
>>
>>
>>     matriz->SetElement(1,0,0);
>>
>>     matriz->SetElement(1,1,-1);
>>
>>     matriz->SetElement(1,2,0);
>>
>>     matriz->SetElement(1,3,0);
>>
>>
>>     matriz->SetElement(2,0,0);
>>
>>     matriz->SetElement(2,1,0);
>>
>>     matriz->SetElement(2,2,1);
>>
>>     matriz->SetElement(2,3,0);
>>
>>
>>     matriz->SetElement(3,0,0);
>>
>>     matriz->SetElement(3,1,0);
>>
>>     matriz->SetElement(3,2,0);
>>
>>     matriz->SetElement(3,3,0);
>>
>>     flipperX->SetResliceAxes(matriz);
>>
>>     flipperX->Update();
>>
>>
>> The image disappeared :(
>>
>>
>> Not sure if I'm doing well.
>>
>>
>>
>>
>> 2015-09-14 19:19 GMT+02:00 David Gobbi <david.gobbi at gmail.com>:
>>
>>> Hi Marcos,
>>>
>>> It might be more convenient to use vtkImageReslice to flip the images.
>>> It can take a 3x3 or 4x4 matrix that describes the transformation.
>>>
>>> For a 3x3 matrix that flips the Y axis, you would use this:
>>>
>>> reslice->SetResliceAxesDirectionCosines(
>>>   1, 0, 0,
>>>   0, -1, 0,
>>>   0, 0, 1);
>>>
>>> Be careful, though, because this flips the image around the origin,
>>> rather than flipping it around its center.
>>>
>>> For a 4x4 matrix, use reslice->SetResliceAxes(vtkMatrix4x4 *).  By using
>>> a 4x4 matrix, you can make sure that the correct center-of-rotation is
>>> applied.
>>>
>>>  - David
>>>
>>>
>>> On Mon, Sep 14, 2015 at 11:03 AM, Marcos <fotosentido at gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I attached a vtkImageFlip filter to my pipeline, but I can't find the
>>>> way to "switch off" this filter or revert its effects.
>>>>
>>>> I just want to flip my image when I press a button.
>>>>
>>>> Any suggestions?
>>>> Thank you.
>>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150914/e66d92a6/attachment.html>


More information about the Insight-users mailing list