MATLAB: Identify a boundary in an image (matrix form)

image analysisimage processingImage Processing Toolbox

Hi,
i have a matrix with the size of 25*20*10 (lon*lat*time). I would like to find the boundary of the image. Any ideas on how to do that?Here is part of the matrix (25*20*1):

Best Answer

One way that works for multiple regions in the 2-D image "m":
validData = ~isnan(m); % Map of valid (non-nan) locations of matrix m.
boundaries = bwboundaries(validData);
imshow(m, [], 'InitialMagnification', 1000); % Display this matrix.
axis('on', 'image'); % Display tick marks.
hold on; % Don't let boundaries blow away image because we want to plot them over the image.
for k = 1 : length(boundaries)
thisBoundary = boundaries{k}; % Get this particular boundary.
plot(thisBoundary(:, 2), thisBoundary(:, 1), 'r-', 'LineWidth', 2); % Plot it.
end