From 58b7f414d8d90e482b59075845e611ad54fa9810 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Tue, 18 Oct 2011 11:50:15 +0200 Subject: [PATCH] Protect 'crop' if given parameters are larger than image size --- itk/clitkSegmentationUtils.txx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index adca988..2f0d935 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -464,10 +464,12 @@ namespace clitk { typename ImageType::RegionType region; typename ImageType::SizeType size = image->GetLargestPossibleRegion().GetSize(); typename ImageType::PointType p = image->GetOrigin(); - p[dim] = min; + if (min > p[dim]) p[dim] = min; // Check if not outside the image typename ImageType::IndexType start; image->TransformPhysicalPointToIndex(p, start); - p[dim] = max; + double m = image->GetOrigin()[dim] + size[dim]*image->GetSpacing()[dim]; + if (max > m) p[dim] = m; // Check if not outside the image + else p[dim] = max; typename ImageType::IndexType end; image->TransformPhysicalPointToIndex(p, end); size[dim] = abs(end[dim]-start[dim]); -- 2.47.1