필터 지우기
필터 지우기

A problem in the loop

조회 수: 1 (최근 30일)
Nada Kadhim
Nada Kadhim 2015년 4월 17일
댓글: Nada Kadhim 2015년 4월 19일
Hi,
Please I want to draw a patch from four corner points of each building in the image. However, I do not know how can I create a loop for this purpose.
I posted my codes and I will highly appreciate any help may I get.
aa = imread('test_8bit_vis.tif');
figure, image(aa)
[x, y] = ginput
save My_Coordinates.mat x y
hold on
plot(x,y,'xw');
for ii = 1:length(x-1)
ind = x(1:4) + 4 * (ii-1);
patch(x(ind), y(ind),'yellow');
end

채택된 답변

Image Analyst
Image Analyst 2015년 4월 19일
See my code for doing it:
% Display something so we can draw on it.
folder = fileparts(which('office_4.jpg')); % Determine where demo folder is (works with all versions).
baseFileName = 'office_4.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
imshow(rgbImage, []);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
message = sprintf('Draw your polygon with left clicks.\nRight click the last point to finish it.');
uiwait(helpdlg(message));
loopCounter = 1;
while loopCounter < 30
% Let user draw the polygon.
[~, x, y] = roipolyold;
% Draw a yellow patch over the image.
patch(x, y,'yellow');
% Ask user if they want to continue.
promptMessage = sprintf('Do you want to Continue drawing patches,\nor Cancel to quit drawing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
break;
end
loopCounter = loopCounter + 1;
end
It this meets the requirements, go ahead and please mark it Accepted.
  댓글 수: 1
Nada Kadhim
Nada Kadhim 2015년 4월 19일
Hi Image Analyst, Thank you very much for your help. Yours sincerely, Nada

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by