フィルターのクリア

use imcrop and specify width and height but not starting location?

6 ビュー (過去 30 日間)
r_soo
r_soo 2022 年 10 月 4 日
コメント済み: r_soo 2022 年 10 月 9 日
Is there a way to create a specified size rectangle on an image without a set starting point? So I could move the ROI around on the image and save that chunk but without being able to click an drage to change the size of the rectangle?

採用された回答

DGM
DGM 2022 年 10 月 5 日
編集済み: DGM 2022 年 10 月 5 日
This is an attempt to constrain the size of the ROI object during user interaction.
% say you have an image
inpict = imread('peppers.png');
% and you know the box geometry
cropsz = [200 100]; % [x y] (pixels)
% start by displaying the image
figure(1)
imshow(inpict);
% create an ROI object with the specified size
% at some default location (e.g. the image origin)
myROI = drawrectangle(gca,'position',[0 0 cropsz]);
addlistener(myROI,'MovingROI',@(a,b) forcesize(myROI,cropsz));
% the ROI object can be manually dragged around the image
% attempts to resize the object will be prevented
% a simple means to wait for the user
input('Press enter when you''re done moving the ROI object.','s');
% crop using the offsets from the ROI and the specified size
outpict = imcrop(inpict,[myROI.Position(1:2) cropsz]);
% show the result
figure(2)
imshow(outpict)
function forcesize(hObject,fixedsz)
hObject.Position(3:4) = fixedsz;
end
  1 件のコメント
r_soo
r_soo 2022 年 10 月 9 日
Thank you so much this helps a lot!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 10 月 4 日
Maybe try drawrectangle. Demo attached. Adapt as needed.

Community Treasure Hunt

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

Start Hunting!

Translated by