vtkimagereslice Issues/Questions

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

vtkimagereslice Issues/Questions

Bert Renolds
Hello all,
I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

Questions:
1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

2.
vimage = 3dnode.GetImageData()
reslice = vtk.vtkImageReslice()
reslice.SetSlabModeToMean()
reslice.SetInputData(vimage)
reslice.SetSlabNumberOfSlices(10)
reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)
reslice.SetOutputSpacing(0.5,0.5,0.5)
reslice.Update()
vimageOut = reslice.GetOutput()
3dnode.SetAndObserveImageData(vimageOut)

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

Hope I have explained everything.  Thanks ahead of time for any help provided.

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

Steve Pieper-2
Hi Bert - 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

3) If the volume node spacing is set correctly then the exported dicom should also be right.

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

HTH,
Steve



On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:
Hello all,
I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

Questions:
1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

2.
vimage = 3dnode.GetImageData()
reslice = vtk.vtkImageReslice()
reslice.SetSlabModeToMean()
reslice.SetInputData(vimage)
reslice.SetSlabNumberOfSlices(10)
reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)
reslice.SetOutputSpacing(0.5,0.5,0.5)
reslice.Update()
vimageOut = reslice.GetOutput()
3dnode.SetAndObserveImageData(vimageOut)

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

Hope I have explained everything.  Thanks ahead of time for any help provided.

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ


_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

Bert Renolds
In reply to this post by Bert Renolds
2) If I set the image spacing to 0.5, 0.5, 5.0 with a slab slicing of 10 and change the volume node spacing to match I end up with a completely blank volume (i.e. all pixel values 0)

So I still have the same issue.....  Anyone else have ideas to resolve me problem??

Bert

On Wed, Mar 29, 2017 at 5:59 PM, Steve Pieper <[hidden email]> wrote:
Hi Bert - 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

3) If the volume node spacing is set correctly then the exported dicom should also be right.

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

HTH,
Steve



On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:
Hello all,
I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

Questions:
1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

2.
vimage = 3dnode.GetImageData()
reslice = vtk.vtkImageReslice()
reslice.SetSlabModeToMean()
reslice.SetInputData(vimage)
reslice.SetSlabNumberOfSlices(10)
reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)
reslice.SetOutputSpacing(0.5,0.5,0.5)
reslice.Update()
vimageOut = reslice.GetOutput()
3dnode.SetAndObserveImageData(vimageOut)

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

Hope I have explained everything.  Thanks ahead of time for any help provided.

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ



_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

lasso2

vtkImageReslice is the most powerful and hardest-to-use filter that I’ve ever encountered in VTK. I would recommend to avoid using it directly, but use them through Slicer modules instead.

 

For example, you can get what you need by using crop and resample modules:

·         Load any volume => referenceVolume

·         In Volumes module: change the spacing to 0.5 0.5 5.0

·         In Crop Volume: Crop referenceVolume to your inputVolume => this creates a volume that has the same size as inputVolume, but with a spacing of 0.5 0.5 5.0

·         In Resample Scalar/Vector/DWI Volume: resample inputVolume, using referenceVolume as reference volume

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of Bert Renolds
Sent: March 30, 2017 9:22
To: Steve Pieper <[hidden email]>
Cc: SPL Slicer Devel <[hidden email]>
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

2) If I set the image spacing to 0.5, 0.5, 5.0 with a slab slicing of 10 and change the volume node spacing to match I end up with a completely blank volume (i.e. all pixel values 0)

 

So I still have the same issue.....  Anyone else have ideas to resolve me problem??

 

Bert

 

On Wed, Mar 29, 2017 at 5:59 PM, Steve Pieper <[hidden email]> wrote:

Hi Bert - 

 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

 

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

 

3) If the volume node spacing is set correctly then the exported dicom should also be right.

 

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

 

HTH,

Steve

 

 

On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:

Hello all,

I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

 

Questions:

1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

 

2.

vimage = 3dnode.GetImageData()

reslice = vtk.vtkImageReslice()

reslice.SetSlabModeToMean()

reslice.SetInputData(vimage)

reslice.SetSlabNumberOfSlices(10)

reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)

reslice.SetOutputSpacing(0.5,0.5,0.5)

reslice.Update()

vimageOut = reslice.GetOutput()

3dnode.SetAndObserveImageData(vimageOut)

 

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

 

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

 

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

 

Hope I have explained everything.  Thanks ahead of time for any help provided.

 

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

 

 


_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

Bert Renolds
In reply to this post by Bert Renolds
Andrea,
Thanks for the advice.  The issue with your solution is that it does not allow for the collapsing of 10 slices to 1 slice using the mean of every pixel.  Resampling the volume will just perform a linear interpolation instead.  The collapsing of the slices is fundamental for the task I am trying to accomplish.  Unfortunately, I think I must struggle through vtkImageReslice and find the proper parameters.

Bert

On Thu, Mar 30, 2017 at 11:19 AM, Andras Lasso <[hidden email]> wrote:

vtkImageReslice is the most powerful and hardest-to-use filter that I’ve ever encountered in VTK. I would recommend to avoid using it directly, but use them through Slicer modules instead.

 

For example, you can get what you need by using crop and resample modules:

·         Load any volume => referenceVolume

·         In Volumes module: change the spacing to 0.5 0.5 5.0

·         In Crop Volume: Crop referenceVolume to your inputVolume => this creates a volume that has the same size as inputVolume, but with a spacing of 0.5 0.5 5.0

·         In Resample Scalar/Vector/DWI Volume: resample inputVolume, using referenceVolume as reference volume

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of Bert Renolds
Sent: March 30, 2017 9:22
To: Steve Pieper <[hidden email]>
Cc: SPL Slicer Devel <[hidden email]>
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

2) If I set the image spacing to 0.5, 0.5, 5.0 with a slab slicing of 10 and change the volume node spacing to match I end up with a completely blank volume (i.e. all pixel values 0)

 

So I still have the same issue.....  Anyone else have ideas to resolve me problem??

 

Bert

 

On Wed, Mar 29, 2017 at 5:59 PM, Steve Pieper <[hidden email]> wrote:

Hi Bert - 

 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

 

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

 

3) If the volume node spacing is set correctly then the exported dicom should also be right.

 

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

 

HTH,

Steve

 

 

On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:

Hello all,

I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

 

Questions:

1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

 

2.

vimage = 3dnode.GetImageData()

reslice = vtk.vtkImageReslice()

reslice.SetSlabModeToMean()

reslice.SetInputData(vimage)

reslice.SetSlabNumberOfSlices(10)

reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)

reslice.SetOutputSpacing(0.5,0.5,0.5)

reslice.Update()

vimageOut = reslice.GetOutput()

3dnode.SetAndObserveImageData(vimageOut)

 

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

 

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

 

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

 

Hope I have explained everything.  Thanks ahead of time for any help provided.

 

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

 

 



_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

lasso2
In reply to this post by Bert Renolds

You can average the slices using numpy array manipulation then resample using nearest neighbor interpolator.

 

See Steve’s recent example for image manipulation using numpy:

http://slicer-users.65878.n3.nabble.com/How-to-change-INVALID-label-maps-tp4031996p4032001.html

>>> a = slicer.util.array('Output Volume-label')

>>> a[a== 11400] = 2

Andras

 

 

From: Bert Renolds [mailto:[hidden email]]
Sent: March 30, 2017 12:06
To: Andras Lasso <[hidden email]>
Cc: Steve Pieper <[hidden email]>; SPL Slicer Devel <[hidden email]>
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

Andrea,

Thanks for the advice.  The issue with your solution is that it does not allow for the collapsing of 10 slices to 1 slice using the mean of every pixel.  Resampling the volume will just perform a linear interpolation instead.  The collapsing of the slices is fundamental for the task I am trying to accomplish.  Unfortunately, I think I must struggle through vtkImageReslice and find the proper parameters.

 

Bert

 

On Thu, Mar 30, 2017 at 11:19 AM, Andras Lasso <[hidden email]> wrote:

vtkImageReslice is the most powerful and hardest-to-use filter that I’ve ever encountered in VTK. I would recommend to avoid using it directly, but use them through Slicer modules instead.

 

For example, you can get what you need by using crop and resample modules:

·         Load any volume => referenceVolume

·         In Volumes module: change the spacing to 0.5 0.5 5.0

·         In Crop Volume: Crop referenceVolume to your inputVolume => this creates a volume that has the same size as inputVolume, but with a spacing of 0.5 0.5 5.0

·         In Resample Scalar/Vector/DWI Volume: resample inputVolume, using referenceVolume as reference volume

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of Bert Renolds
Sent: March 30, 2017 9:22
To: Steve Pieper <
[hidden email]>
Cc: SPL Slicer Devel <
[hidden email]>
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

2) If I set the image spacing to 0.5, 0.5, 5.0 with a slab slicing of 10 and change the volume node spacing to match I end up with a completely blank volume (i.e. all pixel values 0)

 

So I still have the same issue.....  Anyone else have ideas to resolve me problem??

 

Bert

 

On Wed, Mar 29, 2017 at 5:59 PM, Steve Pieper <[hidden email]> wrote:

Hi Bert - 

 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

 

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

 

3) If the volume node spacing is set correctly then the exported dicom should also be right.

 

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

 

HTH,

Steve

 

 

On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:

Hello all,

I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

 

Questions:

1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

 

2.

vimage = 3dnode.GetImageData()

reslice = vtk.vtkImageReslice()

reslice.SetSlabModeToMean()

reslice.SetInputData(vimage)

reslice.SetSlabNumberOfSlices(10)

reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)

reslice.SetOutputSpacing(0.5,0.5,0.5)

reslice.Update()

vimageOut = reslice.GetOutput()

3dnode.SetAndObserveImageData(vimageOut)

 

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

 

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

 

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

 

Hope I have explained everything.  Thanks ahead of time for any help provided.

 

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

 

 

 


_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

Bert Renolds
In reply to this post by Bert Renolds
I gave up on the vtkImageReslice.  No matter what I tried I could not get it to produce what I want.  Instead I used vtkImageSlab.  I have one last issue that I need some help with:
After I run vtkImageSlab I get a huge dataset where each slice represents the average of the 10 slices around it.   I now want to step through these slices and only keep every 10th slice.  Andras I took your advice and used a numpy array to do it.  I am having a problem with it though
See below:

image = self.outVolume.GetImageData()
vtk_data = image.GetPointData().GetScalars()
numpy_data = vtk.util.numpy_support.vtk_to_numpy(vtk_data)
imageDims = image.GetDimensions()
numpy_data = numpy.reshape(numpy_data, [imageDims[0], imageDims[1], imageDims[2]], 'F')
numpy_data = numpy_data.transpose(2,1,0)
dims = numpy_data.shape
numpy_data = numpy_data[0:dims[0]:10]
numpy_data = numpy_data.transpose(2,1,0)
dimsAfter = numpy_data.shape
numpy_data = numpy.ravel(numpy_data, order='F')
vtk_data = vtk.util.numpy_support.numpy_to_vtk(numpy_data)
img_vtk = vtk.vtkImageData()
img_vtk.SetDimensions(imageDims[0], imageDims[1], dimsAfter[2])
img_vtk.SetSpacing(1.0,1.0,1.0)
img_vtk.SetOrigin(0.0,0.0,0.0)
img_vtk.GetPointData().SetScalars(vtk_data)
self.outVolume.SetSpacing(0.5,0.5,5.0)

#now...when I go to set the image data in the self.outVolume with the line below...slicer crashes and complains Unhandled exception at 0x000007FED34B7213 (vtkCommon-7.1.dll) in SlicerApp-real.exe: 0xC0000005: Access violation reading location 0x0000000046D3B3F6

self.outVolume.SetAndObserveImageData(img_vtk)

#When I run this same code in the python interactor it works fine and there is no access violation but when I run it in my python scripted module it crashes.  Any ideas on how to fix this?  I believe the problem is that slicer cannot access the vtk_data within my module which causes the crash.  How would I fix this?

On Thu, Mar 30, 2017 at 12:15 PM, Andras Lasso <[hidden email]> wrote:

You can average the slices using numpy array manipulation then resample using nearest neighbor interpolator.

 

See Steve’s recent example for image manipulation using numpy:

http://slicer-users.65878.n3.nabble.com/How-to-change-INVALID-label-maps-tp4031996p4032001.html

>>> a = slicer.util.array('Output Volume-label')

>>> a[a== 11400] = 2

Andras

 

 

From: Bert Renolds [mailto:[hidden email]]
Sent: March 30, 2017 12:06
To: Andras Lasso <[hidden email]>
Cc: Steve Pieper <[hidden email]>; SPL Slicer Devel <[hidden email]>


Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

Andrea,

Thanks for the advice.  The issue with your solution is that it does not allow for the collapsing of 10 slices to 1 slice using the mean of every pixel.  Resampling the volume will just perform a linear interpolation instead.  The collapsing of the slices is fundamental for the task I am trying to accomplish.  Unfortunately, I think I must struggle through vtkImageReslice and find the proper parameters.

 

Bert

 

On Thu, Mar 30, 2017 at 11:19 AM, Andras Lasso <[hidden email]> wrote:

vtkImageReslice is the most powerful and hardest-to-use filter that I’ve ever encountered in VTK. I would recommend to avoid using it directly, but use them through Slicer modules instead.

 

For example, you can get what you need by using crop and resample modules:

·         Load any volume => referenceVolume

·         In Volumes module: change the spacing to 0.5 0.5 5.0

·         In Crop Volume: Crop referenceVolume to your inputVolume => this creates a volume that has the same size as inputVolume, but with a spacing of 0.5 0.5 5.0

·         In Resample Scalar/Vector/DWI Volume: resample inputVolume, using referenceVolume as reference volume

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of Bert Renolds
Sent: March 30, 2017 9:22
To: Steve Pieper <
[hidden email]>
Cc: SPL Slicer Devel <
[hidden email]>
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

2) If I set the image spacing to 0.5, 0.5, 5.0 with a slab slicing of 10 and change the volume node spacing to match I end up with a completely blank volume (i.e. all pixel values 0)

 

So I still have the same issue.....  Anyone else have ideas to resolve me problem??

 

Bert

 

On Wed, Mar 29, 2017 at 5:59 PM, Steve Pieper <[hidden email]> wrote:

Hi Bert - 

 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

 

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

 

3) If the volume node spacing is set correctly then the exported dicom should also be right.

 

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

 

HTH,

Steve

 

 

On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:

Hello all,

I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

 

Questions:

1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

 

2.

vimage = 3dnode.GetImageData()

reslice = vtk.vtkImageReslice()

reslice.SetSlabModeToMean()

reslice.SetInputData(vimage)

reslice.SetSlabNumberOfSlices(10)

reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)

reslice.SetOutputSpacing(0.5,0.5,0.5)

reslice.Update()

vimageOut = reslice.GetOutput()

3dnode.SetAndObserveImageData(vimageOut)

 

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

 

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

 

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

 

Hope I have explained everything.  Thanks ahead of time for any help provided.

 

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

 

 

 



_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

lasso2
In reply to this post by Bert Renolds

Passing data between numpy and VTK is tricky.

 

It's easier to create a volume that has the desired geometry (0.5 x 0.5 x 5.0 spacing) and it as a reference volume in resample scalar/vector/dwi volume module, with nearest neighbor interpolation.

 

Andras

 

From: [hidden email]
Sent: Friday, March 31, 2017 4:30 PM
To: [hidden email]
Cc: [hidden email]; [hidden email]
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

I gave up on the vtkImageReslice.  No matter what I tried I could not get it to produce what I want.  Instead I used vtkImageSlab.  I have one last issue that I need some help with:
After I run vtkImageSlab I get a huge dataset where each slice represents the average of the 10 slices around it.   I now want to step through these slices and only keep every 10th slice.  Andras I took your advice and used a numpy array to do it.  I am having a problem with it though
See below:

image = self.outVolume.GetImageData()
vtk_data = image.GetPointData().GetScalars()
numpy_data = vtk.util.numpy_support.vtk_to_numpy(vtk_data)
imageDims = image.GetDimensions()
numpy_data = numpy.reshape(numpy_data, [imageDims[0], imageDims[1], imageDims[2]], 'F')
numpy_data = numpy_data.transpose(2,1,0)
dims = numpy_data.shape
numpy_data = numpy_data[0:dims[0]:10]
numpy_data = numpy_data.transpose(2,1,0)
dimsAfter = numpy_data.shape
numpy_data = numpy.ravel(numpy_data, order='F')
vtk_data = vtk.util.numpy_support.numpy_to_vtk(numpy_data)
img_vtk = vtk.vtkImageData()
img_vtk.SetDimensions(imageDims[0], imageDims[1], dimsAfter[2])
img_vtk.SetSpacing(1.0,1.0,1.0)
img_vtk.SetOrigin(0.0,0.0,0.0)
img_vtk.GetPointData().SetScalars(vtk_data)
self.outVolume.SetSpacing(0.5,0.5,5.0)

#now...when I go to set the image data in the self.outVolume with the line below...slicer crashes and complains Unhandled exception at 0x000007FED34B7213 (vtkCommon-7.1.dll) in SlicerApp-real.exe: 0xC0000005: Access violation reading location 0x0000000046D3B3F6

self.outVolume.SetAndObserveImageData(img_vtk)

#When I run this same code in the python interactor it works fine and there is no access violation but when I run it in my python scripted module it crashes.  Any ideas on how to fix this?  I believe the problem is that slicer cannot access the vtk_data within my module which causes the crash.  How would I fix this?

On Thu, Mar 30, 2017 at 12:15 PM, Andras Lasso <[hidden email]> wrote:

You can average the slices using numpy array manipulation then resample using nearest neighbor interpolator.

 

See Steve’s recent example for image manipulation using numpy:

http://slicer-users.65878.n3.nabble.com/How-to-change-INVALID-label-maps-tp4031996p4032001.html

>>> a = slicer.util.array('Output Volume-label')

>>> a[a== 11400] = 2

Andras

 

 

From: Bert Renolds [mailto:[hidden email]]
Sent: March 30, 2017 12:06
To: Andras Lasso <[hidden email]>
Cc: Steve Pieper <[hidden email]>; SPL Slicer Devel <[hidden email]>


Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

Andrea,

Thanks for the advice.  The issue with your solution is that it does not allow for the collapsing of 10 slices to 1 slice using the mean of every pixel.  Resampling the volume will just perform a linear interpolation instead.  The collapsing of the slices is fundamental for the task I am trying to accomplish.  Unfortunately, I think I must struggle through vtkImageReslice and find the proper parameters.

 

Bert

 

On Thu, Mar 30, 2017 at 11:19 AM, Andras Lasso <[hidden email]> wrote:

vtkImageReslice is the most powerful and hardest-to-use filter that I’ve ever encountered in VTK. I would recommend to avoid using it directly, but use them through Slicer modules instead.

 

For example, you can get what you need by using crop and resample modules:

·         Load any volume => referenceVolume

·         In Volumes module: change the spacing to 0.5 0.5 5.0

·         In Crop Volume: Crop referenceVolume to your inputVolume => this creates a volume that has the same size as inputVolume, but with a spacing of 0.5 0.5 5.0

·         In Resample Scalar/Vector/DWI Volume: resample inputVolume, using referenceVolume as reference volume

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of Bert Renolds
Sent: March 30, 2017 9:22
To: Steve Pieper <
[hidden email]>
Cc: SPL Slicer Devel <
[hidden email]>
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

2) If I set the image spacing to 0.5, 0.5, 5.0 with a slab slicing of 10 and change the volume node spacing to match I end up with a completely blank volume (i.e. all pixel values 0)

 

So I still have the same issue.....  Anyone else have ideas to resolve me problem??

 

Bert

 

On Wed, Mar 29, 2017 at 5:59 PM, Steve Pieper <[hidden email]> wrote:

Hi Bert - 

 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

 

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

 

3) If the volume node spacing is set correctly then the exported dicom should also be right.

 

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

 

HTH,

Steve

 

 

On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:

Hello all,

I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

 

Questions:

1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

 

2.

vimage = 3dnode.GetImageData()

reslice = vtk.vtkImageReslice()

reslice.SetSlabModeToMean()

reslice.SetInputData(vimage)

reslice.SetSlabNumberOfSlices(10)

reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)

reslice.SetOutputSpacing(0.5,0.5,0.5)

reslice.Update()

vimageOut = reslice.GetOutput()

3dnode.SetAndObserveImageData(vimageOut)

 

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

 

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

 

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

 

Hope I have explained everything.  Thanks ahead of time for any help provided.

 

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

 

 

 



_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

Bert Renolds
In reply to this post by Bert Renolds
I would really like to fix the issue using what I have.  By performing this task with a numpy array I have much better control over the final data than I do with the resample scalar volume module.......  Do you have any idea of how I would perform this task correctly?

On Fri, Mar 31, 2017 at 4:40 PM, Andras Lasso <[hidden email]> wrote:

Passing data between numpy and VTK is tricky.

 

It's easier to create a volume that has the desired geometry (0.5 x 0.5 x 5.0 spacing) and it as a reference volume in resample scalar/vector/dwi volume module, with nearest neighbor interpolation.

 

Andras

 

From: [hidden email]
Sent: Friday, March 31, 2017 4:30 PM
To: [hidden email]
Cc: [hidden email]; [hidden email]


Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

I gave up on the vtkImageReslice.  No matter what I tried I could not get it to produce what I want.  Instead I used vtkImageSlab.  I have one last issue that I need some help with:
After I run vtkImageSlab I get a huge dataset where each slice represents the average of the 10 slices around it.   I now want to step through these slices and only keep every 10th slice.  Andras I took your advice and used a numpy array to do it.  I am having a problem with it though
See below:

image = self.outVolume.GetImageData()
vtk_data = image.GetPointData().GetScalars()
numpy_data = vtk.util.numpy_support.vtk_to_numpy(vtk_data)
imageDims = image.GetDimensions()
numpy_data = numpy.reshape(numpy_data, [imageDims[0], imageDims[1], imageDims[2]], 'F')
numpy_data = numpy_data.transpose(2,1,0)
dims = numpy_data.shape
numpy_data = numpy_data[0:dims[0]:10]
numpy_data = numpy_data.transpose(2,1,0)
dimsAfter = numpy_data.shape
numpy_data = numpy.ravel(numpy_data, order='F')
vtk_data = vtk.util.numpy_support.numpy_to_vtk(numpy_data)
img_vtk = vtk.vtkImageData()
img_vtk.SetDimensions(imageDims[0], imageDims[1], dimsAfter[2])
img_vtk.SetSpacing(1.0,1.0,1.0)
img_vtk.SetOrigin(0.0,0.0,0.0)
img_vtk.GetPointData().SetScalars(vtk_data)
self.outVolume.SetSpacing(0.5,0.5,5.0)

#now...when I go to set the image data in the self.outVolume with the line below...slicer crashes and complains Unhandled exception at 0x000007FED34B7213 (vtkCommon-7.1.dll) in SlicerApp-real.exe: 0xC0000005: Access violation reading location 0x0000000046D3B3F6

self.outVolume.SetAndObserveImageData(img_vtk)

#When I run this same code in the python interactor it works fine and there is no access violation but when I run it in my python scripted module it crashes.  Any ideas on how to fix this?  I believe the problem is that slicer cannot access the vtk_data within my module which causes the crash.  How would I fix this?

On Thu, Mar 30, 2017 at 12:15 PM, Andras Lasso <[hidden email]> wrote:

You can average the slices using numpy array manipulation then resample using nearest neighbor interpolator.

 

See Steve’s recent example for image manipulation using numpy:

http://slicer-users.65878.n3.nabble.com/How-to-change-INVALID-label-maps-tp4031996p4032001.html

>>> a = slicer.util.array('Output Volume-label')

>>> a[a== 11400] = 2

Andras

 

 

From: Bert Renolds [mailto:[hidden email]]
Sent: March 30, 2017 12:06
To: Andras Lasso <[hidden email]>
Cc: Steve Pieper <[hidden email]>; SPL Slicer Devel <[hidden email]>


Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

Andrea,

Thanks for the advice.  The issue with your solution is that it does not allow for the collapsing of 10 slices to 1 slice using the mean of every pixel.  Resampling the volume will just perform a linear interpolation instead.  The collapsing of the slices is fundamental for the task I am trying to accomplish.  Unfortunately, I think I must struggle through vtkImageReslice and find the proper parameters.

 

Bert

 

On Thu, Mar 30, 2017 at 11:19 AM, Andras Lasso <[hidden email]> wrote:

vtkImageReslice is the most powerful and hardest-to-use filter that I’ve ever encountered in VTK. I would recommend to avoid using it directly, but use them through Slicer modules instead.

 

For example, you can get what you need by using crop and resample modules:

·         Load any volume => referenceVolume

·         In Volumes module: change the spacing to 0.5 0.5 5.0

·         In Crop Volume: Crop referenceVolume to your inputVolume => this creates a volume that has the same size as inputVolume, but with a spacing of 0.5 0.5 5.0

·         In Resample Scalar/Vector/DWI Volume: resample inputVolume, using referenceVolume as reference volume

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of Bert Renolds
Sent: March 30, 2017 9:22
To: Steve Pieper <
[hidden email]>
Cc: SPL Slicer Devel <
[hidden email]>
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

2) If I set the image spacing to 0.5, 0.5, 5.0 with a slab slicing of 10 and change the volume node spacing to match I end up with a completely blank volume (i.e. all pixel values 0)

 

So I still have the same issue.....  Anyone else have ideas to resolve me problem??

 

Bert

 

On Wed, Mar 29, 2017 at 5:59 PM, Steve Pieper <[hidden email]> wrote:

Hi Bert - 

 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

 

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

 

3) If the volume node spacing is set correctly then the exported dicom should also be right.

 

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

 

HTH,

Steve

 

 

On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:

Hello all,

I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

 

Questions:

1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

 

2.

vimage = 3dnode.GetImageData()

reslice = vtk.vtkImageReslice()

reslice.SetSlabModeToMean()

reslice.SetInputData(vimage)

reslice.SetSlabNumberOfSlices(10)

reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)

reslice.SetOutputSpacing(0.5,0.5,0.5)

reslice.Update()

vimageOut = reslice.GetOutput()

3dnode.SetAndObserveImageData(vimageOut)

 

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

 

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

 

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

 

Hope I have explained everything.  Thanks ahead of time for any help provided.

 

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

 

 

 




_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

lasso2
In reply to this post by Bert Renolds

I don’t think you can transfer the ownership of a numpy array (that was allocated by numpy) to a vtkImageData object. Instead, allocate the voxel data using vtkImageData::AllocateScalars and fill that buffer using numpy.

 

I rarely use numpy for image processing, so others may have better suggestions.

 

Andras

 

From: [hidden email]
Sent: Friday, March 31, 2017 4:43 PM
To: [hidden email]
Cc: [hidden email]; [hidden email]
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

I would really like to fix the issue using what I have.  By performing this task with a numpy array I have much better control over the final data than I do with the resample scalar volume module.......  Do you have any idea of how I would perform this task correctly?

On Fri, Mar 31, 2017 at 4:40 PM, Andras Lasso <[hidden email]> wrote:

Passing data between numpy and VTK is tricky.

 

It's easier to create a volume that has the desired geometry (0.5 x 0.5 x 5.0 spacing) and it as a reference volume in resample scalar/vector/dwi volume module, with nearest neighbor interpolation.

 

Andras

 

From: [hidden email]
Sent: Friday, March 31, 2017 4:30 PM
To: [hidden email]
Cc: [hidden email]; [hidden email]


Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

I gave up on the vtkImageReslice.  No matter what I tried I could not get it to produce what I want.  Instead I used vtkImageSlab.  I have one last issue that I need some help with:
After I run vtkImageSlab I get a huge dataset where each slice represents the average of the 10 slices around it.   I now want to step through these slices and only keep every 10th slice.  Andras I took your advice and used a numpy array to do it.  I am having a problem with it though
See below:

image = self.outVolume.GetImageData()
vtk_data = image.GetPointData().GetScalars()
numpy_data = vtk.util.numpy_support.vtk_to_numpy(vtk_data)
imageDims = image.GetDimensions()
numpy_data = numpy.reshape(numpy_data, [imageDims[0], imageDims[1], imageDims[2]], 'F')
numpy_data = numpy_data.transpose(2,1,0)
dims = numpy_data.shape
numpy_data = numpy_data[0:dims[0]:10]
numpy_data = numpy_data.transpose(2,1,0)
dimsAfter = numpy_data.shape
numpy_data = numpy.ravel(numpy_data, order='F')
vtk_data = vtk.util.numpy_support.numpy_to_vtk(numpy_data)
img_vtk = vtk.vtkImageData()
img_vtk.SetDimensions(imageDims[0], imageDims[1], dimsAfter[2])
img_vtk.SetSpacing(1.0,1.0,1.0)
img_vtk.SetOrigin(0.0,0.0,0.0)
img_vtk.GetPointData().SetScalars(vtk_data)
self.outVolume.SetSpacing(0.5,0.5,5.0)

#now...when I go to set the image data in the self.outVolume with the line below...slicer crashes and complains Unhandled exception at 0x000007FED34B7213 (vtkCommon-7.1.dll) in SlicerApp-real.exe: 0xC0000005: Access violation reading location 0x0000000046D3B3F6

self.outVolume.SetAndObserveImageData(img_vtk)

#When I run this same code in the python interactor it works fine and there is no access violation but when I run it in my python scripted module it crashes.  Any ideas on how to fix this?  I believe the problem is that slicer cannot access the vtk_data within my module which causes the crash.  How would I fix this?

On Thu, Mar 30, 2017 at 12:15 PM, Andras Lasso <[hidden email]> wrote:

You can average the slices using numpy array manipulation then resample using nearest neighbor interpolator.

 

See Steve’s recent example for image manipulation using numpy:

http://slicer-users.65878.n3.nabble.com/How-to-change-INVALID-label-maps-tp4031996p4032001.html

>>> a = slicer.util.array('Output Volume-label')

>>> a[a== 11400] = 2

Andras

 

 

From: Bert Renolds [mailto:[hidden email]]
Sent: March 30, 2017 12:06
To: Andras Lasso <[hidden email]>
Cc: Steve Pieper <[hidden email]>; SPL Slicer Devel <[hidden email]>


Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

Andrea,

Thanks for the advice.  The issue with your solution is that it does not allow for the collapsing of 10 slices to 1 slice using the mean of every pixel.  Resampling the volume will just perform a linear interpolation instead.  The collapsing of the slices is fundamental for the task I am trying to accomplish.  Unfortunately, I think I must struggle through vtkImageReslice and find the proper parameters.

 

Bert

 

On Thu, Mar 30, 2017 at 11:19 AM, Andras Lasso <[hidden email]> wrote:

vtkImageReslice is the most powerful and hardest-to-use filter that I’ve ever encountered in VTK. I would recommend to avoid using it directly, but use them through Slicer modules instead.

 

For example, you can get what you need by using crop and resample modules:

·         Load any volume => referenceVolume

·         In Volumes module: change the spacing to 0.5 0.5 5.0

·         In Crop Volume: Crop referenceVolume to your inputVolume => this creates a volume that has the same size as inputVolume, but with a spacing of 0.5 0.5 5.0

·         In Resample Scalar/Vector/DWI Volume: resample inputVolume, using referenceVolume as reference volume

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of Bert Renolds
Sent: March 30, 2017 9:22
To: Steve Pieper <
[hidden email]>
Cc: SPL Slicer Devel <
[hidden email]>
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

2) If I set the image spacing to 0.5, 0.5, 5.0 with a slab slicing of 10 and change the volume node spacing to match I end up with a completely blank volume (i.e. all pixel values 0)

 

So I still have the same issue.....  Anyone else have ideas to resolve me problem??

 

Bert

 

On Wed, Mar 29, 2017 at 5:59 PM, Steve Pieper <[hidden email]> wrote:

Hi Bert - 

 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

 

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

 

3) If the volume node spacing is set correctly then the exported dicom should also be right.

 

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

 

HTH,

Steve

 

 

On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:

Hello all,

I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

 

Questions:

1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

 

2.

vimage = 3dnode.GetImageData()

reslice = vtk.vtkImageReslice()

reslice.SetSlabModeToMean()

reslice.SetInputData(vimage)

reslice.SetSlabNumberOfSlices(10)

reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)

reslice.SetOutputSpacing(0.5,0.5,0.5)

reslice.Update()

vimageOut = reslice.GetOutput()

3dnode.SetAndObserveImageData(vimageOut)

 

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

 

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

 

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

 

Hope I have explained everything.  Thanks ahead of time for any help provided.

 

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

 

 

 




_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkimagereslice Issues/Questions

Bert Renolds
In reply to this post by Bert Renolds
I actually just managed to fix it.  I changed this line of code:

vtk_data = vtk.util.numpy_support.numpy_to_vtk(numpy_data, deep=True, array_type=vtk.VTK_SHORT)

Basically I needed to do a deep copy of the numpy to vtk.......makes sense.  Thanks for trying to help.  Hopefully this email chain will help someone else in the future!

On Fri, Mar 31, 2017 at 5:07 PM, Andras Lasso <[hidden email]> wrote:

I don’t think you can transfer the ownership of a numpy array (that was allocated by numpy) to a vtkImageData object. Instead, allocate the voxel data using vtkImageData::AllocateScalars and fill that buffer using numpy.

 

I rarely use numpy for image processing, so others may have better suggestions.

 

Andras

 

From: [hidden email]
Sent: Friday, March 31, 2017 4:43 PM


To: [hidden email]
Cc: [hidden email]; [hidden email]
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

I would really like to fix the issue using what I have.  By performing this task with a numpy array I have much better control over the final data than I do with the resample scalar volume module.......  Do you have any idea of how I would perform this task correctly?

On Fri, Mar 31, 2017 at 4:40 PM, Andras Lasso <[hidden email]> wrote:

Passing data between numpy and VTK is tricky.

 

It's easier to create a volume that has the desired geometry (0.5 x 0.5 x 5.0 spacing) and it as a reference volume in resample scalar/vector/dwi volume module, with nearest neighbor interpolation.

 

Andras

 

From: [hidden email]
Sent: Friday, March 31, 2017 4:30 PM
To: [hidden email]
Cc: [hidden email]; [hidden email]


Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

I gave up on the vtkImageReslice.  No matter what I tried I could not get it to produce what I want.  Instead I used vtkImageSlab.  I have one last issue that I need some help with:
After I run vtkImageSlab I get a huge dataset where each slice represents the average of the 10 slices around it.   I now want to step through these slices and only keep every 10th slice.  Andras I took your advice and used a numpy array to do it.  I am having a problem with it though
See below:

image = self.outVolume.GetImageData()
vtk_data = image.GetPointData().GetScalars()
numpy_data = vtk.util.numpy_support.vtk_to_numpy(vtk_data)
imageDims = image.GetDimensions()
numpy_data = numpy.reshape(numpy_data, [imageDims[0], imageDims[1], imageDims[2]], 'F')
numpy_data = numpy_data.transpose(2,1,0)
dims = numpy_data.shape
numpy_data = numpy_data[0:dims[0]:10]
numpy_data = numpy_data.transpose(2,1,0)
dimsAfter = numpy_data.shape
numpy_data = numpy.ravel(numpy_data, order='F')
vtk_data = vtk.util.numpy_support.numpy_to_vtk(numpy_data)
img_vtk = vtk.vtkImageData()
img_vtk.SetDimensions(imageDims[0], imageDims[1], dimsAfter[2])
img_vtk.SetSpacing(1.0,1.0,1.0)
img_vtk.SetOrigin(0.0,0.0,0.0)
img_vtk.GetPointData().SetScalars(vtk_data)
self.outVolume.SetSpacing(0.5,0.5,5.0)

#now...when I go to set the image data in the self.outVolume with the line below...slicer crashes and complains Unhandled exception at 0x000007FED34B7213 (vtkCommon-7.1.dll) in SlicerApp-real.exe: 0xC0000005: Access violation reading location 0x0000000046D3B3F6

self.outVolume.SetAndObserveImageData(img_vtk)

#When I run this same code in the python interactor it works fine and there is no access violation but when I run it in my python scripted module it crashes.  Any ideas on how to fix this?  I believe the problem is that slicer cannot access the vtk_data within my module which causes the crash.  How would I fix this?

On Thu, Mar 30, 2017 at 12:15 PM, Andras Lasso <[hidden email]> wrote:

You can average the slices using numpy array manipulation then resample using nearest neighbor interpolator.

 

See Steve’s recent example for image manipulation using numpy:

http://slicer-users.65878.n3.nabble.com/How-to-change-INVALID-label-maps-tp4031996p4032001.html

>>> a = slicer.util.array('Output Volume-label')

>>> a[a== 11400] = 2

Andras

 

 

From: Bert Renolds [mailto:[hidden email]]
Sent: March 30, 2017 12:06
To: Andras Lasso <[hidden email]>
Cc: Steve Pieper <[hidden email]>; SPL Slicer Devel <[hidden email]>


Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

Andrea,

Thanks for the advice.  The issue with your solution is that it does not allow for the collapsing of 10 slices to 1 slice using the mean of every pixel.  Resampling the volume will just perform a linear interpolation instead.  The collapsing of the slices is fundamental for the task I am trying to accomplish.  Unfortunately, I think I must struggle through vtkImageReslice and find the proper parameters.

 

Bert

 

On Thu, Mar 30, 2017 at 11:19 AM, Andras Lasso <[hidden email]> wrote:

vtkImageReslice is the most powerful and hardest-to-use filter that I’ve ever encountered in VTK. I would recommend to avoid using it directly, but use them through Slicer modules instead.

 

For example, you can get what you need by using crop and resample modules:

·         Load any volume => referenceVolume

·         In Volumes module: change the spacing to 0.5 0.5 5.0

·         In Crop Volume: Crop referenceVolume to your inputVolume => this creates a volume that has the same size as inputVolume, but with a spacing of 0.5 0.5 5.0

·         In Resample Scalar/Vector/DWI Volume: resample inputVolume, using referenceVolume as reference volume

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of Bert Renolds
Sent: March 30, 2017 9:22
To: Steve Pieper <
[hidden email]>
Cc: SPL Slicer Devel <
[hidden email]>
Subject: Re: [slicer-devel] vtkimagereslice Issues/Questions

 

2) If I set the image spacing to 0.5, 0.5, 5.0 with a slab slicing of 10 and change the volume node spacing to match I end up with a completely blank volume (i.e. all pixel values 0)

 

So I still have the same issue.....  Anyone else have ideas to resolve me problem??

 

Bert

 

On Wed, Mar 29, 2017 at 5:59 PM, Steve Pieper <[hidden email]> wrote:

Hi Bert - 

 

1) The vtkImageData can't natively represent the image orientation, so we use it only as a pixel container and all the real spacing and orientation is in the IJKToRAS members of the vtkMRMLVolumeNode [1].  You can set these programmatically like you would through the Volumes module GUI.

 

2) what happens if you make the OutputSpacing be .5, .5, 5. ?  This, together with the slab slicing of 10 should give what you want (also changing the volume node spacing to match).

 

3) If the volume node spacing is set correctly then the exported dicom should also be right.

 

4) don't know about that one, but I think in your case setting it to 1, 1, 10 would be the alternative to setting the output spacing directly.

 

HTH,

Steve

 

 

On Wed, Mar 29, 2017 at 5:25 PM, Bert Renolds <[hidden email]> wrote:

Hello all,

I am having some trouble with vtkimagereslice and was hoping everyone could help me.  The task I am trying to accomplish is to take a 3d vtkMRMLScalarVolumeNode (lets call this 3dnode) with a spacing of 0.5 mm, 0.5 mm, 0.5 mm and convert it to a volume with spacing of 0.5 mm, 0.5 mm, 5.0 mm.  In order to do this I want to combine 10 slices to make the 5 mm slab and take the mean pixel value of those 10 slices.  After I do this I want to export the volume as a dicom series.

 

Questions:

1.  In the volume module of slicer my image spacing shows as 0.5 mm, 0.5 mm, 0.5 mm.  But when I get the image data of 3dnode with the function GetImageData() then check the spacing of that image data it says the spacing is 1.0, 1.0, 1.0.  My first question is why would my image data report a different spacing than the 3dnode image spacing?

 

2.

vimage = 3dnode.GetImageData()

reslice = vtk.vtkImageReslice()

reslice.SetSlabModeToMean()

reslice.SetInputData(vimage)

reslice.SetSlabNumberOfSlices(10)

reslice.SetResliceAxesDirectionCosines(1,0,0,0,1,0,0,0,1)

reslice.SetOutputSpacing(0.5,0.5,0.5)

reslice.Update()

vimageOut = reslice.GetOutput()

3dnode.SetAndObserveImageData(vimageOut)

 

The code above effectively gives me the image series I want.  The problem is that the 3dnode still maintains its imaging spacing as 0.5 mm, 0.5 mm, 0.5 mm.  This means that when I go to export to DICOM I get 0.5 mm slices instead of 5 mm slices.  If I use the volume module to change the 3dnode image spacing then it makes my slices 100 mm apart and the location of slices gets all messed up.  How would I fix this?

 

3.  I know I can control the viewing of the dataset by grabbing the sliceNode and using SetSliceSpacingModeToPrescribed() then SetPrescribedSliceSpacing(0.5, 0.5, 5.0).  How do I ensure that when I export my 3dnode as a DICOM that I get 5.0 mm slices?

 

4.  When would I use the function SetSlabModeSpacingFraction(double)?  I am having trouble understanding what this method is used for......

 

Hope I have explained everything.  Thanks ahead of time for any help provided.

 

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

 

 

 





_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ