필터 지우기
필터 지우기

How can I crop the image from an specific boundary?

조회 수: 8 (최근 30일)
Behrooz Daneshian
Behrooz Daneshian 2023년 8월 1일
답변: Daniel Bengtson 2023년 8월 1일
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