#include "itkOrientImageFilter.h"
#include "itkSpatialOrientationAdapter.h"
#include "itkImageDuplicator.h"
+#include "itkRelabelComponentImageFilter.h"
+
#include <fcntl.h>
//--------------------------------------------------------------------
SetForegroundValue(1);
SetMinimalComponentSize(100);
VerboseRegionGrowingFlagOff();
+ RemoveSmallLabelBeforeSeparationFlagOn();
// Step 1 default values
SetUpperThreshold(-300);
StartNewStep("Search for the trachea");
SearchForTrachea();
PrintMemory(GetVerboseMemoryFlag(), "After SearchForTrachea");
+ if (m_Seeds.empty()) {
+ clitkExceptionMacro("No seeds for trachea... Aborting.");
+ }
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//--------------------------------------------------------------------
StartNewStep("Separate Left/Right lungs");
- PrintMemory(GetVerboseMemoryFlag(), "Before Separate");
+ PrintMemory(GetVerboseMemoryFlag(), "Before Separate");
// Initial label
working_mask = Labelize<MaskImageType>(working_mask,
GetBackgroundValue(),
statisticsImageFilter->SetInput(working_mask);
statisticsImageFilter->Update();
unsigned int initialNumberOfLabels = statisticsImageFilter->GetMaximum();
- working_mask = statisticsImageFilter->GetOutput();
-
+ working_mask = statisticsImageFilter->GetOutput();
PrintMemory(GetVerboseMemoryFlag(), "After count label");
+
+ // If already 2 labels, but a too big differences, remove the
+ // smalest one (sometimes appends with the stomach
+ if (initialNumberOfLabels >1) {
+ if (GetRemoveSmallLabelBeforeSeparationFlag()) {
+ DD(GetRemoveSmallLabelBeforeSeparationFlag());
+ typedef itk::RelabelComponentImageFilter<MaskImageType, MaskImageType> RelabelFilterType;
+ typename RelabelFilterType::Pointer relabelFilter = RelabelFilterType::New();
+ relabelFilter->SetInput(working_mask);
+ relabelFilter->SetMinimumObjectSize(10);
+ relabelFilter->Update();
+ const std::vector<float> & a = relabelFilter->GetSizeOfObjectsInPhysicalUnits();
+ std::vector<MaskImagePixelType> remove_label;
+ for(unsigned int i=1; i<a.size(); i++) {
+ if (a[i] < 0.5*a[0]) { // more than 0.5 difference
+ remove_label.push_back(i+1); // label zero is BG
+ }
+ }
+ working_mask =
+ clitk::RemoveLabels<MaskImageType>(working_mask, GetBackgroundValue(), remove_label);
+ statisticsImageFilter->SetInput(working_mask);
+ statisticsImageFilter->Update();
+ initialNumberOfLabels = statisticsImageFilter->GetMaximum();
+ }
+ }
// Decompose the first label
if (initialNumberOfLabels<2) {
opening->Update();
typename SlicerFilterType::Pointer slicer = SlicerFilterType::New();
+#if ITK_VERSION_MAJOR >= 4
+ slicer->SetDirectionCollapseToIdentity();
+#endif
slicer->SetInput(opening->GetOutput());
// label result
writer->Update();
}
- typename LabelImageType::LabelObjectContainerType shapes_map = label_map->GetLabelObjectContainer();
- typename LabelImageType::LabelObjectContainerType::const_iterator s;
typename ShapeLabelType::Pointer shape, max_e_shape;
double max_elongation = GetMaxElongation();
double max_size = size[0]*size[1]/128;
double max_e = 0;
int nshapes = 0;
- for (s = shapes_map.begin(); s != shapes_map.end(); s++) {
- shape = s->second;
- if (shape->GetSize() > 150 && shape->GetSize() <= max_size) {
+ unsigned int nlables = label_map->GetNumberOfLabelObjects();
+ for (unsigned int j = 0; j < nlables; j++) {
+ shape = label_map->GetNthLabelObject(j);
+ if (shape->Size() > 150 && shape->Size() <= max_size) {
+#if ITK_VERSION_MAJOR < 4
double e = 1 - 1/shape->GetBinaryElongation();
+#else
+ double e = 1 - 1/shape->GetElongation();
+#endif
//double area = 1 - r->Area() ;
if (e < max_elongation) {
nshapes++;
prev_e_centre= max_e_centre;
}
+ else {
+ if (GetVerboseRegionGrowingFlag()) {
+ cout << "No shapes found at slice " << index[2] << std::endl;
+ }
+ }
}
size_t longest = 0;
}
}
- if (GetVerboseRegionGrowingFlag())
- std::cout << "seed at: " << trachea_centre << std::endl;
- m_Seeds.push_back(trachea_centre);
+ if (longest > 0) {
+ if (GetVerboseRegionGrowingFlag())
+ std::cout << "seed at: " << trachea_centre << std::endl;
+ m_Seeds.push_back(trachea_centre);
+ }
}
return (m_Seeds.size() != 0);
f->SetUpper(GetUpperThresholdForTrachea());
f->SetMinimumLowerThreshold(-2000);
// f->SetMaximumUpperThreshold(0); // MAYBE TO CHANGE ???
- f->SetMaximumUpperThreshold(-700); // MAYBE TO CHANGE ???
+ f->SetMaximumUpperThreshold(-300); // MAYBE TO CHANGE ???
f->SetAdaptLowerBorder(false);
f->SetAdaptUpperBorder(true);
f->SetMinimumSize(5000);
std::cout << "\t Found trachea with volume " << volume << " cc." << std::endl;
}
}
- else {
- if (GetVerboseStepFlag()) {
- std::cout << "\t The volume of the trachea (" << volume
- << " cc) seems not correct. I skip some slices (" << skip << ") and restart to find seeds."
- << std::endl;
- }
- skip += 5;
- stop = false;
- // empty the list of seed
- m_Seeds.clear();
+ else
+ if (GetTracheaSeedAlgorithm() == 0) {
+ if (GetVerboseStepFlag()) {
+ std::cout << "\t The volume of the trachea (" << volume
+ << " cc) seems not correct. I skip some slices (" << skip << ") and restart to find seeds."
+ << std::endl;
+ }
+ skip += 5;
+ stop = false;
+ // empty the list of seed
+ m_Seeds.clear();
}
if (skip > 0.5 * working_input->GetLargestPossibleRegion().GetSize()[2]) {
// we want to skip more than a half of the image, it is probably a bug