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.
I'd just use colormap and not mess with contours unless you know what you're doing and what you want. To pseudocolor a grayscale image an leave it as grayscale but display it as colored:
imshow(grayImage);
colormap(jet(256));
colorbar;
To convert a grayscale image into a true color RGB image and display the RGB image instead of the pseudocolored image:
Best Answer