我有一个奇怪的问题,该图在图形中重叠,但在同一轴的图像中不重叠。
我确定我不会在某个地方留下阴影,否则它也会在图像本身中重叠。
编辑 :我想摆脱蓝色的重叠线,我只希望在该图片中出现一条蓝色线。
这是一个示例:
(注意:黑色图像是RGB图像,但我没有绘制该atm,因此它意味着在图形上是从黑色到白色的过渡。)
替代文字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 有任何想法吗?
回答:
您有多条蓝线的原因是,您用该线通过循环每次绘制一条图:
plot(parabola_x,parabola_polyval,'b-'); 实际上,您正在循环中一遍又一遍地绘制
所有内容 (图像,点和线),而不会清除旧的图像。
相反,您应该在for循环
之外初始化绘图对象,并使用
SET命令在循环内
更新它们,而不仅仅是重新绘制它们。我在
这个答案的一个例子中
回答了一个问题,您先前曾在这里讨论过使用句柄绘制对象以对其进行修改的问题。对于您在此处提供的示例代码,可以执行以下操作:
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); ... end
更多&回答...