Clear Filters
Clear Filters

How can I crop the image from an specific boundary?

8 views (last 30 days)
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?

Answers (1)

Daniel Bengtson
Daniel Bengtson on 1 Aug 2023
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)

Categories

Find more on Contour Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!