From: dsarrut Date: Wed, 7 Jul 2010 07:01:50 +0000 (+0000) Subject: prevent padding if same size/spacing X-Git-Tag: v1.2.0~562 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=0e9612d2827fc3e3ea10a9e8c2e365dd992692ae;p=clitk.git prevent padding if same size/spacing --- diff --git a/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx b/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx index 4078b84..66624a0 100644 --- a/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx +++ b/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx @@ -210,34 +210,39 @@ GenerateData() { // 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 - typename ImageType::Pointer output = ImageType::New(); - SizeType size; - for(unsigned int i=0; iGetLargestPossibleRegion().GetSize()[i]*input->GetSpacing()[i])/(double)working_image->GetSpacing()[i]); + if (!clitk::HaveSameSizeAndSpacing(input, working_image)) { + typename ImageType::Pointer output = ImageType::New(); + SizeType size; + for(unsigned int i=0; iGetLargestPossibleRegion().GetSize()[i]*input->GetSpacing()[i])/(double)working_image->GetSpacing()[i]); + } + RegionType region; + region.SetSize(size); + // output->SetLargestPossibleRegion(region); + output->SetRegions(region); + output->SetSpacing(working_image->GetSpacing()); + output->SetOrigin(input->GetOrigin()); + output->Allocate(); + output->FillBuffer(m_BackgroundValue); + typename PadFilterType::Pointer padFilter = PadFilterType::New(); + typename PadFilterType::InputImageIndexType index; + for(unsigned int i=0; iGetOrigin()[i] - input->GetOrigin()[i])/(double)m_IntermediateSpacing); + } + padFilter->SetSourceImage(working_image); + padFilter->SetDestinationImage(output); + padFilter->SetDestinationIndex(index); + padFilter->SetSourceRegion(working_image->GetLargestPossibleRegion()); + padFilter->Update(); + working_image = padFilter->GetOutput(); } - RegionType region; - region.SetSize(size); - // output->SetLargestPossibleRegion(region); - output->SetRegions(region); - output->SetSpacing(working_image->GetSpacing()); - output->SetOrigin(input->GetOrigin()); - output->Allocate(); - output->FillBuffer(m_BackgroundValue); - typename PadFilterType::Pointer padFilter = PadFilterType::New(); - typename PadFilterType::InputImageIndexType index; - for(unsigned int i=0; iGetOrigin()[i] - input->GetOrigin()[i])/(double)m_IntermediateSpacing); + else { + DD("[debug] RelPos : same size and spacing : no padding"); } - padFilter->SetSourceImage(working_image); - padFilter->SetDestinationImage(output); - padFilter->SetDestinationIndex(index); - padFilter->SetSourceRegion(working_image->GetLargestPossibleRegion()); - padFilter->Update(); - working_image = padFilter->GetOutput(); // Keep object image (with resampline and pad) object_resampled = working_image; - // writeImage(working_image, "pad.mhd"); + // writeImage(working_image, "pad.mhd"); // Step 3: compute rel pos in object typedef itk::RelativePositionPropImageFilter RelPosFilterType; @@ -312,6 +317,9 @@ GenerateData() { padFilter2->Update(); working_image = padFilter2->GetOutput(); } + else { + DD("[debug] Rel Pos : no padding after"); + } // writeImage(working_image, "pad2.mhd"); // Step 6: combine input+thresholded relpos