Molding an image slice

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Molding an image slice

Miguel
Hello,

I have been trying for some days to "mold" a 3D image slice. (imagine a towel in the wind)

What I mean is that I have a 2D slice, extracted from a 3D vtkImageData, and one 3D vector for each pixel of the slice. I want to translate/transform/move each pixel from the 2D slice to a 3D position (and augmenting the extent of the 2D slice in x,y,z when necessary) while keeping these pixel stitched together. I believe my knowledge of all VTK filters is not that great, so I think something is already implemented for this, but I cannot find it.

Currently, my line of thinking is: create an unstructured grid, apply the vectors transformation, create a new vtkImageData from this transformation and map the pixel values through ids (cell IDs? point IDs? ).

In the end I would see a slice stretched, compressed and bent up, down and to the sides.

Thank you!
shark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

David Gobbi
Hi Shark,

I think the most efficient option would be a vtkTexture on a vtkPolyData.  You can use vtkPlaneSource to make a polydata that has as many points as your image has pixels.  If necessary, you can use vtkTransformTextureCoords to tweak the texture coords.

Then you can use e.g. vtkGridTransform or vtkBSplineTransform with vtkTransformPolyDataFilter to warp the plane, or perhaps vtkWarpVector.

Regards,
 - David


On Tue, Mar 21, 2017 at 6:26 AM, Shark <[hidden email]> wrote:
Hello,

I have been trying for some days to "mold" a 3D image slice. (imagine a
towel in the wind)

What I mean is that I have a 2D slice, extracted from a 3D vtkImageData, and
one 3D vector for each pixel of the slice. I want to
translate/transform/move each pixel from the 2D slice to a 3D position (and
augmenting the extent of the 2D slice in x,y,z when necessary) while keeping
these pixel stitched together. I believe my knowledge of all VTK filters is
not that great, so I think something is already implemented for this, but I
cannot find it.

Currently, my line of thinking is: create an unstructured grid, apply the
vectors transformation, create a new vtkImageData from this transformation
and map the pixel values through ids (cell IDs? point IDs? ).

In the end I would see a slice stretched, compressed and bent up, down and
to the sides.

Thank you!
shark



_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

David Gobbi
Here is an example of applying a texture map to a plane (the warping step would have to be added).
https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/TextureMapPlane

To properly set up the vtkPlaneSource to match the image geometry, it would be necessary to use these methods:
plane->SetResolution(xdivs, ydivs);
plane->SetOrigin(<coords of image corner (0,0)>)
plane->SetPoint1(<coords of image corner (1,0)>)
plane->SetPoint2(<coords of image corner (0,1)>)

On Tue, Mar 21, 2017 at 6:54 AM, David Gobbi <[hidden email]> wrote:
Hi Shark,

I think the most efficient option would be a vtkTexture on a vtkPolyData.  You can use vtkPlaneSource to make a polydata that has as many points as your image has pixels.  If necessary, you can use vtkTransformTextureCoords to tweak the texture coords.

Then you can use e.g. vtkGridTransform or vtkBSplineTransform with vtkTransformPolyDataFilter to warp the plane, or perhaps vtkWarpVector.

Regards,
 - David


On Tue, Mar 21, 2017 at 6:26 AM, Shark <[hidden email]> wrote:
Hello,

I have been trying for some days to "mold" a 3D image slice. (imagine a
towel in the wind)

What I mean is that I have a 2D slice, extracted from a 3D vtkImageData, and
one 3D vector for each pixel of the slice. I want to
translate/transform/move each pixel from the 2D slice to a 3D position (and
augmenting the extent of the 2D slice in x,y,z when necessary) while keeping
these pixel stitched together. I believe my knowledge of all VTK filters is
not that great, so I think something is already implemented for this, but I
cannot find it.

Currently, my line of thinking is: create an unstructured grid, apply the
vectors transformation, create a new vtkImageData from this transformation
and map the pixel values through ids (cell IDs? point IDs? ).

In the end I would see a slice stretched, compressed and bent up, down and
to the sides.

Thank you!
shark




_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

David Gobbi
Note: if you get a warning when you click the link to the example, try again without https:

On Tue, Mar 21, 2017 at 7:10 AM, David Gobbi <[hidden email]> wrote:
Here is an example of applying a texture map to a plane (the warping step would have to be added).
https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/TextureMapPlane

To properly set up the vtkPlaneSource to match the image geometry, it would be necessary to use these methods:
plane->SetResolution(xdivs, ydivs);
plane->SetOrigin(<coords of image corner (0,0)>)
plane->SetPoint1(<coords of image corner (1,0)>)
plane->SetPoint2(<coords of image corner (0,1)>)

On Tue, Mar 21, 2017 at 6:54 AM, David Gobbi <[hidden email]> wrote:
Hi Shark,

I think the most efficient option would be a vtkTexture on a vtkPolyData.  You can use vtkPlaneSource to make a polydata that has as many points as your image has pixels.  If necessary, you can use vtkTransformTextureCoords to tweak the texture coords.

Then you can use e.g. vtkGridTransform or vtkBSplineTransform with vtkTransformPolyDataFilter to warp the plane, or perhaps vtkWarpVector.

Regards,
 - David


On Tue, Mar 21, 2017 at 6:26 AM, Shark <[hidden email]> wrote:
Hello,

I have been trying for some days to "mold" a 3D image slice. (imagine a
towel in the wind)

What I mean is that I have a 2D slice, extracted from a 3D vtkImageData, and
one 3D vector for each pixel of the slice. I want to
translate/transform/move each pixel from the 2D slice to a 3D position (and
augmenting the extent of the 2D slice in x,y,z when necessary) while keeping
these pixel stitched together. I believe my knowledge of all VTK filters is
not that great, so I think something is already implemented for this, but I
cannot find it.

Currently, my line of thinking is: create an unstructured grid, apply the
vectors transformation, create a new vtkImageData from this transformation
and map the pixel values through ids (cell IDs? point IDs? ).

In the end I would see a slice stretched, compressed and bent up, down and
to the sides.

Thank you!
shark





_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

Miguel
David Gobbi,

thank you so much for the tips! I will explore them and let you know if it worked!
Best
Shark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

Miguel
David,

Unfortunately I haven't been able to figure it out.

I do not have a jpg image. I have a 3D CT image, stored in a VTKImageData. I also have another vtkImageData with 3 scalars - vector(x,y,z) representing the displacement of each CT pixel.

I am rendering the CT slice and the vectors as a glyph3D with arrow source.

What I want is to "stretch" the CT slice to fit the arrows, hence the molding.

It seams the following examples, combined with the one you provided, are something similar to what I want to achieve:
http://www.paraview.org/Wiki/VTK/Examples/Cxx/PolyData/WarpSurface
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/WarpVector

However I am having a hard time understanding how to put things together with the CT data's slice.
Best,
Shark
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

David Gobbi
Hi Shark,

The vtkTexture takes an arbitrary vtkImageData as input, the input (obviously) doesn't have to come from a jpeg file.  However, you will have to convert your CT image data to RGB or RGBA before using it as a texture, e.g. with vtkImageMapToColors via a greyscale lookup table.

 - David

On Tue, Mar 21, 2017 at 10:35 AM, Shark <[hidden email]> wrote:
David,

Unfortunately I haven't been able to figure it out.

I do not have a jpg image. I have a 3D CT image, stored in a VTKImageData. I
also have another vtkImageData with 3 scalars - vector(x,y,z) representing
the displacement of each CT pixel.

I am rendering the CT slice and the vectors as a glyph3D with arrow source.

What I want is to "stretch" the CT slice to fit the arrows, hence the
molding.

It seams the following examples, combined with the one you provided, are
something similar to what I want to achieve:
http://www.paraview.org/Wiki/VTK/Examples/Cxx/PolyData/WarpSurface
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/WarpVector

However I am having a hard time understanding how to put things together
with the CT data's slice.
Best,
Shark




--
View this message in context: http://vtk.1045678.n5.nabble.com/Molding-an-image-slice-tp5742555p5742574.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

Miguel
Hello David Gobbi,

Thank you for your reply. I have been busy with other things, lately, but I have managed to make it work.
I can generate a plane out of the slice, apply a 3D transformation per point of the plane. Before applying the vtkTexture extracted from the slice, I am able to see it and it looks correct.

However, when the I pass the texture to the actor, it seems that the texture is not well mapped to the plane. This is very noticeable in some corners of the image where the texture is simply cut, because the plane is retracted in that corner. So, instead of the color texture being molded to the deformed plane, it is simply applied on top of it without any other consideration.

Another thing I have noticed is when I set up the resolution of the plane, I have to reduce a unit from its dimensions, so I can match the number of points in the displacement field:

vtkPlaneSource* plane = vtkPlaneSource::New();
plane->SetXResolution(img->GetDimensions()[0] - 1);
plane->SetYResolution(img->GetDimensions()[1] - 1);

In this way, both the plane and the warpVector will have the same number of points. Is this expected? or is it that my displacement field could have some issue?

Another thing I have noticed is that when I am setting the vtkDoubleArray to pass to the warpVector, if I set 3 components, and set the Z, there is a crazy behavior of how the texture is applied to the plane. With the Z coordinate, things get strange and the texture gets randomly inverted X <-> Y in different slices.

If I only pass the X and Y coords of the points' transformations (and keep Z=0), everything looks good. But only 2D transformation. Howevever, when I set the component to 2 (X and Y, no Z), the plane is not transformed.


I think I am almost there, but something is just not quite right.
Cheers,
Shark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

David Gobbi
On Wed, Apr 5, 2017 at 5:23 AM, Shark <[hidden email]> wrote:

However, when the I pass the texture to the actor, it seems that the texture
is not well mapped to the plane. This is very noticeable in some corners of
the image where the texture is simply cut, because the plane is retracted in
that corner. So, instead of the color texture being molded to the deformed
plane, it is simply applied on top of it without any other consideration.

If the parts of the plane are folded back, then you might have to use either
vtkGridTransform or vtkBSplineTransform, instead of using vtkWarpVector.

Another thing I have noticed is when I set up the resolution of the plane, I
have to reduce a unit from its dimensions, so I can match the number of
points in the displacement field:

The resolution of the vtkPlaneSource is the number of facets (little squares)
that make up the plane.  It's basic math that the number of points will be the
number of facets plus one.

The texture coords are associated with the points, so you have two options:
you can set the number of facets to be equal to the number of pixels in your
image, and then map the texture coords to the corners of your pixels.  Or you
can set the number of points to be equal to the number of pixels, and map
the texture coords to the centers of your pixels.  Both of these methods is
perfectly valid (you just have to be sure that you set the texture coords
correctly).

Also, remember that in texture coordinates, the position (0,0) is at the corner
of the first texel, whereas in image coordinates, the origin is at the center of
the first pixel.

Another thing I have noticed is that when I am setting the vtkDoubleArray to
pass to the warpVector, if I set 3 components, and set the Z, there is a
crazy behavior of how the texture is applied to the plane. With the Z
coordinate, things get strange and the texture gets randomly inverted X <->
Y in different slices.

You might have better luck applying the transformation with vtkGridTransform
and vtkTransformPolyDataFilter.  The vtkGridTransform expects a vector image
as its input, i.e. an image where each pixel is a displacement vector (dx,dy,dz).

 - David

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

Miguel
David,
all your tips are extremely appreciated!
I am sure this will be useful for other people in the future :-)

I have solved my case by adding celldata values to my plane, and then passing the LUT to the mapper.
plane->GetOutput()->GetCellData()->SetScalars(cellData);

Worked as a charm. Now my plane is correctly colored.  

Best regards,
shark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Molding an image slice

David Gobbi
Hi Shark,

Yup, adding scalar attributes to the polydata works.  As you can probably
tell, though, I'm a fan of using texture maps for these sorts of problems.

 - David


On Thu, Apr 6, 2017 at 8:08 AM, Shark <[hidden email]> wrote:
David,
all your tips are extremely appreciated!
I am sure this will be useful for other people in the future :-)

I have solved my case by adding celldata values to my plane, and then
passing the LUT to the mapper.
plane->GetOutput()->GetCellData()->SetScalars(cellData);

Worked as a charm. Now my plane is correctly colored.

Best regards,
shark

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Loading...