2次元/3次元プロットに画像を挿入するにはどうすればよいですか?
15 views (last 30 days)
Show older comments
MathWorks Support Team
on 1 Sep 2016
Edited: MathWorks Support Team
on 29 Mar 2018
2次元プロットもしくは、3次元プロットに画像を挿入する方法を教えてください。
Accepted Answer
MathWorks Support Team
on 29 Mar 2018
Edited: MathWorks Support Team
on 29 Mar 2018
2次元グラフィックスと3 次元グラフィックスのそれぞれの場合について、説明します。
2次元グラフィックスの場合:
image 関数(もしくは、imagesc, imshow 関数)を用いて行うことが可能です。
以下の例では、scatter プロットの中心に画像を挿入します。
img = imread('peppers.png'); % サンプル画像の読み込み
scatter(rand(1,20)-0.5,rand(1,20)-0.5); % ランダムデータの表示
hold on; % 重ね書き on
image([-0.1 0.1],[0.1 -0.1],img); % 画像の表示
3次元グラフィックスの場合:
image 関数(もしくは、imagesc, imshow 関数)を用いると、Z = 0 の平面に画像が表示されます。
Z 軸方向の位置をユーザ側で指定したい場合には、surf (surface) 関数を用いて表示します。
以下の例では、3 次元 scatter プロットの中央に画像を挿入します。
[xSphere,ySphere,zSphere] = sphere(16); % サンプルデータ定義
scatter3(xSphere(:),ySphere(:),zSphere(:),'.'); % プロット
axis equal; % 軸の比率を1:1:1に設定
hold on; % 重ね書き on
xlabel('x');
ylabel('y');
zlabel('z');
img = imread('peppers.png'); % サンプル画像の読み込み
pos = axis; % 先に描画した 3 次元グラフィックスの Axes 範囲を取得
% 画像を表示するための x, y z データ作成
xImage = repmat(pos(1:2),2,1);
yImage = repmat(pos(3:4)',1,2);
zImage = ones(2)*pos(5);
surf(xImage,yImage,zImage,'CData',img,'FaceColor','texturemap'); % Texturemap として画像を表示
set(gca,'YDir', 'reverse') % Y 軸の向きを反転
0 Comments
More Answers (0)
See Also
Categories
Find more on イメージ算術 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!