From: David Sarrut Date: Tue, 18 Oct 2011 09:50:15 +0000 (+0200) Subject: Protect 'crop' if given parameters are larger than image size X-Git-Tag: v1.3.0~180^2~6 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=58b7f414d8d90e482b59075845e611ad54fa9810;p=clitk.git Protect 'crop' if given parameters are larger than image size --- 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]);