How can I plot an image (.jpg) in MATLAB in both 2-D and 3-D?












16















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.










share|improve this question





























    16















    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.










    share|improve this question



























      16












      16








      16


      8






      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 29 '12 at 10:56









      Amro

      116k19209389




      116k19209389










      asked Sep 15 '10 at 15:58









      dewalladewalla

      69981542




      69981542
























          1 Answer
          1






          active

          oldest

          votes


















          34














          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


          alt text






          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');


          alt text



          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.






          share|improve this answer


























          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          34














          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


          alt text






          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');


          alt text



          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.






          share|improve this answer


























          • 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
















          34














          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


          alt text






          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');


          alt text



          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.






          share|improve this answer


























          • 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














          34












          34








          34







          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


          alt text






          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');


          alt text



          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.






          share|improve this answer















          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


          alt text






          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');


          alt text



          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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



















          • 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




















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine