我有一个奇怪的问题,那就是图中的图形重叠,而在同一轴上的图像没有重叠。
我确信我没有离开什么地方,否则它将重叠在图像本身。
编辑:我想去掉蓝色的重叠线,我只想在那张照片中出现一条蓝线。
以下是一个示例:
(注意:黑色图像是RGB图像,但我没有绘制该atm,因此它意味着在图形上从黑色过渡到白色。)
alt文本http://img541.imageshack.us/img541/3212/parabolaaaaa.png
守则的某些部分:
for K=1:23
hold on
I = fig.img.(['p' num2str(K)]);
bw=(I);
imshow(bw)
ss = bwlabel(bw);
s = regionprops(ss,'centroid');
centroids{K} = cat(1,s.Centroid);
hold(imgca,'on')
plot(imgca,centroids{K}(:,1), centroids{K}(:,2), 'r*'); hold on;
x=centroids{K}(:,1);
y=centroids{K}(:,2);
points=plot(x,y,'go',x,y,'rx');
hold on
axis on
axis fill
ccentroids = cat(1,centroids{:});
C1=ccentroids(:,1);
C2=ccentroids(:,2);
set(points,'XData',C1,'YData',C2);
.
.
.
p= polyfit(x2,y2,2)
parabola_x = linspace(-250,640,500);
parabola_polyval = polyval(p,parabola_x);
plot(parabola_x,parabola_polyval,'b-');
.
.
.
end有什么想法吗?
发布于 2010-05-19 19:58:39
之所以有多条蓝线,是因为每次通过循环时都要用该线绘制一条:
plot(parabola_x,parabola_polyval,'b-');实际上,您正在反复绘制循环中的所有内容(图像、点和线),而不清除旧的。
相反,您应该在for循环之外初始化绘图对象,并使用设置命令在循环中更新它们,而不是仅仅重新绘制它们。我在这个答案中给出了这方面的一个例子,您之前曾问过我在哪里讨论如何使用句柄来绘制对象来修改它们。对于这里给出的示例代码,您可以这样做:
hImage = imshow(bw(fig.img.p1)); %# Initialize the image
hold on; %# Add to the existing plot
hStar = plot(nan,nan,'r*'); %# Initialize the red star
hPoints = plot(nan,nan,'go',... %# Initialize the other points
nan,nan,'rx');
hLine = plot(nan,nan,'b-'); %# Initialize the blue line
for K = 1:23
I = fig.img.(['p' num2str(K)]);
bw = (I);
set(hImage,'CData',bw); %# Update the image
ss = bwlabel(bw);
s = regionprops(ss,'centroid');
centroids{K} = cat(1,s.Centroid);
set(hStar,'XData',centroids{K}(:,1),... %# Update the red star
'YData',centroids{K}(:,2));
ccentroids = cat(1,centroids{:});
C1 = ccentroids(:,1);
C2 = ccentroids(:,2);
set(hPoints,'XData',C1,'YData',C2); %# Update the other points
...
p = polyfit(x2,y2,2);
parabola_x = linspace(-250,640,500);
parabola_polyval = polyval(p,parabola_x);
set(hLine,'XData',parabola_x,... %# Update the blue line
'YData',parabola_polyval);
...
endhttps://stackoverflow.com/questions/2868576
复制相似问题