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

 Respuesta aceptada

Image Analyst
Image Analyst el 19 de Abr. de 2015

0 votos

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 comentario

Nada Kadhim
Nada Kadhim el 19 de Abr. de 2015
Hi Image Analyst, Thank you very much for your help. Yours sincerely, Nada

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Preguntada:

el 17 de Abr. de 2015

Comentada:

el 19 de Abr. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by