Reslice 3d Raw image using vtkImageReslice

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Reslice 3d Raw image using vtkImageReslice



I'm trying to get a 2d slice from a 3d raw image, and I'm viewing the output on a vtkImageViewer2 but I'm getting a blank window.



I'm afraid that i can not make this code shorter because each step in this pipeline is necessary as mentioned here:
example that i followed .



also you need a raw image and its header file FullHead.raw.gz which uses FullHead.mhd as a header file.



Here is my code :


#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include<vtkRenderWindow.h>
#include<vtkRenderWindowInteractor.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkImageReslice.h>
#include <vtkImageData.h>
#include <vtkLookupTable.h>
#include <vtkImageMapToColors.h>
#include <vtkImageViewer2.h>
#include <vtkMatrix4x4.h>
int main(){
vtkSmartPointer<vtkImageData> imagedata =
vtkSmartPointer<vtkImageData>::New();
vtkSmartPointer<vtkRenderWindow> m_renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
std:string file_path = "FullHead.mhd";
vtkSmartPointer<vtkMetaImageReader> m_rawImageReader =
vtkSmartPointer<vtkMetaImageReader>::New();
m_rawImageReader->SetFileName(file_path.c_str());
imagedata = m_rawImageReader->GetOutput();

double * center = imagedata->GetCenter();

static double axialElements[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
vtkMatrix4x4 *resliceAxes = vtkMatrix4x4::New();
resliceAxes->DeepCopy(axialElements);

resliceAxes->SetElement(0, 3, center[0]);
resliceAxes->SetElement(1, 3, center[1]);
resliceAxes->SetElement(2, 3, center[2]);

vtkSmartPointer<vtkImageReslice> imageReslice =
vtkSmartPointer<vtkImageReslice>::New();
imageReslice->SetInputConnection(m_rawImageReader-
>GetOutputPort());
imageReslice->SetOutputDimensionality(2);
imageReslice->SetResliceAxes(resliceAxes);
imageReslice->SetInterpolationModeToLinear();
// Create a greyscale lookup table
vtkSmartPointer<vtkLookupTable> table =
vtkSmartPointer<vtkLookupTable>::New();
table->SetRange(0, 2000); // image intensity range
table->SetValueRange(0.0, 1.0); // from black to
white
table->SetSaturationRange(0.0, 0.0); // no color
saturation
table->SetRampToLinear();
table->Build();

// Map the image through the lookup table
vtkSmartPointer<vtkImageMapToColors> color =
vtkSmartPointer<vtkImageMapToColors>::New();
color->SetLookupTable(table);
color->SetInputConnection(imageReslice-
>GetOutputPort());

vtkSmartPointer<vtkImageViewer2> viewier =
vtkSmartPointer<vtkImageViewer2>::New();
viewier->SetInputData(color->GetOutput());
viewier->SetRenderWindow(m_renderWindow);
viewier->SetupInteractor(m_renderWindow-
>GetInteractor());
viewier->Render();
return 0;
}



It seems that i do not understand this pipeline fully.
So, Dose any body know how to this properly?





If you want us to debug your code, then please provide a minimal, complete and verifiable example. The code you provided does not compile without modifications.
– normanius
Jul 27 at 1:51





Thanks for your reply, I'll try to edit my question.
– Sameer Ahmad
Jul 27 at 5:41






1 Answer
1



Before using color->GetOutput() you have to update the Pipeline at least once. VTk uses demand driven pipelines and will only update the parts necessary.
So try color->update() before creating the view. Without update the output of your ImageMapToColors filter is empty.


color->GetOutput()


color->update()






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Better method to check all objects' parameters with a single call