How to create fixed rectangle and crop it?

조회 수: 5 (최근 30일)
Rashidul Alim Anik
Rashidul Alim Anik 2022년 3월 15일
댓글: DGM 2022년 3월 16일
I want a fixed 257x257 rectangle and want to crop according to the rectangle of my image.What is the code would be?

채택된 답변

yanqi liu
yanqi liu 2022년 3월 16일
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/927339/image.jpeg');
figure; imshow(img, []);
h = imrect(gca, [1 1 257 257]);
title('please move the rect');
% now you can set the rect
pos = wait(h);
hold on; rectangle('position', pos, 'EdgeColor', 'g', 'LineWidth', 2)
img2 = imcrop(img, round(pos));
figure; imshow(img2, []);
  댓글 수: 1
DGM
DGM 2022년 3월 16일
You can just do imcrop(img) directly for interactive cropping. If you want to preserve the rect parameter for later, you can do
[croppedimg croprect] = imcrop(img);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by