MATLAB: How can cropped subvolume containing all voxels that have intensity in the interval [-100,200]HU from 3D ct images

3d-ctcroppedintensity

how can crooped subvolume containing all voxels that have intensity in the interval [-100,200]HU from 3D ct images

Best Answer

mask = YourVoxels >= -100 & YourVoxels <= 200;
any1 = any(mask,1);
any12 = any(any1, 2);
start_pane = find( any12, 1, 'first');
end_pane = find( any12, 1, 'last');
any13 = any(any1, 3);
start_col = find( any13, 1, 'first');
end_col = find( any13, 1, 'last');
any23 = any(any( mask, 2), 3);
start_row = find( any23, 1, 'first');
end_row = find( any23, 1, 'last');
sub_volume = YourVoxels(start_row : end_row, start_col : end_col, start_pane : end_pane );
Alternately,
mask = YourVoxels >= -100 & YourVoxels <= 200;
rinfo = regionprops( double(mask), 'BoundingBox');
bb = rinfo.BoundingBox;
sub_volume = YourVoxels(bb(1) : bb(1) + bb(4) - 1, bb(2) : bb(2) + bb(5) - 1, bb(3) : bb(3) + bb(6) - 1);
Or if you want that more verbosely:
mask = YourVoxels >= -100 & YourVoxels <= 200;
rinfo = regionprops( double(mask), 'BoundingBox');
bb = rinfo.BoundingBox;
start_row = bb(1);
end_row = bb(1) + bb(4) - 1;
start_col = bb(2);
end_col = bb(2) + bb(5) - 1;
start_pane = bb(3);
end_pane = bb(3) + bb(6) - 1;
sub_volume = YourVoxels(start_row : end_row, start_col : end_col, start_pane : end_pane );