were to introduce hold on command

1 回表示 (過去 30 日間)
FIR
FIR 2013 年 1 月 10 日
I have a image in which i have to draw a circle over it,i have to draw circles in many places in the image ,please tell how to procees,i saw a code in matlab central it draws only one circle ,but how to draw many circles on a image manually ,i have to click on image and have to draw circle
http://www.mathworks.com/matlabcentral/fileexchange/23121-circle-on-image
i edited from above link but the thing is that i have to draw many circle on one image ,please tell where i have to write hold on command
code
where k is my image
function [] = circle_saptha(k)
ok = 0;
while ok~=1
% figure;
imshow(k);
pt = ginput(2)
x1 = pt(1,1);
y1 = pt(1,2);
x2 = pt(2,1);
y2 = pt(2,2);
xpt = [x1 x2];
ypt = [y1 y2];
%line(x,y); % Enablw this for draw rectangle on circle
r = sqrt((x2-x1)^2 + (y2-y1)^2)
pp=rsmak('circle',r,[x1 y1]);
% figure;
% imshow(k)
fnplt(pp);
line(xpt,ypt);
xtl = x1-r;
xtr = x1+r;
xbl = x1-r;
xbr = x1+r;
ytl = y1+r;
ytr = y1+r;
ybl = y1-r;
ybr = y1-r;
x = [xtl xtr xbr xbl xtl];
y = [ytl ytr ybr ybl ytl];
%line(x,y);
for i=1:size(k,1)
for j=1:size(k,2)
x2 = j;
y2 = i;
val = floor(sqrt((x2-x1)^2 + (y2-y1)^2));
if(val == floor(r))
nim(i,j,1) = 255;
nim(i,j,2) = 0;
nim(i,j,3) = 0;
else
nim(i,j,1) = k(i,j,1);
nim(i,j,2) = k(i,j,2);
nim(i,j,3) = k(i,j,3);
end
end
end
imshow(nim);
ok = (menu('Do u want to draw another circle?','No','Yes')==1)
imshow(nim);
end
end

採用された回答

Teja Muppirala
Teja Muppirala 2013 年 1 月 11 日
You keep overwriting "nim" with the same original "k". You can fix it easily:
Step 1. Change these lines:
ok = 0;
while ok~=1
% figure;
imshow(k);
to this:
ok = 0;
nim = k;
while ok~=1
% figure;
imshow(nim);
Step 2. Delete these three lines:
nim(i,j,1) = k(i,j,1);
nim(i,j,2) = k(i,j,2);
nim(i,j,3) = k(i,j,3);
  2 件のコメント
FIR
FIR 2013 年 1 月 11 日
same error
Teja Muppirala
Teja Muppirala 2013 年 1 月 11 日
Are you sure? Run this:
k = imread('peppers.png');
ok = 0;
nim = k;
while ok~=1
% figure;
imshow(nim);
pt = ginput(2)
x1 = pt(1,1);
y1 = pt(1,2);
x2 = pt(2,1);
y2 = pt(2,2);
xpt = [x1 x2];
ypt = [y1 y2];
%line(x,y); % Enablw this for draw rectangle on circle
r = sqrt((x2-x1)^2 + (y2-y1)^2)
%line(x,y);
for i=1:size(k,1)
for j=1:size(k,2)
x2 = j;
y2 = i;
val = floor(sqrt((x2-x1)^2 + (y2-y1)^2));
if(val == floor(r))
nim(i,j,1) = 255;
nim(i,j,2) = 0;
nim(i,j,3) = 0;
else
end
end
end
imshow(nim); ok = (menu('Do u want to draw another circle?','No','Yes')==1)
imshow(nim);
end

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

その他の回答 (1 件)

Jan
Jan 2013 年 1 月 10 日
編集済み: Jan 2013 年 1 月 10 日
A simplified version:
while ok~=1
imshow(k);
nim = <modified k>
imshow(nim);
ok = (menu('Do u want to draw another circle?','No','Yes') == 1);
imshow(nim);
end
Now nim is overwritten each time based on k. Perhaps you want:
nim = k;
while ok~=1
nim = <modified nim>
imshow(nim);
ok = (menu('Do u want to draw another circle?','No','Yes') == 1);
end
  4 件のコメント
FIR
FIR 2013 年 1 月 11 日
The code above draws circle on imagaes one by one,i want to draw many circles on same image
Jan
Jan 2013 年 1 月 11 日
Then you should not insert the values of "k" in each iteration, but keep the values of "nim".

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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by