<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi JongWon,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">welcome to ITK! To reproduce your problem we will need the input file too. If it crashes with different input files, please provide the smallest one. Also, we have migrated to the <a href="https://discourse.itk.org/">forum</a>, so please post the updated question there.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Regards,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Dženan</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 3, 2018 at 11:30 AM wonnybro <<a href="mailto:kjwjj627@gmail.com">kjwjj627@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, ITK users<br>
<br>
I really really need your help, please help me...<br>
I am trying to do BSpline interpolation of DVFs obtained by image<br>
registrations of 10 images. <br>
I'm trying to modify the BSplineScatteredDataPointSetToImageFilter from the<br>
Insight Journal. However,<br>
I am having trouble to find the correct parameter in order to make the<br>
filter work. <br>
I'll have scattered 3-D points of several DVFs over time and I want to fit<br>
these DVFs by a 4-D Bspline. Afterwards I want to evaluate output DVF to one<br>
time step.<br>
<br>
Here you can find the code, unfortunately it crashes.<br>
<br>
Please help me...please.<br>
<br>
Thanks in advance.<br>
<br>
#include "itkBSplineScatteredDataPointSetToImageFilter.h"<br>
#include "itkPointSet.h"<br>
#include "itkImage.h"<br>
#include "itkVectorImage.h"<br>
#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>
<br>
int main (int argc, char* argv[])<br>
{<br>
const unsigned int ImageDimension = 3;<br>
<br>
using VectorType = itk::Vector<float, ImageDimension>;<br>
using InputImageType = itk::Image<VectorType, ImageDimension>;<br>
using InputPointType = InputImageType::PointType;<br>
using OutputImageType = itk::Image<VectorType, ImageDimension + 1>;<br>
using PointSetType = itk::PointSet<VectorType, ImageDimension + 1>;<br>
using OutputPointType = PointSetType::PointType;<br>
using ReaderType = itk::ImageFileReader<InputImageType>;<br>
using WriterType = itk::ImageFileWriter<OutputImageType>;<br>
<br>
PointSetType::Pointer pointSet = PointSetType::New();<br>
unsigned long pointId = 0;<br>
InputImageType::PointType origin;<br>
InputImageType::SpacingType spacing;<br>
InputImageType::SizeType size;<br>
for (int i = 1; i < argc; ++i)<br>
{<br>
ReaderType::Pointer reader = ReaderType::New();<br>
std::cout << "Reading file " << argv[i] << std::endl;<br>
reader->SetFileName(argv[i]);<br>
try<br>
{<br>
reader->Update();<br>
}<br>
catch (itk::ExceptionObject & err)<br>
{<br>
std::cout << "ExceptionObject caught !" << std::endl;<br>
std::cout << err << std::endl;<br>
return EXIT_FAILURE;<br>
}<br>
using IteratorType = itk::ImageRegionConstIterator<InputImageType>;<br>
const InputImageType * image = reader->GetOutput();<br>
IteratorType it(image, image->GetBufferedRegion());<br>
it.GoToBegin();<br>
InputPointType inPoint;<br>
OutputPointType outPoint;<br>
int iCount = 0;<br>
while (!it.IsAtEnd())<br>
{<br>
inPoint = image->GetPixel(it.GetIndex());<br>
for (int j = 0; j < ImageDimension; ++j)<br>
outPoint[j] = inPoint[i];<br>
outPoint[ImageDimension] = i - 1;<br>
pointSet->SetPoint(pointId, outPoint);<br>
// Transfer the pixel data to the value associated with the point.<br>
pointSet->SetPointData(pointId, it.Get());<br>
++it;<br>
++pointId;<br>
++iCount;<br>
}<br>
std::cout << "Number of points in " << argv[i] << " = " << iCount <<<br>
std::endl;<br>
std::cout << "Total number of points = " <<<br>
pointSet->GetNumberOfPoints() << std::endl;<br>
origin = image->GetOrigin();<br>
spacing = image->GetSpacing();<br>
size = image->GetLargestPossibleRegion().GetSize();<br>
}<br>
<br>
typedef itk::BSplineScatteredDataPointSetToImageFilter < PointSetType,<br>
OutputImageType > SplineFilterType;<br>
SplineFilterType::Pointer splineFilter = SplineFilterType::New();<br>
<br>
int splineorder=3; // complexity of the spline<br>
<br>
SplineFilterType::ArrayType ncontrol;<br>
ncontrol[0]=splineorder + 1;<br>
SplineFilterType::ArrayType closedim;<br>
closedim[0]= 0;<br>
<br>
OutputImageType::PointType parametricDomainOrigin;<br>
OutputImageType::SpacingType parametricDomainSpacing;<br>
OutputImageType::SizeType parametricDomainSize;<br>
for (int i = 0; i < ImageDimension; ++i)<br>
{<br>
parametricDomainOrigin[i] = origin[i];<br>
parametricDomainSpacing[i] = spacing[i];<br>
parametricDomainSize[i] = size[i];<br>
}<br>
parametricDomainOrigin[ImageDimension] = 0;<br>
parametricDomainSize[ImageDimension] = argc - 2;<br>
parametricDomainSpacing[ImageDimension] = 10.0;<br>
<br>
splineFilter->SetGenerateOutputImage( true ); // the only reason to turn<br>
this off is if one only wants to use the control point lattice for further<br>
processing<br>
splineFilter->SetInput ( pointSet );<br>
splineFilter->SetSplineOrder ( splineorder );<br>
splineFilter->SetNumberOfControlPoints ( ncontrol );<br>
splineFilter->SetNumberOfLevels( 3 );<br>
splineFilter->SetCloseDimension ( closedim );<br>
splineFilter->SetSize( parametricDomainSize );<br>
splineFilter->SetSpacing( parametricDomainSpacing );<br>
splineFilter->SetOrigin( parametricDomainOrigin );<br>
std::cout << "Before update spline filter" << std::endl;<br>
splineFilter->Update();<br>
std::cout << "After update spline filter" << std::endl;<br>
<br>
WriterType::Pointer writer = WriterType::New();<br>
writer->SetInput(splineFilter->GetOutput());<br>
writer->SetFileName("Output.mhd");<br>
writer->Update();<br>
std::cout << "After write image filter" << std::endl;<br>
<br>
return EXIT_SUCCESS;<br>
};<br>
<br>
<br>
<br>
--<br>
Sent from: <a href="http://itk-users.7.n7.nabble.com/" rel="noreferrer" target="_blank">http://itk-users.7.n7.nabble.com/</a><br>
The ITK community is transitioning from this mailing list to <a href="http://discourse.itk.org" rel="noreferrer" target="_blank">discourse.itk.org</a>. Please join us there!<br>
________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://itk.org/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">https://itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div>