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

New to MATLAB?

Thread Subject:
Display Image + Mesh like Contourslice

Subject: Display Image + Mesh like Contourslice

From: Sean de

Date: 17 Nov, 2010 19:42:04

Message: 1 of 2

Hey all,

I have been trying to find away to do this but haven't come up with a successful solution.
I have a grayscale 8bit image, and a mesh corresponding to calculated values from parts of the image.

I would like to be able to show the image and the mesh in a 3D plot so that the image is on the bottom and the mesh hovering a few slices above it. The image should remain in grayscale if possible and the mesh should be in a pretty color map.

So the locations would be like this in
contourslice(V,[],[],[1 50])
where the slice at 1 is the image as it would be with imshow
and the slice at 50 is a mesh as it would be with mesh. If it can't be a full mesh, a contour would work too.

Thank you!

Subject: Display Image + Mesh like Contourslice

From: Sean de

Date: 18 Nov, 2010 19:26:05

Message: 2 of 2

I figured out the solution to this problem. For anyone else looking here is a small demo. It requires the IPT for the sample image.

%SCd 11/18/2010

%Sample image (IPT stock)
I = imread('cameraman.tif');
%2x2x2 required for SLICE
I = repmat(I,[1 1 2]);

%Sample Mesh
meshdata = rand(256,256)*100+100;
%Set a small window to NaN to check alignment visually
meshdata(30:100,30:100) = nan;

H(1) = slice(double(I),[],[],1);
set(H(1),'EdgeColor','none') %required so image isn't just an edge
hold on
H(2) = mesh(meshdata);
hold off
axis vis3d
axis ij
axis tight

%make colormap
cm = [gray(256);jet(256)];

%For a demo on this part please see:

%Slice were using isolation and statistics
im = double(I(:,:,1));
im_min = min(im(:));
im_max = max(im(:));

%Map size for each part
MPsz = 256;

%Image ranges (1:256 for uint8)
im_idx = ceil(min(MPsz,round((MPsz-1)*(im-im_min)/(im_max-im_min))+1));

%Update CData
caxis([1 512])

Tags for 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