+ //--------------------------------------------------------------------
+ /* 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;
+ }
+
+ }
+ //--------------------------------------------------------------------
+
+
+ //--------------------------------------------------------------------
+ template<class ImageType>
+ typename ImageType::Pointer
+ SliceBySliceKeepMainCCL(const ImageType * input,
+ typename ImageType::PixelType BG,
+ typename ImageType::PixelType FG) {
+
+ // Extract slices
+ const int d = ImageType::ImageDimension-1;
+ typedef typename itk::Image<typename ImageType::PixelType, d> SliceType;
+ std::vector<typename SliceType::Pointer> slices;
+ clitk::ExtractSlices<ImageType>(input, d, slices);
+ DD(slices.size());
+
+ // Labelize and keep the main one
+ std::vector<typename SliceType::Pointer> o;
+ for(uint i=0; i<slices.size(); i++) {
+ DD(i);
+ o.push_back(clitk::Labelize<SliceType>(slices[i], BG, false, 1));
+ o[i] = clitk::KeepLabels<SliceType>(o[i], BG, FG, 1, 1, true);
+ }
+
+ // Join slices
+ DD("join");
+ typename ImageType::Pointer output;
+ output = clitk::JoinSlices<ImageType>(o, input, d);
+ DD("return");
+ return output;
+ }
+ //--------------------------------------------------------------------
+
+