## how to superimpose a surface plot on a different size gray scale image

### Huayan Wang (view profile)

on 14 Feb 2018
Latest activity Commented on by Huayan Wang

on 15 Feb 2018

### Walter Roberson (view profile)

I have a grayscale image which has a size of 2448*2048.
I have a surface plot on a mesh grid of (1:110, 1:92)
Their data numbers are totally different. How can I make the grayscale image as the background and make the surface fit right onto it and transparent so that I can see the background image through the surface plot at the same I can still draw ROI on the surface plot with the roipoly function?

### Walter Roberson (view profile)

on 14 Feb 2018

Look at the XData and YData parameters of image(): you can specify the coordinates of the centers of the bottom left and upper right pixels. Getting them to line up exactly with the boundaries of (for example) 1:110 is a bit of a nuisance because you have to account for the 1/2 pixel, which will be 1/2448/2 or 1/2048/2 of the image, but you can do it (but it's usually easier to just let half a pixel hang outside the surf plot.)
When you create the surf() plot, you will probably want to use 'edgecolor', 'none'. Make it transparent by passing in 'AlphaData', such as .8 .

Huayan Wang

### Huayan Wang (view profile)

on 14 Feb 2018
Hi Walter,
Thank you for your answer. This helps me most of the part. Only one thing I didn't expect.
You can refer to the attached image.
This left one is a surface plot, the middle one is a grayscale image. I plot them into one figure and got the right one.
The problem is that I have some negative value point on the surface plot. It looks like that the grayscale image will cover the negative value. I want all surface plot is above of the background image.
Is there a way to do that?
Thank you!
Walter Roberson

### Walter Roberson (view profile)

on 14 Feb 2018
All points in the image() are considered to have Z of 0, so Z below 0 on the surface plot would be "behind" the image.
You should consider using
surf(X, Y, ones(size(Z)), Z)
so that your Z data gets interpreted as "color" and so MATLAB thinks your surface is at 1 (and thus "above" your image.)
Huayan Wang

### Huayan Wang (view profile)

on 15 Feb 2018
This works very well, exactly what I want.
Thank you so much!