X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkAddRelativePositionConstraintToLabelImageFilter.txx;h=1e06168877a91929bf2ed06444e4e4da9d06735e;hb=c743d3bed0d7d619740eea35430770265c4a1b9b;hp=5e7011ad37f861ef900a7ecf6d083378f657261f;hpb=38786c4da19b87319bbe3cecc145e3d1771d10da;p=clitk.git diff --git a/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx b/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx index 5e7011a..1e06168 100644 --- a/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx +++ b/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx @@ -173,7 +173,7 @@ GenerateData() //-------------------------------------------------------------------- //-------------------------------------------------------------------- static const unsigned int dim = ImageType::ImageDimension; - StartNewStep("Initial resample and pad"); + StartNewStep("Initial resample"); // Step 1 : resample if (m_ResampleBeforeRelativePositionFilter) { typedef clitk::ResampleImageWithOptionsFilter ResampleFilterType; @@ -181,36 +181,55 @@ GenerateData() resampleFilter->SetInput(object); resampleFilter->SetOutputIsoSpacing(m_IntermediateSpacing); resampleFilter->SetGaussianFilteringEnabled(false); - // resampleFilter->SetVerboseOptions(true); + // resampleFilter->SetVerboseOptions(true); resampleFilter->Update(); working_image = resampleFilter->GetOutput(); } else { working_image = object; } + StopCurrentStep(working_image); // Step 2: object pad to input image -> we want to compute the // relative position for each point belonging to the input image // domain, so we have to extend (pad) the object image to fit the // domain size if (!clitk::HaveSameSizeAndSpacing(input, working_image)) { + StartNewStep("Pad object to image size"); typename ImageType::Pointer output = ImageType::New(); SizeType size; for(unsigned int i=0; iGetLargestPossibleRegion().GetSize()[i]*input->GetSpacing()[i])/(double)working_image->GetSpacing()[i]); } + + // The index of the input is not necessarily zero, so we have to + // take it into account (not done) RegionType region; + IndexType index = input->GetLargestPossibleRegion().GetIndex(); region.SetSize(size); + for(unsigned int i=0; iSetLargestPossibleRegion(region); output->SetRegions(region); - output->SetSpacing(working_image->GetSpacing()); - output->SetOrigin(input->GetOrigin()); + output->SetSpacing(working_image->GetSpacing()); + PointType origin = input->GetOrigin(); + for(unsigned int i=0; iGetSpacing()[i] + input->GetOrigin()[i]; + } + output->SetOrigin(origin); + // output->SetOrigin(input->GetOrigin()); + output->Allocate(); output->FillBuffer(m_BackgroundValue); typename PadFilterType::Pointer padFilter = PadFilterType::New(); - typename PadFilterType::InputImageIndexType index; + // typename PadFilterType::InputImageIndexType index; for(unsigned int i=0; iGetOrigin()[i] - input->GetOrigin()[i])/working_image->GetSpacing()[i]); + index[i] = -index[i]*input->GetSpacing()[i]/(double)working_image->GetSpacing()[i] + + lrint((working_image->GetOrigin()[i] - input->GetOrigin()[i])/working_image->GetSpacing()[i]); } padFilter->SetSourceImage(working_image); padFilter->SetDestinationImage(output); @@ -218,13 +237,14 @@ GenerateData() padFilter->SetSourceRegion(working_image->GetLargestPossibleRegion()); padFilter->Update(); working_image = padFilter->GetOutput(); + StopCurrentStep(working_image); } else { // DD("[debug] RelPos : same size and spacing : no padding"); } // Keep object image (with resampline and pad) object_resampled = working_image; - StopCurrentStep(working_image); + // StopCurrentStep(working_image); // Step 3: compute rel pos in object StartNewStep("Relative Position Map"); @@ -300,8 +320,8 @@ GenerateData() temp->CopyInformation(input); temp->SetRegions(input->GetLargestPossibleRegion()); // Do not forget !! temp->Allocate(); - temp->FillBuffer(m_BackgroundValue); - typename PadFilterType::Pointer padFilter2 = PadFilterType::New(); // if yes : redo relpos + temp->FillBuffer(m_BackgroundValue); + typename PadFilterType::Pointer padFilter2 = PadFilterType::New(); padFilter2->SetSourceImage(working_image); padFilter2->SetDestinationImage(temp); padFilter2->SetDestinationIndex(input->GetLargestPossibleRegion().GetIndex()); @@ -320,8 +340,6 @@ GenerateData() StartNewStep("Combine with initial input (boolean And)"); typedef clitk::BooleanOperatorLabelImageFilter BoolFilterType; typename BoolFilterType::Pointer combineFilter = BoolFilterType::New(); - writeImage(input, "i.mhd"); - writeImage(working_image, "w.mhd"); combineFilter->SetBackgroundValue(m_BackgroundValue); combineFilter->SetBackgroundValue1(m_BackgroundValue); combineFilter->SetBackgroundValue2(m_BackgroundValue); @@ -332,7 +350,6 @@ GenerateData() combineFilter->InPlaceOn(); combineFilter->Update(); working_image = combineFilter->GetOutput(); - // writeImage(working_image, "res.mhd"); combineFilter = BoolFilterType::New(); combineFilter->SetInput1(working_image);