![]() |
Matlab中的图重叠
我有一个奇怪的问题,该图在图形中重叠,但在同一轴的图像中不重叠。
我确定我不会在某个地方留下阴影,否则它也会在图像本身中重叠。 [B]编辑[/B] :我想摆脱蓝色的重叠线,我只希望在该图片中出现一条蓝色线。 这是一个示例: (注意:黑色图像是RGB图像,但我没有绘制该atm,因此它意味着在图形上是从黑色到白色的过渡。) [URL="http://img541.imageshack.us/img541/3212/parabolaaaaa.png"]替代文字http://img541.imageshack.us/img541/3212/parabolaaaaa.png[/URL] 部分代码: 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 有任何想法吗? [B]回答:[/B] 您有多条蓝线的原因是,您用该线通过循环每次绘制一条图: plot(parabola_x,parabola_polyval,'b-'); 实际上,您正在循环中一遍又一遍地绘制[I]所有内容[/I] (图像,点和线),而不会清除旧的图像。 相反,您应该在for循环[I]之外[/I]初始化绘图对象,并使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/set.html"]SET[/URL]命令在循环内[I]更新[/I]它们,而不仅仅是重新绘制它们。我在[URL="https://stackoverflow.com/questions/2837791/using-polyfit-to-predict-where-the-object-falls/2837823#2837823"]这个答案的[/URL]一个例子中[URL="https://stackoverflow.com/questions/2837791/using-polyfit-to-predict-where-the-object-falls/2837823#2837823"]回答[/URL]了一个问题,您先前曾在这里讨论过使用句柄绘制对象以对其进行修改的问题。对于您在此处提供的示例代码,可以执行以下操作: 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 [url=https://stackoverflow.com/questions/2868576]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:09。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.