]> Creatis software - clitk.git/commitdiff
Protect 'crop' if given parameters are larger than image size
authorDavid Sarrut <david.sarrut@gmail.com>
Tue, 18 Oct 2011 09:50:15 +0000 (11:50 +0200)
committerDavid Sarrut <david.sarrut@gmail.com>
Tue, 18 Oct 2011 09:50:15 +0000 (11:50 +0200)
itk/clitkSegmentationUtils.txx

index adca988098ad8c78fee5cfb132b890fb0bef0c09..2f0d935a7cbbc88d038000768d6bed04bfd2451f 100644 (file)
@@ -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]);