How can I plot an image (.jpg) in MATLAB in both 2-D and 3-D?
I have a 2-D scatter plot and at the origin I want to display an image (not a colorful square, but an actual picture). Is there any way to do this?
I also will be plotting a 3-D sphere in which I would like an image to be displayed at the origin as well.
image matlab 3d plot
add a comment |
I have a 2-D scatter plot and at the origin I want to display an image (not a colorful square, but an actual picture). Is there any way to do this?
I also will be plotting a 3-D sphere in which I would like an image to be displayed at the origin as well.
image matlab 3d plot
add a comment |
I have a 2-D scatter plot and at the origin I want to display an image (not a colorful square, but an actual picture). Is there any way to do this?
I also will be plotting a 3-D sphere in which I would like an image to be displayed at the origin as well.
image matlab 3d plot
I have a 2-D scatter plot and at the origin I want to display an image (not a colorful square, but an actual picture). Is there any way to do this?
I also will be plotting a 3-D sphere in which I would like an image to be displayed at the origin as well.
image matlab 3d plot
image matlab 3d plot
edited Jun 29 '12 at 10:56
Amro
116k19209389
116k19209389
asked Sep 15 '10 at 15:58
dewalladewalla
69981542
69981542
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
For 2-D plots...
The function IMAGE is what you're looking for. Here's an example:
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
For 3-D plots...
The IMAGE function is no longer appropriate, as the image will not be displayed unless the axis is viewed from directly above (i.e. from along the positive z-axis). In this case you will have to create a surface in 3-D using the SURF function and texture map the image onto it. Here's an example:
[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');
Note that this surface is fixed in space, so the image will not always be directly facing the camera as you rotate the axes. If you want the texture-mapped surface to automatically rotate so that it is always perpendicular to the line of sight of the camera, it's a much more involved process.
I'll try this will this work for 3-D plots as well?
– dewalla
Sep 15 '10 at 16:15
Greate answer. Can I resize the image so that it fits the scatter chart?
– SolessChong
Jun 3 '13 at 3:44
how can I just project the image on the 2D plane, while showing dynamically generated data in 3d?
– Diego
Sep 25 '13 at 18:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3719502%2fhow-can-i-plot-an-image-jpg-in-matlab-in-both-2-d-and-3-d%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For 2-D plots...
The function IMAGE is what you're looking for. Here's an example:
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
For 3-D plots...
The IMAGE function is no longer appropriate, as the image will not be displayed unless the axis is viewed from directly above (i.e. from along the positive z-axis). In this case you will have to create a surface in 3-D using the SURF function and texture map the image onto it. Here's an example:
[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');
Note that this surface is fixed in space, so the image will not always be directly facing the camera as you rotate the axes. If you want the texture-mapped surface to automatically rotate so that it is always perpendicular to the line of sight of the camera, it's a much more involved process.
I'll try this will this work for 3-D plots as well?
– dewalla
Sep 15 '10 at 16:15
Greate answer. Can I resize the image so that it fits the scatter chart?
– SolessChong
Jun 3 '13 at 3:44
how can I just project the image on the 2D plane, while showing dynamically generated data in 3d?
– Diego
Sep 25 '13 at 18:14
add a comment |
For 2-D plots...
The function IMAGE is what you're looking for. Here's an example:
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
For 3-D plots...
The IMAGE function is no longer appropriate, as the image will not be displayed unless the axis is viewed from directly above (i.e. from along the positive z-axis). In this case you will have to create a surface in 3-D using the SURF function and texture map the image onto it. Here's an example:
[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');
Note that this surface is fixed in space, so the image will not always be directly facing the camera as you rotate the axes. If you want the texture-mapped surface to automatically rotate so that it is always perpendicular to the line of sight of the camera, it's a much more involved process.
I'll try this will this work for 3-D plots as well?
– dewalla
Sep 15 '10 at 16:15
Greate answer. Can I resize the image so that it fits the scatter chart?
– SolessChong
Jun 3 '13 at 3:44
how can I just project the image on the 2D plane, while showing dynamically generated data in 3d?
– Diego
Sep 25 '13 at 18:14
add a comment |
For 2-D plots...
The function IMAGE is what you're looking for. Here's an example:
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
For 3-D plots...
The IMAGE function is no longer appropriate, as the image will not be displayed unless the axis is viewed from directly above (i.e. from along the positive z-axis). In this case you will have to create a surface in 3-D using the SURF function and texture map the image onto it. Here's an example:
[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');
Note that this surface is fixed in space, so the image will not always be directly facing the camera as you rotate the axes. If you want the texture-mapped surface to automatically rotate so that it is always perpendicular to the line of sight of the camera, it's a much more involved process.
For 2-D plots...
The function IMAGE is what you're looking for. Here's an example:
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
For 3-D plots...
The IMAGE function is no longer appropriate, as the image will not be displayed unless the axis is viewed from directly above (i.e. from along the positive z-axis). In this case you will have to create a surface in 3-D using the SURF function and texture map the image onto it. Here's an example:
[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');
Note that this surface is fixed in space, so the image will not always be directly facing the camera as you rotate the axes. If you want the texture-mapped surface to automatically rotate so that it is always perpendicular to the line of sight of the camera, it's a much more involved process.
edited Sep 15 '10 at 17:30
answered Sep 15 '10 at 16:01
gnovicegnovice
116k13231335
116k13231335
I'll try this will this work for 3-D plots as well?
– dewalla
Sep 15 '10 at 16:15
Greate answer. Can I resize the image so that it fits the scatter chart?
– SolessChong
Jun 3 '13 at 3:44
how can I just project the image on the 2D plane, while showing dynamically generated data in 3d?
– Diego
Sep 25 '13 at 18:14
add a comment |
I'll try this will this work for 3-D plots as well?
– dewalla
Sep 15 '10 at 16:15
Greate answer. Can I resize the image so that it fits the scatter chart?
– SolessChong
Jun 3 '13 at 3:44
how can I just project the image on the 2D plane, while showing dynamically generated data in 3d?
– Diego
Sep 25 '13 at 18:14
I'll try this will this work for 3-D plots as well?
– dewalla
Sep 15 '10 at 16:15
I'll try this will this work for 3-D plots as well?
– dewalla
Sep 15 '10 at 16:15
Greate answer. Can I resize the image so that it fits the scatter chart?
– SolessChong
Jun 3 '13 at 3:44
Greate answer. Can I resize the image so that it fits the scatter chart?
– SolessChong
Jun 3 '13 at 3:44
how can I just project the image on the 2D plane, while showing dynamically generated data in 3d?
– Diego
Sep 25 '13 at 18:14
how can I just project the image on the 2D plane, while showing dynamically generated data in 3d?
– Diego
Sep 25 '13 at 18:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3719502%2fhow-can-i-plot-an-image-jpg-in-matlab-in-both-2-d-and-3-d%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown