How can I crop the image from an specific boundary?

7 次查看(过去 30 天)
Hello all,
I have a contour plot showing frost depth across the US (it is attached here). I want to crop the plot so that I would just have the entire US ( not anything outside the us borders). Can anyone help me with this regard?

回答(1 个)

Daniel Bengtson
Daniel Bengtson 2023-8-1
The mask and blur causes a bit of artifacting in the text, and there is obviously a bit of color outside of the boundaries. I'm sure others can do better, but here is a start.
im = imread('1FrostPlot_1_feet.png');
mask = im(:,:,1) < 50 & im(:,:,2) < 50 & im(:,:,3) < 50; % identify the dark borders between states/ocean
im2 = imgaussfilt(255*repmat(uint8(mask),1,1,3),1); % add a small amount of blur to close gaps in the boundaries
border = grayconnected(im2(:,:,1),10,10,1); % use the pixel at 10,10 to define connected color
border = repmat(border,1,1,3); % make mask the same shape as image
im(border) = 255; % set masked pixels to white
figure;
imshow(im)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by