필터 지우기
필터 지우기

imrect function how I can show the image ?

조회 수: 7 (최근 30일)
Khaled Al-Faleh
Khaled Al-Faleh 2017년 4월 14일
댓글: Image Analyst 2017년 4월 15일
Hi guys, I want to show the position that I choosed by using imrect for example see the code ..
I = imread('---.png');
imshow(I);
h = imrect;
imshow(h);
here I want to show the h How I can do it ??
  댓글 수: 3
Khaled Al-Faleh
Khaled Al-Faleh 2017년 4월 14일
I cropped the image by rectangular box using imrect so I want to show that cropped ..
Khaled Al-Faleh
Khaled Al-Faleh 2017년 4월 14일
let say that I have this image I i used imrect to select what I want from the image so I need to show that selection ... is it clear ?

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

채택된 답변

Image Analyst
Image Analyst 2017년 4월 14일
See this snippet from the attached demo.
% Have user specify the area they want to define as neutral colored (white or gray).
promptMessage = sprintf('Drag out a box over the ROI you want to be neutral colored.\nDouble-click inside of it to finish it.');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Draw', 'Cancel', 'Draw');
if strcmpi(button, 'Cancel')
return;
end
hBox = imrect;
roiPosition = wait(hBox); % Wait for user to double-click
roiPosition % Display in command window.
% Get box coordinates so we can crop a portion out of the full sized image.
xCoords = [roiPosition(1), roiPosition(1)+roiPosition(3), roiPosition(1)+roiPosition(3), roiPosition(1), roiPosition(1)];
yCoords = [roiPosition(2), roiPosition(2), roiPosition(2)+roiPosition(4), roiPosition(2)+roiPosition(4), roiPosition(2)];
croppingRectangle = roiPosition;
% Display (shrink) the original color image in the upper left.
subplot(2, 4, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Crop out the ROI.
whitePortion = imcrop(rgbImage, croppingRectangle);
subplot(2, 4, 5);
imshow(whitePortion);
caption = sprintf('ROI.\nWe will Define this to be "White"');
title(caption, 'FontSize', fontSize);
Once you have croppingRectangle you can put it into the overlay above the image using rectangle(). Or you could use xCoords and yCoords and the plot() function to plot the box over the image.
  댓글 수: 12
Khaled Al-Faleh
Khaled Al-Faleh 2017년 4월 15일
how we can do it sir ?
Image Analyst
Image Analyst 2017년 4월 15일
You can use the function rbbox() instead of imrect():
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint'); % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca,'CurrentPoint'); % button up detected
point1 = point1(1,1:2); % extract x and y
point2 = point2(1,1:2);
p1 = min(point1,point2); % calculate locations
offset = abs(point1-point2); % and dimensions
% Find the coordinates of the box.
xCoords = [p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)];
yCoords = [p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)];
x1 = round(xCoords(1));
x2 = round(xCoords(2));
y1 = round(yCoords(5));
y2 = round(yCoords(3));
width = x2-x1;
height = y2-y1;
% The box from rbbox() disappears after drawing, so redraw the box over the image.
hold on
axis manual
plot(xCoords, yCoords, 'b-'); % redraw in dataspace units

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by