Path: news.mathworks.com!not-for-mail
From: "Hui Song" <john.doe.nospam@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: HELP reading JPG and plotting image in 3D
Date: Tue, 18 Mar 2008 12:08:01 +0000 (UTC)
Organization: Fundan University
Lines: 43
Message-ID: <frobb1$rg7$1@fred.mathworks.com>
References: <Pine.LNX.4.64.0803171321000.23534@tsunami.ocean.washington.edu>
Reply-To: "Hui Song" <john.doe.nospam@mathworks.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205842081 28167 172.30.248.37 (18 Mar 2008 12:08:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 18 Mar 2008 12:08:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 222374
Xref: news.mathworks.com comp.soft-sys.matlab:457804


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