Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

plotting 2D image in a 3D plot

661 views
Skip to first unread message

dormant

unread,
Sep 12, 2008, 7:18:03 PM9/12/08
to
I'm going mad because I am sure it is easy to do what I want to do, but I can't find any clues in the docs how to do it.

I have a set of geographic data - lat long and height. But the area is restricted enough that I can plot as x y and z without any projection.

I want to plot them in a 3-D plot, with a 2-D image plotted on the XY plane. The 2D image is a geotiff file, so can be used with all the mapping functions.

Any suggestions would be welcomed.


Alan B

unread,
Sep 12, 2008, 7:30:05 PM9/12/08
to
If you're trying to use image or imagesc, and then calling 3D plot functions afterward, that won't work. Use surf or pcolor instead. If that isn't the problem you're having, you might need to explain a little more specifically.

"dormant " <rod.s...@uwiseismic.com> wrote in message <gaetba$hql$1...@fred.mathworks.com>...

dormant

unread,
Sep 12, 2008, 10:26:02 PM9/12/08
to
Sorry I can't be specific, because I am really floundering trying to understand handle graphics.

What I want to do is something like this (which doesn't work).

---------------------------------------
imfile = 'nasa-e-carib.tif';
[A, R, bbox] = geotiffread( imfile );
mapshow(A, R);
hold on;
plot3( X, Y, Z, ...
'o', ...
'LineStyle', 'none', ...
'MarkerEdgeColor', [.5 .5 .5], ...
'MarkerFaceColor', [ .7 .7 .7], ...
'MarkerSize', 4 );
view(-35,45);
----------------------------------------

even the following doesn't work

----------------------------------------
imfile = 'nasa-e-carib.tif';
[A, R, bbox] = geotiffread( imfile );
mapshow(A, R);
view(-35,45);
----------------------------------------

Steven Lord

unread,
Sep 15, 2008, 10:38:31 AM9/15/08
to

"dormant " <rod.s...@uwiseismic.com> wrote in message
news:gaf8bp$k7p$1...@fred.mathworks.com...

> Sorry I can't be specific, because I am really floundering trying to
> understand handle graphics.

*snip*

Then don't explain using Handle Graphics. Explain using plain old English
text. Alternately, if you have code that's doing something close to what
you want, indicate what it's doing that's different from what you want.

> ---------------------------------------
> imfile = 'nasa-e-carib.tif';
> [A, R, bbox] = geotiffread( imfile );
> mapshow(A, R);
> hold on;
> plot3( X, Y, Z, ...

Since you're using a map axes, I think you want PLOT3M instead of PLOT3.

*snip*

> even the following doesn't work
>
> ----------------------------------------
> imfile = 'nasa-e-carib.tif';
> [A, R, bbox] = geotiffread( imfile );
> mapshow(A, R);
> view(-35,45);
> ----------------------------------------

Clarify what "doesn't work" means. Does it error? Does it crash MATLAB?
Does it format your hard drive? Does it work but give you a figure that
doesn't look the way you want (and if so, how specifically does it look
different from how you want?)

--
Steve Lord
sl...@mathworks.com


dormant

unread,
Sep 16, 2008, 10:09:02 PM9/16/08
to
Steve,

Apologies if I am not clear. I thought I was being clear.

> Since you're using a map axes, I think you want PLOT3M instead of PLOT3.

I am plotting using mapshow which has no projection, so plot3 is the correct thing to use.

The following MATLAB code does not give me what I want. It plots the points using plot3 correctly, but does not plot the image on the Z=0 plane. The resulting plot is exactly the same if the last line is removed.

plot3( X, Y, Z, 'o', ...


'LineStyle', 'none', ...

'MarkerEdgeColor', 'r', ...
'MarkerFaceColor', 'r', ...
'MarkerSize', 3 );
set( gca, 'XLim', [ -72 -54 ], ...
'YLim', [ 9 24 ], ...
'ZLim', [-300 0] );
grid on;
view(-35,45);
hold on;


[A, R, bbox] = geotiffread( imfile );

mapshow( A, R, );

If I replace the last two lines with the following, the resulting plot does show what I want - it draws the coastlines on the Z=0 plane.

load coast;
mapshow( long, lat );

It appears to me that mapshow doesn't like plotting images at an angle - this can be demonstrated by using it on its own, then using the "Rotate 3D" tool in the figure window. the image disappears as soon as the view moves away from the perpendicular.

dormant

unread,
Sep 23, 2008, 1:36:02 PM9/23/08
to
I solved this problem by using geoshow instead of mapshow.

Joachim

unread,
Jul 23, 2013, 1:03:10 PM7/23/13
to
Hello,

As I could not find a solution by myself, I want to ask if someone can give me some hints how to resolve the following issue:

In a 3D plot it is possible to display 2D projections as (filled) contour plots by assigning the result of the function contourf to a graphics handle, as in the following matlab code fragment:

[~,h2]=contourf(w1,w3,sz,level_list2,'LineWidth',1);
h2=findobj(h2,'type','patch');
for j=1:length(h2),
zd=w5(1).*ones(size(get(h2(j),'XData')));
set(h2(j),'ZData',zd);
end
set(h2,'FaceLighting','none');

The arguments w1 and w3 of the function contourf define the x- and y-axis of the 3D plot, while sz contains the projection of the three-dimensional data set onto the (x,y)-plane.

However, as I want to use a specific color encoding for the 2D projection, a (filled) contour plot doesn't seem to be the appropriate solution.
Rather, the 2D projection is given as a RGB image after applying the procedure for the desired color encoding.
As it was pointed out in a previous thread (http://www.mathworks.com/matlabcentral/newsreader/view_thread/235957), two-dimensional images cannot be included in a 3D plot by using the function "image". Also the suggested solution to use the functions "mapshow" or "geoshow" did not work: when I called

mapshow(w1,w3,image(w1,w3,sz));

or

geoshow(w1,w3,image(w1,w3,sz));

a 2D plot was shown separately, but it was not taken as a coordinate plain within the 3D plot.

Is there any other approach I could try?

Best regards,

Joachim

Joachim

unread,
Jul 24, 2013, 5:34:10 AM7/24/13
to
update:

Now I tried

[~,h2]=mapshow(w1,w3,szIndexedImage,hsv);
h2=findobj(h2,'type','patch');
for j=1:length(h2),
zd=w5(1).*ones(size(get(h2(j),'XData')));
set(h2(j),'ZData',zd);
end
set(h2,'FaceLighting','none');

where w1 and w3 define the x- and y-axis of the 3D plot,
the indexed image szIndexedImage is obtained from the rgb image szRGBimage via

szIndexedImage=rgb2ind(szRGBimage,hsv);

and hsv is the HSV color map.

Running the program leads to the eroor message

Error in mapshow (line 214)
error(nargchk(1,Inf,nargin,'struct'))

Output argument "varargout" (and maybe others) not assigned during call to
"/usr/local/MATLAB/R2012a/toolbox/map/map/mapshow.m>mapshow".

Does anyone have an idea how to resolve this issue?

Best regards,

Joachim
0 new messages