From 35c9a996e72711cf095f0daa49b76fe0c0e4bacb Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Mon, 25 Jul 2011 09:15:47 +0200 Subject: [PATCH] Add SliceBySliceSetBackgroundFromPoints, GetMinMaxBoundary, FillRegionWithValue --- itk/clitkSegmentationUtils.h | 25 +++++++- itk/clitkSegmentationUtils.txx | 105 +++++++++++++++++++++++++++++---- 2 files changed, 118 insertions(+), 12 deletions(-) diff --git a/itk/clitkSegmentationUtils.h b/itk/clitkSegmentationUtils.h index 85f2591..6204c9c 100644 --- a/itk/clitkSegmentationUtils.h +++ b/itk/clitkSegmentationUtils.h @@ -444,11 +444,32 @@ namespace clitk { int dim1, int dim2, bool removeLowerPartFlag); //-------------------------------------------------------------------- - + + //-------------------------------------------------------------------- + template + typename ImageType::Pointer + SliceBySliceSetBackgroundFromPoints(const ImageType * input, + typename ImageType::PixelType BG, + int sliceDim, + std::vector & A, + bool removeGreaterThanXFlag, + bool removeGreaterThanYFlag); + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + template + void + FillRegionWithValue(ImageType * input, typename ImageType::PixelType value, + typename ImageType::RegionType & region); + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- template void - FillRegionWithValue(ImageType * input, typename ImageType::PixelType value, typename ImageType::RegionType & region); + GetMinMaxBoundary(ImageType * input, typename ImageType::PointType & min, + typename ImageType::PointType & max); //-------------------------------------------------------------------- } diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index b328315..afcefcf 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -730,7 +730,8 @@ namespace clitk { dilateFilter->SetForegroundValue(FG); dilateFilter->SetBoundaryToForeground(false); dilateFilter->SetKernel(structuringElement); - dilateFilter->SetInput(output); + if (extendSupport) dilateFilter->SetInput(output); + else dilateFilter->SetInput(image); dilateFilter->Update(); return dilateFilter->GetOutput(); } @@ -831,9 +832,6 @@ namespace clitk { while ((iTransformIndexToPhysicalPoint(siter.GetIndex(), C); - // DD(C); - // DD(i); - // DD(lA[i]); if ((fabs(C[2] - lA[i][2]))>0.01) { // is !equal with a tolerance of 0.01 mm } else { @@ -841,9 +839,6 @@ namespace clitk { A = lA[i]; B = lB[i]; C = A; - // DD(A); - // DD(B); - // DD(C); // Check that the line is not a point (A=B) bool p = (A[0] == B[0]) && (A[1] == B[1]); @@ -1063,7 +1058,7 @@ namespace clitk { extremaDirection, extremaOppositeFlag, p); if (found) { position2D[i] = p; - } + } } // Convert 2D points in slice into 3D points @@ -1076,8 +1071,8 @@ namespace clitk { p[lineDirection] += 10; B.push_back(p); // Margins ? - A[i][1] += margin; - B[i][1] += margin; + A[i][extremaDirection] += margin; + B[i][extremaDirection] += margin; } } @@ -1196,6 +1191,78 @@ namespace clitk { } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + /* Consider an input object, slice by slice, use the point A and set + pixel to BG according to their position relatively to A + */ + template + typename ImageType::Pointer + SliceBySliceSetBackgroundFromPoints(const ImageType * input, + typename ImageType::PixelType BG, + int sliceDim, + std::vector & A, + bool removeGreaterThanXFlag, + bool removeGreaterThanYFlag) + + { + // Extract slices + typedef typename itk::Image SliceType; + typedef typename SliceType::Pointer SlicePointer; + std::vector slices; + clitk::ExtractSlices(input, sliceDim, slices); + + // Start at slice that contains A + typename ImageType::IndexType Ap; + + // Determine slice largest region + typename SliceType::RegionType region = slices[0]->GetLargestPossibleRegion(); + typename SliceType::SizeType size = region.GetSize(); + typename SliceType::IndexType index = region.GetIndex(); + + // Loop from slice A to slice B + for(uint i=0; iTransformPhysicalPointToIndex(A[i], Ap); + uint sliceIndex = Ap[2] - input->GetLargestPossibleRegion().GetIndex()[2]; + if ((sliceIndex < 0) || (sliceIndex >= slices.size())) { + continue; // do not consider this slice + } + + // Compute region for BG + if (removeGreaterThanXFlag) { + index[0] = Ap[0]; + size[0] = region.GetSize()[0]-(index[0]-region.GetIndex()[0]); + } + else { + index[0] = region.GetIndex()[0]; + size[0] = Ap[0] - index[0]; + } + + if (removeGreaterThanYFlag) { + index[1] = Ap[1]; + size[1] = region.GetSize()[1]-(index[1]-region.GetIndex()[1]); + } + else { + index[1] = region.GetIndex()[1]; + size[1] = Ap[1] - index[1]; + } + + // Set region + region.SetSize(size); + region.SetIndex(index); + + // Fill region with BG (simple region iterator) + FillRegionWithValue(slices[sliceIndex], BG, region); + // Loop + } + + // Merge slices + typename ImageType::Pointer output; + output = clitk::JoinSlices(slices, input, sliceDim); + return output; + } + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- template void @@ -1211,5 +1278,23 @@ namespace clitk { } //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + template + void + GetMinMaxBoundary(ImageType * input, typename ImageType::PointType & min, + typename ImageType::PointType & max) + { + typedef typename ImageType::PointType PointType; + typedef typename ImageType::IndexType IndexType; + IndexType min_i, max_i; + min_i = input->GetLargestPossibleRegion().GetIndex(); + for(uint i=0; iGetLargestPossibleRegion().GetSize()[i] + min_i[i]; + input->TransformIndexToPhysicalPoint(min_i, min); + input->TransformIndexToPhysicalPoint(max_i, max); + } + //-------------------------------------------------------------------- + } // end of namespace -- 2.47.1