I need some help to plot getrect selected portion of a picture. How can i plot it after getting coordinates. here what i have done yet. If there is a simple way please mention it.

1 Ansicht (letzte 30 Tage)
fullFileName = fullfile(folder, baseFileName)
crack = imread(fullFileName); %This file is of bmp formate
[rows, columns, numberOfColorChannels] = size(crack);
imshow(crack)
title('Select The Crack', 'FontSize', captionFontSize);
grid on;
uiwait(helpdlg('Select the Crack in Crack Image.'));
rect=getrect;
% Get the x and y co-ordinates
rect(1) = max(floor(rect(1)), 1); %xmin
rect(2) = max(floor(rect(2)), 1);%ymin
rect(3)= min(ceil(rect(1) + rect(3))); %xmax
rect(4)=min(ceil(rect(2) +rect(4))); %ymax
% Index into the original image to create the new image
MM=crack(rect(2):rect(4), rect(1): rect(3),:);
image(MM)
imsave

Antworten (1)

Ameer Hamza
Ameer Hamza am 22 Okt. 2020
Directly pass the rect to imcrop(): https://www.mathworks.com/help/images/ref/imcrop.html
rect=getrect;
MM = imcrop(crack, rect);
image(MM)
  3 Kommentare
Ameer Hamza
Ameer Hamza am 22 Okt. 2020
Instead of image() use imshow()
crack = imread('image.bmp');
imshow(crack)
rect=getrect;
MM = imcrop(crack, rect);
imshow(MM)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by