Skip to content
Snippets Groups Projects
Commit 923b404f authored by Nicola Vigano's avatar Nicola Vigano
Browse files

gtCrop: added 4D cropping

parent 7e2a3863
No related branches found
No related tags found
No related merge requests found
......@@ -29,15 +29,15 @@ function img = gtCrop(img, gtbbox)
% Greg Johnson, September 2006
% Modified to work also with 3D volumes W. Ludwig, March 2012
[size_img(1), size_img(2), size_img(3)] = size(img);
[size_img(1), size_img(2), size_img(3), size_img(4)] = size(img);
switch (length(gtbbox))
case 4 % 2D case
minLims = gtbbox(1:2)
maxLims = minLims + gtbbox(3:4) - 1
minLims = gtbbox(1:2);
maxLims = minLims + gtbbox(3:4) - 1;
% if bbox is too large, crop to image extent
minLims = max(minLims, 1)
maxLims = min(size_img(1:2), maxLims)
minLims = max(minLims, 1);
maxLims = min(size_img(1:2), maxLims);
img = img(minLims(2):maxLims(2), minLims(1):maxLims(1));
case 6
......@@ -47,9 +47,19 @@ function img = gtCrop(img, gtbbox)
maxLims = minLims + gtbbox(4:6) - 1;
% if bbox is too large, crop to image extent
minLims = max(minLims, 1);
maxLims = min(size_img, maxLims);
maxLims = min(size_img(1:3), maxLims);
img = img(minLims(1):maxLims(1), minLims(2):maxLims(2), minLims(3):maxLims(3));
case 8
% 4D case, uses different conventions from 2D case: x and y are not
% inverted
minLims = gtbbox(1:4);
maxLims = minLims + gtbbox(5:8) - 1;
% if bbox is too large, crop to image extent
minLims = max(minLims, 1);
maxLims = min(size_img(1:4), maxLims);
img = img(minLims(1):maxLims(1), minLims(2):maxLims(2), minLims(3):maxLims(3), minLims(4):maxLims(4));
otherwise
error('gtCrop:wrongInput', ...
'Argument bbox needs either to be a 4 (2D) or 6 (3D) element vector');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment