Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
HELP reading JPG and plotting image in 3D

Subject: HELP reading JPG and plotting image in 3D

From: Skip Albertson

Date: 17 Mar, 2008 20:31:30

Message: 1 of 3

Can anyone tell me the best way to read an image:

A=imread('pic.jpg');

and then plot it in a 3D space specifying the vertices.

If my workspace has x:0-100, y:0-100, and z:0-100 and I want to paste my
JPEG image so that the corners are placed at:

lower left: x=25, y=25, z=0
upper left: x=25, y=25, z=100
upper right: x=75, y=75, z=100
lower right: x=75, y=75, z=0

view(3)

How would I best do that?

Thanks!

Subject: HELP reading JPG and plotting image in 3D

From: Hui Song

Date: 18 Mar, 2008 12:08:01

Message: 2 of 3

Skip Albertson <alberts@ocean.washington.edu> wrote in
message
<Pine.LNX.4.64.0803171321000.23534@tsunami.ocean.washington.edu>...
> Can anyone tell me the best way to read an image:
>
> A=imread('pic.jpg');
>
> and then plot it in a 3D space specifying the vertices.
>
> If my workspace has x:0-100, y:0-100, and z:0-100 and I
want to paste my
> JPEG image so that the corners are placed at:
>
> lower left: x=25, y=25, z=0
> upper left: x=25, y=25, z=100
> upper right: x=75, y=75, z=100
> lower right: x=75, y=75, z=0
>
> view(3)
>
> How would I best do that?
>
> Thanks!
>
>
Hi John,
Not easy. Try this:
vertice1 = [25 25 0]; % start vertice
vertice2 = [75 75 100] ; % end vertice
imHeight = vertice2(3) - vertice1(3) ; % height
imWidth = norm(vertice1(1:2)-vertice2(1:2)) ; % width
x = linspace(vertice1(1), vertice2(1), imWidth) ;
X = repmat(x, imHeight, 1) ; % create plane mesh
y = linspace(vertice1(2), vertice2(2), imWidth) ;
Y = repmat(y, imHeight, 1) ; % create plane mesh
z = linspace(vertice1(2), vertice2(2), imHeight) ;
Z = repmat(z', 1, imWidth) ; % create plane mesh
[C, map] = imread('canoe.tif') ; % read image
h = surface(X, Y, Z) ; % create a surace
set(h, 'CData', flipud(C), 'FaceColor','texturemap',
'EdgeColor','none','CDataMapping','direct') ; % image as
colormap(map) ;
view(30, 30) ;

Subject: HELP reading JPG and plotting image in 3D

From: Vihang Patil

Date: 18 Mar, 2008 12:34:01

Message: 3 of 3

Skip Albertson <alberts@ocean.washington.edu> wrote in
message
<Pine.LNX.4.64.0803171321000.23534@tsunami.ocean.washington
.edu>...
> Can anyone tell me the best way to read an image:
>
> A=imread('pic.jpg');
>
> and then plot it in a 3D space specifying the vertices.
>
> If my workspace has x:0-100, y:0-100, and z:0-100 and I
want to paste my
> JPEG image so that the corners are placed at:
>
> lower left: x=25, y=25, z=0
> upper left: x=25, y=25, z=100
> upper right: x=75, y=75, z=100
> lower right: x=75, y=75, z=0
>
> view(3)
>
> How would I best do that?
>
> Thanks!
>
>

Try this

load clown
C = X;
X = [0 0; 1 1];
Y = [1 1; 1 1];
Z = [0 1; 0 1];
surface(X,Y,Z,rot90(flipud
(C)),'FaceColor','texturemap','EdgeColor','none','CDataMapp
ing','direct')
view(3)
colormap(map)
cameratoolbar
set(gcf,'color','k');
axis off;
axis vis3d;


HTH
Vihang

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us