How to select rectangle ROI in the image and adjust the position of ROI manually. Then it can return the adjusted ROI position

12 ビュー (過去 30 日間)
I can generate roi using images.roi.Rectangle function, but it is easy to be time-consuming during the adjustment process.
Is there any way to write that allows me to manually adjust the roi size and position in the image, and return the pixel value of the roi adjusted position
close all
I = imread('rice.png'); % your input image
figure, imshow(I);
roi = images.roi.Rectangle(gca,'Position',[80,45,80,100]);

採用された回答

Matt J
Matt J 2021 年 9 月 11 日
編集済み: Matt J 2021 年 9 月 11 日
h=drawrectangle();
wait(h);
You must double-click on the rectangle to confirm its position and return control to Matlab.
  2 件のコメント
chihyu
chihyu 2021 年 9 月 18 日
After I follow deer Matt and the URL below, I succeeded. Thanks.
ROI = drawrectangle('Color', 'r')
x1 = ROI.Position(1);
x2 = x1 + ROI.Position(3) - 1;
y1 = ROI.Position(2);
y2 = y1 + ROI.Position(4) - 1;
caption = sprintf('x1 = %.1f, x2 = %.1f, y1 = %.1f, y2 = %.1f',...
x1, x2, y1, y2)
title(caption, 'FontSize', 15)
wait(ROI);
x1 = ROI.Position(1);
x2 = x1 + ROI.Position(3) - 1;
y1 = ROI.Position(2);
y2 = y1 + ROI.Position(4) - 1;
captionNEW = sprintf('x1 = %.1f, x2 = %.1f, y1 = %.1f, y2 = %.1f',...
x1, x2, y1, y2)
title(captionNEW, 'FontSize', 15)
Matt J
Matt J 2021 年 9 月 18 日
You're welcome, but please Accept-click the answer to indicate that it resolved your question.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by