/*=========================================================================
Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Authors belong to:
+ Authors belong to:
- University of LYON http://www.universite-lyon.fr/
- Léon Bérard cancer center http://www.centreleonberard.fr
- CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
#include "itkBinaryMorphologicalOpeningImageFilter.h"
#include "itkBinaryBallStructuringElement.h"
#include "itkCastImageFilter.h"
+#include "itkConstantPadImageFilter.h"
//--------------------------------------------------------------------
template <class TInputImageType>
SetRadius2(r);
SetMaximumNumberOfLabels2(2);
SetNumberOfNewLabels2(1);
-
+
// Step 5: Only keep label corresponding (Keep patient's labels)
SetFirstKeep(1);
SetLastKeep(1);
-
+
// Step 4: OpenClose (option)
FinalOpenCloseOff();
AutoCropOn();
//--------------------------------------------------------------------
template <class TInputImageType>
-void
+void
clitk::ExtractPatientFilter<TInputImageType>::
-SetInput(const TInputImageType * image)
+SetInput(const TInputImageType * image)
{
this->SetNthInput(0, const_cast<TInputImageType *>(image));
}
//--------------------------------------------------------------------
template <class TInputImageType>
-void
+void
clitk::ExtractPatientFilter<TInputImageType>::
-GenerateOutputInformation() {
+GenerateOutputInformation() {
clitk::PrintMemory(GetVerboseMemoryFlag(), "Initial memory"); // OK
// Get input pointers
static const unsigned int Dim = InputImageType::ImageDimension;
//input = dynamic_cast<const TInputImageType*>(itk::ProcessObject::GetInput(0));
-
+
//--------------------------------------------------------------------
//--------------------------------------------------------------------
- // Step 1:
+ // Step 1:
StartNewStep("Find low densities areas");
- typedef itk::BinaryThresholdImageFilter<InputImageType, InternalImageType> BinarizeFilterType;
+
+ // Pad images with air to prevent patient touching the image border
+ typedef itk::ConstantPadImageFilter<InputImageType, InputImageType> PadFilterType;
+ typename PadFilterType::Pointer padFilter = PadFilterType::New();
+ padFilter->SetInput(input);
+ padFilter->SetConstant(GetUpperThreshold() - 1);
+ typename InputImageType::SizeType bounds;
+ for (unsigned i = 0; i < Dim - 1; ++i)
+ bounds[i] = 1;
+ bounds[Dim - 1] = 0;
+ padFilter->SetPadLowerBound(bounds);
+ padFilter->SetPadUpperBound(bounds);
+
+ typedef itk::BinaryThresholdImageFilter<InputImageType, InternalImageType> BinarizeFilterType;
typename BinarizeFilterType::Pointer binarizeFilter=BinarizeFilterType::New();
- binarizeFilter->SetInput(input);
+ binarizeFilter->SetInput(padFilter->GetOutput());
if (m_UseLowerThreshold) binarizeFilter->SetLowerThreshold(GetLowerThreshold());
binarizeFilter->SetUpperThreshold(GetUpperThreshold());
binarizeFilter ->SetInsideValue(this->GetForegroundValue());
connectFilter->SetInput(binarizeFilter->GetOutput());
connectFilter->SetBackgroundValue(this->GetBackgroundValue());
connectFilter->SetFullyConnected(false);
-
+
// Sort labels according to size
typedef itk::RelabelComponentImageFilter<InternalImageType, InternalImageType> RelabelFilterType;
typename RelabelFilterType::Pointer relabelFilter=RelabelFilterType::New();
relabelFilter->SetInput(connectFilter->GetOutput());
relabelFilter->Update();
working_image = relabelFilter->GetOutput();
-
+
// End
StopCurrentStep<InternalImageType>(working_image);
//--------------------------------------------------------------------
//--------------------------------------------------------------------
- // [Optional]
+ // [Optional]
if (GetDecomposeAndReconstructDuringFirstStep()) {
StartNewStep("First Decompose & Reconstruct step");
typedef clitk::DecomposeAndReconstructImageFilter<InternalImageType,InternalImageType> FilterType;
working_image = f->GetOutput();
StopCurrentStep<InternalImageType>(working_image);
}
-
+
//--------------------------------------------------------------------
//--------------------------------------------------------------------
StartNewStep("Remove the air (largest area)");
- typedef itk::BinaryThresholdImageFilter<InternalImageType, InternalImageType> iBinarizeFilterType;
+ typedef itk::BinaryThresholdImageFilter<InternalImageType, InternalImageType> iBinarizeFilterType;
typename iBinarizeFilterType::Pointer binarizeFilter2 = iBinarizeFilterType::New();
binarizeFilter2->SetInput(working_image);
binarizeFilter2->SetLowerThreshold(GetFirstKeep());
relabelFilter2->SetInput(connectFilter2->GetOutput());
relabelFilter2->Update();
working_image = relabelFilter2->GetOutput();
-
+
// Keep main label
working_image = KeepLabels<InternalImageType>
- (working_image, GetBackgroundValue(), GetForegroundValue(), 1, 1, true);
+ (working_image, GetBackgroundValue(), GetForegroundValue(), 1, 1, true);
StopCurrentStep<InternalImageType>(working_image);
//--------------------------------------------------------------------
//--------------------------------------------------------------------
- // [Optional]
+ // [Optional]
if (GetDecomposeAndReconstructDuringSecondStep()) {
StartNewStep("Second Decompose & Reconstruct step");
typedef clitk::DecomposeAndReconstructImageFilter<InternalImageType,InternalImageType> FilterType;
openFilter->SetInput(working_image);
openFilter->SetBackgroundValue(this->GetBackgroundValue());
openFilter->SetForegroundValue(this->GetForegroundValue());
- openFilter->SetKernel(structuringElement);
+ openFilter->SetKernel(structuringElement);
// Close
typedef itk::BinaryMorphologicalClosingImageFilter<InternalImageType, InternalImageType , KernelType> CloseFilterType;
typename CloseFilterType::Pointer closeFilter = CloseFilterType::New();
closeFilter->SetForegroundValue(this->GetForegroundValue());
// closeFilter->SetBackgroundValue(SetBackgroundValue());
closeFilter->SetKernel(structuringElement);
- closeFilter->Update();
+ closeFilter->Update();
working_image = closeFilter->GetOutput();
StopCurrentStep<InternalImageType>(working_image);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
- // Final Cast
+ // Final Cast
typedef itk::CastImageFilter<InternalImageType, MaskImageType> CastImageFilterType;
typename CastImageFilterType::Pointer caster= CastImageFilterType::New();
caster->SetInput(working_image);
typename CropFilterType::Pointer cropFilter = CropFilterType::New();
cropFilter->SetInput(output);
cropFilter->SetBackgroundValue(GetBackgroundValue());
- cropFilter->Update();
+ cropFilter->Update();
output = cropFilter->GetOutput();
StopCurrentStep<MaskImageType>(output);
}
+ else
+ {
+ // Remove Padding region
+ typedef itk::CropImageFilter<MaskImageType, MaskImageType> CropFilterType;
+ typename CropFilterType::Pointer cropFilter = CropFilterType::New();
+ cropFilter->SetInput(output);
+ cropFilter->SetLowerBoundaryCropSize(bounds);
+ cropFilter->SetUpperBoundaryCropSize(bounds);
+ cropFilter->Update();
+ output = cropFilter->GetOutput();
+ }
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
template <class TInputImageType>
-void
+void
clitk::ExtractPatientFilter<TInputImageType>::
GenerateData() {
// Final Graft
this->GraftOutput(output);
// Store image filename into AFDB
- GetAFDB()->SetImageFilename("Patient", this->GetOutputPatientFilename());
+ GetAFDB()->SetImageFilename("Patient", this->GetOutputPatientFilename());
WriteAFDB();
}
//--------------------------------------------------------------------
-
+
#endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX
clipper->SetInput(mHiddenImage->GetVTKImages()[0]);
else
clipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
+
squares->SetInput(clipper->GetOutput());
squaresMapper->SetInput(squares->GetOutput());
squaresMapper->ScalarVisibilityOff();
clipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2],
extent2[3],extent2[4],extent2[5]);
- //std::cout << mTSlice << " " << mSlice << " " << extent2[0] << " " << extent2[1] << " " << extent2[2] << " " << extent2[3] << " " << extent2[4] << " " << extent2[5] << std::endl;
-
if (mHiddenImageIsUsed) delete extent2;
// Move the actor to be visible
position[orientation] = -1;
actor->SetPosition(position);
-// switch (orientation) {
-// case 0:
-// actor->SetPosition(-1,0,0);
-// /*
-// // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0]);
-// if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) {
-// actor->SetPosition(1,0,0);
-// } else {
-// actor->SetPosition(-1,0,0);
-// }*/
-// break;
-// case 1:
-// actor->SetPosition(0,-1,0);
-// /*
-// // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1]);
-// if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) {
-// actor->SetPosition(0,1,0);
-// } else {
-// actor->SetPosition(0,-1,0);
-// }
-// */
-// break;
-// case 2:
-// actor->SetPosition(0,0,-1);
-// /*
-// DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2]);
-// if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) {
-// DD("1");
-// actor->SetPosition(0,0,1);
-// } else {
-// DD("-1");
-// actor->SetPosition(0,0,-1);
-// }
-// */
-// break;
-// }
-
mapper->Update();
-
-
-
}
//------------------------------------------------------------------------------