[英]How can I plot an image (.jpg) in MATLAB in both 2-D and 3-D?
我有一個二維散點圖,並且希望在原點顯示圖像(不是彩色正方形,而是實際圖片)。 有什么辦法嗎?
我還將繪制一個3-D球體,在該球體中我也希望在原點處顯示圖像。
您正在尋找IMAGE功能。 這是一個例子:
img = imread('peppers.png'); %# Load a sample image
scatter(rand(1,20)-0.5,rand(1,20)-0.5); %# Plot some random data
hold on; %# Add to the plot
image([-0.1 0.1],[0.1 -0.1],img); %# Plot the image
IMAGE功能不再適用,因為除非從正上方(即,沿Z軸正方向)觀看軸,否則不會顯示圖像。 在這種情況下,您將必須使用SURF函數在3-D中創建一個表面,然后將圖像紋理映射到該表面上。 這是一個例子:
[xSphere,ySphere,zSphere] = sphere(16); %# Points on a sphere
scatter3(xSphere(:),ySphere(:),zSphere(:),'.'); %# Plot the points
axis equal; %# Make the axes scales match
hold on; %# Add to the plot
xlabel('x');
ylabel('y');
zlabel('z');
img = imread('peppers.png'); %# Load a sample image
xImage = [-0.5 0.5; -0.5 0.5]; %# The x data for the image corners
yImage = [0 0; 0 0]; %# The y data for the image corners
zImage = [0.5 0.5; -0.5 -0.5]; %# The z data for the image corners
surf(xImage,yImage,zImage,... %# Plot the surface
'CData',img,...
'FaceColor','texturemap');
請注意,此表面固定在空間中,因此在旋轉軸時,圖像不一定總是直接面對相機。 如果要使紋理貼圖的表面自動旋轉以使其始終垂直於相機的視線,則該過程將涉及更多的過程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.