Matlab - 如何在图像上绘制比例图形
我有一张图像,上面有 4 个点,我希望这些点与我想在该图像顶部绘制的图形中的 X、Y 坐标完全(或非常接近)对齐。图像当前为 600x600 像素,但可以调整。
我的身材比例来自
AXIS([388020 388090 5776940 5777010])
如何对齐我的图像以匹配它?那么matlab是在它上面绘制的吗?
这是我的 matlab 脚本,运行它我可以看到 matlab 绘图,但下面没有图像......并且 matlab 绘图似乎是倒置的。
%获取csv文件 %for 每行输出一个包含 3 个圆圈和估计值的图像 %点
d = 大小(数据调整后) 长度 = d(1)
对于 i = [1:1]
%# read and display image
img = imread('hciLab_N.png');
figure('Visible', 'off'),imagesc([388020 388090], [5776940 5777010], img);
%# make sure the image doesn't disappear if we plot something else
hold on
%axis([388020 388090 5776940 5777010]);
%location estimation
yCoord = dataAdjusted(i,2)
xCoord = dataAdjusted(i,3)
%first circle y, x, radius
c1Y = dataAdjusted(i,4);
c1X = dataAdjusted(i,5);
c1R = dataAdjusted(i,6);
%second circle y, x, radius
c2Y = dataAdjusted(i,7);
c2X = dataAdjusted(i,8);
c2R = dataAdjusted(i,9);
%third circle y, x, radius
c3Y = dataAdjusted(i,10);
c3X = dataAdjusted(i,11);
c3R = dataAdjusted(i,12);
%draw location
%rectangle('Position',[xCoord-.5,yCoord-.5,2*.5,2*.5],'Curvature',[1,1], 'EdgeColor', 'r')
[locX, locY] = makeCircle(xCoord, yCoord, .5);
scatter(locX, locY, .2,'b')
%draw circles
%rectangle('Position',[c1X-c1R,c1Y-c1R,2*c1R,2*c1R],'Curvature',[1,1])
%rectangle('Position',[c2X-c2R,c2Y-c2R,2*c2R,2*c2R],'Curvature',[1,1])
%rectangle('Position',[c3X-c3R,c3Y-c3R,2*c3R,2*c3R],'Curvature',[1,1])
[c1X, c1y] = makeCircle(c1X, c1Y, c1R);
scatter(c1X, c1y, .2,'k')
[c2X, c2y] = makeCircle(c2X, c2Y, c2R);
scatter(c2X, c2y, .2,'k')
[c3X, c3y] = makeCircle(c3X, c3Y, c2R);
scatter(c3X, c3y, .2,'k')
% 80 5776978.148 388054.1747
%rectangle('Position',[388054.1747-1,5776978.148-1,2*1,2*1],'Curvature',[1,1], 'EdgeColor', 'g')
[r1X, r1y] = makeCircle(388054.1747, 5776978.148, 1);
scatter(r1X, r1y,.2,'g')
% 87 5776988.825 388043.9639
%rectangle('Position',[388043.9639-1,5776988.825-1,2*1,2*1],'Curvature',[1,1], 'EdgeColor', 'g')
[r2X, r2y] = makeCircle(388043.9639, 5776988.825, 1);
scatter(r2X, r2y,.2,'g')
% 88 5776970.712 388054.2578
%rectangle('Position',[388054.2578-1,5776970.712-1,2*1,2*1],'Curvature',[1,1], 'EdgeColor', 'g')
[r3X, r3y] = makeCircle(388054.2578,5776970.712, 1);
scatter(r3X, r3y,.2,'g')
% 89 5776975.889 388039.8496
%rectangle('Position',[388039.8496-1,5776975.889-1,2*1,2*1],'Curvature',[1,1], 'EdgeColor', 'g')
[r4X, r4y] = makeCircle(388039.8496,5776975.889, 1);
scatter(r4X, r4y,.2,'g')
%title(['Localization of duty cycle ' this_name ]);
saveas(gcf, ['TrilaterationNumber_Adjusted_WithRouters_Scaled' num2str(i)], 'png');
结束
I have an image with 4 spots on it, I want those spots to line up exactly(or very close) to X,Y coordinates in a figure that I would like to draw on top of this image. The image is currently 600x600 pixels, but that could be adjusted.
My figure scale goes from
AXIS([388020 388090 5776940 5777010])
How can I align my image to match that? So matlab draws on top of it?
Here is my matlab script, running this I can see the matlab drawing but no image underneath... and the matlab drawing seems to be inverted.
%takes in csv file
%for each line outputs an image that includes 3 circles and the estimated
%point
d = size(dataAdjusted)
length = d(1)
for i = [1:1]
%# read and display image
img = imread('hciLab_N.png');
figure('Visible', 'off'),imagesc([388020 388090], [5776940 5777010], img);
%# make sure the image doesn't disappear if we plot something else
hold on
%axis([388020 388090 5776940 5777010]);
%location estimation
yCoord = dataAdjusted(i,2)
xCoord = dataAdjusted(i,3)
%first circle y, x, radius
c1Y = dataAdjusted(i,4);
c1X = dataAdjusted(i,5);
c1R = dataAdjusted(i,6);
%second circle y, x, radius
c2Y = dataAdjusted(i,7);
c2X = dataAdjusted(i,8);
c2R = dataAdjusted(i,9);
%third circle y, x, radius
c3Y = dataAdjusted(i,10);
c3X = dataAdjusted(i,11);
c3R = dataAdjusted(i,12);
%draw location
%rectangle('Position',[xCoord-.5,yCoord-.5,2*.5,2*.5],'Curvature',[1,1], 'EdgeColor', 'r')
[locX, locY] = makeCircle(xCoord, yCoord, .5);
scatter(locX, locY, .2,'b')
%draw circles
%rectangle('Position',[c1X-c1R,c1Y-c1R,2*c1R,2*c1R],'Curvature',[1,1])
%rectangle('Position',[c2X-c2R,c2Y-c2R,2*c2R,2*c2R],'Curvature',[1,1])
%rectangle('Position',[c3X-c3R,c3Y-c3R,2*c3R,2*c3R],'Curvature',[1,1])
[c1X, c1y] = makeCircle(c1X, c1Y, c1R);
scatter(c1X, c1y, .2,'k')
[c2X, c2y] = makeCircle(c2X, c2Y, c2R);
scatter(c2X, c2y, .2,'k')
[c3X, c3y] = makeCircle(c3X, c3Y, c2R);
scatter(c3X, c3y, .2,'k')
% 80 5776978.148 388054.1747
%rectangle('Position',[388054.1747-1,5776978.148-1,2*1,2*1],'Curvature',[1,1], 'EdgeColor', 'g')
[r1X, r1y] = makeCircle(388054.1747, 5776978.148, 1);
scatter(r1X, r1y,.2,'g')
% 87 5776988.825 388043.9639
%rectangle('Position',[388043.9639-1,5776988.825-1,2*1,2*1],'Curvature',[1,1], 'EdgeColor', 'g')
[r2X, r2y] = makeCircle(388043.9639, 5776988.825, 1);
scatter(r2X, r2y,.2,'g')
% 88 5776970.712 388054.2578
%rectangle('Position',[388054.2578-1,5776970.712-1,2*1,2*1],'Curvature',[1,1], 'EdgeColor', 'g')
[r3X, r3y] = makeCircle(388054.2578,5776970.712, 1);
scatter(r3X, r3y,.2,'g')
% 89 5776975.889 388039.8496
%rectangle('Position',[388039.8496-1,5776975.889-1,2*1,2*1],'Curvature',[1,1], 'EdgeColor', 'g')
[r4X, r4y] = makeCircle(388039.8496,5776975.889, 1);
scatter(r4X, r4y,.2,'g')
%title(['Localization of duty cycle ' this_name ]);
saveas(gcf, ['TrilaterationNumber_Adjusted_WithRouters_Scaled' num2str(i)], 'png');
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以调用 image() 和 imagesc() 带有 x,y 限制,然后用作轴限制:
或者,如果您只是需要缩放数据:
您可能需要发出放置图像后,在绘制其他内容之前,请“保留全部”。
You can call both image() and imagesc() with x,y limits which are then used as the axis limits:
or, if you just need scaled data:
You may need to issue a 'hold all' once you've put up the image, before ploting anything else.