rtsCropMask.m
461 Bytes
function new_mask = rtsCropMask(mask, max_pixels)
%convert to logical
%mask = mask > 0;
if nnz(mask) < max_pixels
new_mask = mask;
else
j = 0;
for i = 1:length(mask(:))
if mask(i) > 0
j = j + 1;
if j == max_pixels
last_pixel = i;
end
end
end
new_mask = zeros(size(mask, 1), size(mask, 2));
new_mask(1:last_pixel) = mask(1:last_pixel);
end