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
{
typename ImageType::Pointer working_image;
working_image = Labelize<ImageType>(input, BG, isFullyConnected, minimalComponentSize);
- working_image = RemoveLabels<ImageType>(working_image, BG, param->GetLabelsToRemove());
+ if (param->GetLabelsToRemove().size() != 0)
+ working_image = RemoveLabels<ImageType>(working_image, BG, param->GetLabelsToRemove());
working_image = KeepLabels<ImageType>(working_image,
BG, FG,
param->GetFirstKeep(),
std::string orientation,
bool uniqueConnectedComponent,
double spacing,
- bool inverseflag)
+ bool autocropFlag,
+ bool singleObjectCCL)
{
typedef SliceBySliceRelativePositionFilter<MaskImageType> SliceRelPosFilterType;
typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New();
sliceRelPosFilter->SetIntermediateSpacingFlag((spacing != -1));
sliceRelPosFilter->SetIntermediateSpacing(spacing);
sliceRelPosFilter->SetUniqueConnectedComponentBySlice(uniqueConnectedComponent);
- sliceRelPosFilter->SetInverseOrientationFlag(inverseflag);
- // sliceRelPosFilter->SetAutoCropFlag(true); ??
+ sliceRelPosFilter->SetUseASingleObjectConnectedComponentBySliceFlag(singleObjectCCL);
+ // sliceRelPosFilter->SetInverseOrientationFlag(inverseflag);
+ sliceRelPosFilter->SetAutoCropFlag(autocropFlag);
+ sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
sliceRelPosFilter->Update();
return sliceRelPosFilter->GetOutput();
}
/*
loop over input pixels, store the index in the fg that is max
according to the given direction.
- */
+ */
typedef itk::ImageRegionConstIteratorWithIndex<ImageType> IteratorType;
IteratorType iter(input, input->GetLargestPossibleRegion());
iter.GoToBegin();
//--------------------------------------------------------------------
template<class ImageType>
typename ImageType::Pointer
- CropImageAbove(const ImageType * image,
+ CropImageRemoveGreaterThan(const ImageType * image,
int dim, double min, bool autoCrop,
typename ImageType::PixelType BG)
{
//--------------------------------------------------------------------
template<class ImageType>
typename ImageType::Pointer
- CropImageBelow(const ImageType * image,
+ CropImageRemoveLowerThan(const ImageType * image,
int dim, double max, bool autoCrop,
typename ImageType::PixelType BG)
{
statFilter->Update();
typename LabelMapType::Pointer labelMap = statFilter->GetOutput();
+ centroids.clear();
+ typename ImageType::PointType dummy;
+ centroids.push_back(dummy); // label 0 -> no centroid, use dummy point for BG
+ //DS FIXME (not useful ! to change ..)
+ DD(labelMap->GetNumberOfLabelObjects());
+ for(uint i=0; i<labelMap->GetNumberOfLabelObjects(); i++) {
+ int label = labelMap->GetLabels()[i];
+ centroids.push_back(labelMap->GetLabelObject(label)->GetCentroid());
+ }
+ }
+ //--------------------------------------------------------------------
+
+
+ //--------------------------------------------------------------------
+ template<class ImageType>
+ void
+ ComputeCentroids2(const ImageType * image,
+ typename ImageType::PixelType BG,
+ std::vector<typename ImageType::PointType> & centroids)
+ {
+ typedef long LabelType;
+ static const unsigned int Dim = ImageType::ImageDimension;
+ typedef itk::ShapeLabelObject< LabelType, Dim > LabelObjectType;
+ typedef itk::LabelMap< LabelObjectType > LabelMapType;
+ typedef itk::LabelImageToLabelMapFilter<ImageType, LabelMapType> ImageToMapFilterType;
+ typename ImageToMapFilterType::Pointer imageToLabelFilter = ImageToMapFilterType::New();
+ typedef itk::ShapeLabelMapFilter<LabelMapType, ImageType> ShapeFilterType;
+ typename ShapeFilterType::Pointer statFilter = ShapeFilterType::New();
+ imageToLabelFilter->SetBackgroundValue(BG);
+ imageToLabelFilter->SetInput(image);
+ statFilter->SetInput(imageToLabelFilter->GetOutput());
+ statFilter->Update();
+ typename LabelMapType::Pointer labelMap = statFilter->GetOutput();
+
centroids.clear();
typename ImageType::PointType dummy;
centroids.push_back(dummy); // label 0 -> no centroid, use dummy point
for(uint i=1; i<labelMap->GetNumberOfLabelObjects()+1; i++) {
centroids.push_back(labelMap->GetLabelObject(i)->GetCentroid());
}
+
+ for(uint i=1; i<labelMap->GetNumberOfLabelObjects()+1; i++) {
+ DD(labelMap->GetLabelObject(i)->GetBinaryPrincipalAxes());
+ DD(labelMap->GetLabelObject(i)->GetBinaryFlatness());
+ DD(labelMap->GetLabelObject(i)->GetRoundness ());
+
+ // search for the point on the boundary alog PA
+
+ }
+
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
- //--------------------------------------------------------------------
- template<class ImageType>
- typename ImageType::Pointer
- JoinSlices(std::vector<typename itk::Image<typename ImageType::PixelType,
- ImageType::ImageDimension-1>::Pointer > & slices,
- const ImageType * input,
- int direction) {
- typedef typename itk::Image<typename ImageType::PixelType, ImageType::ImageDimension-1> SliceType;
- typedef itk::JoinSeriesImageFilter<SliceType, ImageType> JoinSeriesFilterType;
- typename JoinSeriesFilterType::Pointer joinFilter = JoinSeriesFilterType::New();
- joinFilter->SetOrigin(input->GetOrigin()[direction]);
- joinFilter->SetSpacing(input->GetSpacing()[direction]);
- for(unsigned int i=0; i<slices.size(); i++) {
- joinFilter->PushBackInput(slices[i]);
- }
- joinFilter->Update();
- return joinFilter->GetOutput();
- }
- //--------------------------------------------------------------------
-
-
//--------------------------------------------------------------------
template<class ImageType>
void
//--------------------------------------------------------------------
template<class ImageType>
void
- PointsUtils<ImageType>::Convert2DTo3DList(const MapPoint2DType & map,
+ PointsUtils<ImageType>::Convert2DMapTo3DList(const MapPoint2DType & map,
const ImageType * image,
VectorPoint3DType & list)
{
}
//--------------------------------------------------------------------
+
+ //--------------------------------------------------------------------
+ template<class ImageType>
+ void
+ PointsUtils<ImageType>::Convert2DListTo3DList(const VectorPoint2DType & p2D,
+ int slice,
+ const ImageType * image,
+ VectorPoint3DType & list)
+ {
+ for(uint i=0; i<p2D.size(); i++) {
+ PointType3D p;
+ Convert2DTo3D(p2D[i], image, slice, p);
+ list.push_back(p);
+ }
+ }
+ //--------------------------------------------------------------------
+
+
//--------------------------------------------------------------------
template<class ImageType>
void
Binarize(const ImageType * input,
typename ImageType::PixelType lower,
typename ImageType::PixelType upper,
- typename ImageType::PixelType BG=0,
- typename ImageType::PixelType FG=1)
+ typename ImageType::PixelType BG,
+ typename ImageType::PixelType FG)
{
typedef itk::BinaryThresholdImageFilter<ImageType, ImageType> BinaryThresholdFilterType;
typename BinaryThresholdFilterType::Pointer binarizeFilter = BinaryThresholdFilterType::New();
binarizeFilter->SetInput(input);
+ binarizeFilter->InPlaceOff();
binarizeFilter->SetLowerThreshold(lower);
binarizeFilter->SetUpperThreshold(upper);
binarizeFilter->SetInsideValue(FG);
//--------------------------------------------------------------------
+ //--------------------------------------------------------------------
+ /* Consider an input object, for each slice, find the extrema
+ position according to a given direction and build a line segment
+ passing throught this point in a given direction. Output is a
+ vector of line (from point A to B), for each slice;
+ */
+ template<class ImageType>
+ void
+ SliceBySliceBuildLineSegmentAccordingToExtremaPosition(const ImageType * input,
+ typename ImageType::PixelType BG,
+ int sliceDimension,
+ int extremaDirection,
+ bool extremaOppositeFlag,
+ int lineDirection,
+ double margin,
+ std::vector<typename ImageType::PointType> & A,
+ std::vector<typename ImageType::PointType> & B)
+ {
+ // Type of a slice
+ typedef typename itk::Image<typename ImageType::PixelType, ImageType::ImageDimension-1> SliceType;
+
+ // Build the list of slices
+ std::vector<typename SliceType::Pointer> slices;
+ clitk::ExtractSlices<ImageType>(input, sliceDimension, slices);
+
+ // Build the list of 2D points
+ std::map<int, typename SliceType::PointType> position2D;
+ for(uint i=0; i<slices.size(); i++) {
+ typename SliceType::PointType p;
+ bool found =
+ clitk::FindExtremaPointInAGivenDirection<SliceType>(slices[i], BG,
+ extremaDirection, extremaOppositeFlag, p);
+ if (found) {
+ position2D[i] = p;
+ }
+ }
+
+ // Convert 2D points in slice into 3D points
+ clitk::PointsUtils<ImageType>::Convert2DMapTo3DList(position2D, input, A);
+
+ // Create additional point just right to the previous ones, on the
+ // given lineDirection, in order to create a horizontal/vertical line.
+ for(uint i=0; i<A.size(); i++) {
+ typename ImageType::PointType p = A[i];
+ p[lineDirection] += 10;
+ B.push_back(p);
+ // Margins ?
+ A[i][1] += margin;
+ B[i][1] += margin;
+ }
+
+ }
+ //--------------------------------------------------------------------
+
+
} // end of namespace