1
$\begingroup$

I need to visualize one image in two intersecting planes. The attached picture shows an example of what I want to do. However, it uses an equation: (V = X.*exp(-X.^2-Y.^2-Z.^2);) , while I want to insert my image instead.

[X,Y,Z] = meshgrid(-2:.2:2);
V = X.*exp(-X.^2-Y.^2-Z.^2);
xslice = 0;   
yslice = [];
zslice = 0;
slice(X,Y,Z,V,xslice,yslice,zslice)
$\endgroup$
3
  • $\begingroup$ where is the attached picture? $\endgroup$ Commented Jan 12, 2023 at 9:26
  • $\begingroup$ what do you mean by 'insert .. image'? the example provided is a 3D potential or field amplitude that is being sliced with 2 perpedicular planes. Do you mean you need to replace the V=X.*exp.. expression with another expression? or what you are really after is to print a 2D custom image on one of the slicing planes? $\endgroup$ Commented Jan 12, 2023 at 9:32
  • $\begingroup$ Thank you for your comment. The code draws two squares in two perpendicular planes. I want to replace the squares with my image. I want to attach a picture showing exactly what I want but I do not see how to do it. If you want I can send it to you via your email. Thanks again $\endgroup$ Commented Jan 13, 2023 at 14:51

1 Answer 1

2
$\begingroup$

command warp has an example showing how to print an custom impage on an arbitrary surface, have a look here

This is the example :

1.- Load the custom image

[I,map] = imread('custom_image.tif');

These are all the image formats that can be loaded with imread

.bmp .jpeg .png .cur .ppm .gif .pbm .ras .hdf4 .pcx .tiff .ico .pgm .xwd

imread further details available here

2.- Define the surface

[X,Y] = meshgrid(-100:100,-80:80);
Z = -(X.^2 + Y.^2);

3.- Print any image on any surface generated with warp

figure
warp(X,Y,Z,I,map);

4.- Print any image on any surface generated with surf

I2=imread('forest2.jpg');
figure
imshow(I2)

enter image description here

I3r=imresize(I2(:,:,1),size(X));
I3g=imresize(I2(:,:,2),size(X));
I3b=imresize(I2(:,:,3),size(X));

I3=zeros([size(X) 3]);
I3(:,:,1)=I3r;I3(:,:,2)=I3g;I3(:,:,3)=I3b;
I3=uint8(I3);

I3map=[I3r(:) I3g(:) I3b(:)];

figure
hs=surf(X,Y,Z)
hs.EdgeColor='none'
hs.CData=I3

enter image description here

5.- How to define planes in MATLAB

Read my answer here to a question how to define planes. You will learn :

  • how to define the plane containing all 3 points

  • how to define planes including any of 2 of the 3 input points

  • how to define the perpendicular plane including 2 of the 3 input points, and

  • how to define any of the possible perpendicular planes including 1 of the input points

$\endgroup$
2
  • $\begingroup$ Thank you, Jhon. I really appreciate your help. The problem warp requires the DSP or image processing toolboxes which I do not have. Is there a way to go around? Thank you $\endgroup$ Commented Jan 14, 2023 at 19:20
  • $\begingroup$ I have added a way to print any image on any surface generated with command surf. One has to cast type uint8 to the image so that the range [0 255] is correctly accepted as colour range. You also use colormaps, a 2D colormap to the handle of surf, instead of RGB. $\endgroup$ Commented Jan 15, 2023 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.