How can I crop the image from an specific boundary?

5 visualizaciones (últimos 30 días)
Behrooz Daneshian
Behrooz Daneshian el 1 de Ag. de 2023
Respondida: Daniel Bengtson el 1 de Ag. de 2023
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?

Respuestas (1)

Daniel Bengtson
Daniel Bengtson el 1 de Ag. de 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)

Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by