[ITK] [ITK-users] Extract slice from ResampleFilter

sidharta sidharta.gupta93 at gmail.com
Wed Apr 19 09:40:38 EDT 2017


Hi Dženan,

Thank you for your reply. I implemented this, and learned some cool stuff in
3DSlicer (in order to compare the two images) but as you said, the size is
difficult to compute. When I set the origin explicitly, to the start of the
trajectory, the resampled image looks good in the direction I want it to be
in, however, lot of information is lost. After putting my head into it for
the past two weeks, I realized there are other ways to achieve I want this
too. Does it make sense to you that I construct another 2D image (or 3D with
thickness 1) by essentially copying the voxel values at the trajectory
points and around it (probably the size equal to the dimensions of the
original image in the x,y direction)? The aim ultimately is in fact to get
one slice which best represents the HU values. I apologize for asking such
silly questions.

Just putting the code of what I did, let me know if it is in fact what you
suggested me to do:

Vector3d ST, SP, normal_to_plane;
	ST = traj_end - traj_start;
	SP = third_point - traj_start;
	normal_to_plane = ST.cross(SP);
	std::cout << "Vector ST : " << ST << " Vector SP : " << SP << " Direction
of normal : " << normal_to_plane << std::endl;

	InternalImageType::DirectionType dir;
	// vector from start to the end of the trajectory 
	Vector3d normalized_ST = ST.normalized();
	dir[0][0] = normalized_ST[0];
	dir[0][1] = normalized_ST[1];
	dir[0][2] = normalized_ST[2];

	Vector3d second = normal_to_plane.cross(ST);
	Vector3d normalized_second = second.normalized();
	dir[1][0] = normalized_second[0];
	dir[1][1] = normalized_second[1];
	dir[1][2] = normalized_second[2];

	Vector3d normalized_normal = normal_to_plane.normalized();
	dir[2][0] = normalized_normal[0];
	dir[2][1] = normalized_normal[1];
	dir[2][2] = normalized_normal[2];

	// traj_start += normalized_second * 10;
	double mpr_start[3] = { traj_start[0]  , traj_start[1] , traj_start[2]};

	std::cout << "Previous image direction " << image->GetDirection() <<
std::endl;
	std::cout << "New Image Direction " << dir << std::endl;

	getSliceMPR(image, mpr_start, dir);

void getSliceMPR(InternalImageType::Pointer &image, double
output_origin[Dimension], InternalImageType::DirectionType dir)
{

	// Instantiate Resample Filter here
	ResampleFilterType::Pointer filter = ResampleFilterType::New();
	// Instantiate Transform for resampling
	// Changing the Output direction instead of setting the transform
	// filter->SetTransform(transform);

	typedef itk::NearestNeighborInterpolateImageFunction<
		InternalImageType, double> InterpolatorType;

	// Instantiate the interpolator
	InterpolatorType::Pointer interpolator = InterpolatorType::New();
	filter->SetInterpolator(interpolator);

	// Set pixels of the output image that end up being mapped outside the
extent of the input image to -1500
	filter->SetDefaultPixelValue(-1500);

	// Sampling grid of the output space - pixel spacing in mm
	// Hard coded here
	filter->SetOutputSpacing(image->GetSpacing());


    // filter->SetOutputOrigin(image->GetOrigin());
	
	filter->SetOutputOrigin(output_origin);
	filter->SetOutputDirection(dir);
	InternalImageType::SizeType size;
	filter->SetSize(image->GetLargestPossibleRegion().GetSize());

	filter->SetInput(image);

	typedef itk::ImageFileWriter<InternalImageType> WriterType;
	
	WriterType::Pointer writer = WriterType::New();
	writer->SetFileName("C:/Users/api/Desktop/Resampled/resampled_2.mhd");
	writer->SetUseCompression(true);
	writer->SetInput(filter->GetOutput());
	try{
		writer->Update();

	}
	catch (itk::ExceptionObject & excep){

		std::cerr << "Exception catched!.." << std::endl;
		std::cerr << excep << std::endl;
	}

}



--
View this message in context: http://itk-users.7.n7.nabble.com/Extract-slice-from-ResampleFilter-tp38074p38129.html
Sent from the ITK - 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

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list