Authors belong to:
- University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
+ - Léon Bérard cancer center http://www.centreleonberard.fr
- CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
This software is distributed WITHOUT ANY WARRANTY; without even
- BSD See included LICENSE.txt file
- CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
- ======================================================================-====*/
+ ===========================================================================**/
#ifndef CLITKCROPLIKEIMAGEFILTER_TXX
#define CLITKCROPLIKEIMAGEFILTER_TXX
// clitk
#include "clitkCommon.h"
-
-// itk
-#include "itkPasteImageFilter.h"
+#include "clitkPasteImageFilter.h"
//--------------------------------------------------------------------
template <class ImageType>
this->SetNumberOfRequiredInputs(1);
m_LikeImage = NULL;
m_LikeFilenameIsGiven = false;
- this->SetBackgroundValue(0);
+ this->SetBackgroundValue(typename PixelTraits<typename ImageType::PixelType>::ValueType(0));
m_CropAlongThisDimension.resize(ImageType::ImageDimension);
for(uint i=0; i<ImageType::ImageDimension; i++)
m_CropAlongThisDimension[i] = true;
template <class ImageType>
void
clitk::CropLikeImageFilter<ImageType>::
-GenerateOutputInformation() {
- DD("GenerateOutputInformation");
+GenerateOutputInformation() {
// Get input pointers
ImageConstPointer input = dynamic_cast<const ImageType*>(itk::ProcessObject::GetInput(0));
likeStart = m_LikeImage->GetLargestPossibleRegion().GetIndex();
likeOrigin = m_LikeImage->GetOrigin();
likeSpacing = m_LikeImage->GetSpacing();
+ output->CopyInformation(m_LikeImage);
}
else {
// Only load the header (allows to use 'like' with any image type)
for(unsigned int i=0; i<ImageType::ImageDimension; i++) {
if (likeSpacing[i] != input->GetSpacing()[i]) {
clitkExceptionMacro("Images must have the same spacing, but input's spacing(" << i
- <<") is " << input->GetSpacing()[i] << " while like's spacing(" << i
- << ") is " << likeSpacing[i] << ".");
+ <<") is " << input->GetSpacing()[i] << " while the spacing(" << i
+ << ") of 'like' is " << likeSpacing[i] << ".");
+ }
+ }
+
+ // Check that we must crop along each dimension. If not, we use the
+ // size of the input image
+ for(unsigned int i=0; i<ImageType::ImageDimension; i++) {
+ if (m_CropAlongThisDimension[i] == false) {
+ likeStart[i] = input->GetLargestPossibleRegion().GetIndex()[i];
+ likeSize[i] = input->GetLargestPossibleRegion().GetSize()[i];
}
}
+
// Define output region
m_OutputRegion.SetIndex(likeStart);
m_OutputRegion.SetSize(likeSize);
output->SetBufferedRegion(m_OutputRegion);
output->SetSpacing(likeSpacing);
output->SetOrigin(likeOrigin);
+ output->Allocate(); // Needed ?
// get startpoint source/dest
// for each dim
for(int i=0; i<ImageType::ImageDimension; i++)
s[i] = m_StopSourceIndex[i]-m_StartSourceIndex[i];
m_Region.SetSize(s);
+
}
//--------------------------------------------------------------------
// Get output pointer, fill with Background
ImagePointer output = this->GetOutput(0);
- output->Allocate();
+
output->FillBuffer(GetBackgroundValue());
// Paste image inside
- typedef itk::PasteImageFilter<ImageType,ImageType> PasteFilterType;
+ typedef clitk::PasteImageFilter<ImageType,ImageType> PasteFilterType;
typename PasteFilterType::Pointer pasteFilter = PasteFilterType::New();
+ //pasteFilter->ReleaseDataFlagOn(); // change nothing ?
+ // pasteFilter->InPlaceOn(); // makt it seg fault
pasteFilter->SetSourceImage(input);
pasteFilter->SetDestinationImage(output);
pasteFilter->SetDestinationIndex(m_StartDestIndex);
pasteFilter->Update();
// Get (graft) output (SetNthOutput does not fit here because of Origin).
- // this->GraftOutput(cropFilter->GetOutput());
this->GraftOutput(pasteFilter->GetOutput());
}
//--------------------------------------------------------------------
-
-#endif //#define CLITKAUTOCROPFILTER
+
+//--------------------------------------------------------------------
+template<class ImageType>
+typename ImageType::Pointer
+clitk::ResizeImageLike(const ImageType * input,
+ const itk::ImageBase<ImageType::ImageDimension> * like,
+ typename ImageType::PixelType backgroundValue)
+{
+ typedef clitk::CropLikeImageFilter<ImageType> CropFilterType;
+ typename CropFilterType::Pointer cropFilter = CropFilterType::New();
+ cropFilter->SetInput(input);
+ cropFilter->SetCropLikeImage(like);
+ cropFilter->SetBackgroundValue(backgroundValue);
+ cropFilter->Update();
+ return cropFilter->GetOutput();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class ImageType>
+typename ImageType::Pointer
+clitk::ResizeImageLike(const ImageType * input,
+ typename itk::ImageBase<ImageType::ImageDimension>::RegionType * region,
+ typename ImageType::PixelType backgroundValue)
+{
+ typename ImageType::Pointer output = ImageType::New();
+ output->CopyInformation(input);
+ typename ImageType::RegionType reg;
+ reg.SetIndex(region->GetIndex());
+ reg.SetSize(region->GetSize());
+ output->SetRegions(reg);
+ output->Allocate();
+ return clitk::ResizeImageLike<ImageType>(input, output, backgroundValue);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class ImageType>
+typename ImageType::Pointer
+clitk::ResizeImageLike(const ImageType * input,
+ typename itk::BoundingBox<unsigned long, ImageType::ImageDimension>::Pointer bb,
+ typename ImageType::PixelType BG)
+{
+ typename ImageType::RegionType region;
+ clitk::ComputeRegionFromBB<ImageType>(input, bb, region);
+ typename ImageType::Pointer output = ImageType::New();
+ output->CopyInformation(input);
+ output->SetRegions(region);
+ output->Allocate();
+ return clitk::ResizeImageLike<ImageType>(input, output, BG);
+}
+//--------------------------------------------------------------------
+
+#endif //#define CLITKCROPLIKEIMAGEFILTER_TXX