convert 2d image to 3d
Show older comments
my requirement is I have to read two images and should compare the two images in terms of deformation.let me elaborate my question so that I can get a brief answer.For example there are two images say car I want to find the difference in terms of deformation.
I tried
a=imread();
surf(double(a));
shading flat;
but i am getting Warning: Matrix dimensions must agree, not rendering mesh
2 Comments
Adam
on 5 Nov 2014
Is this supposed to be a comment on another question? If it is a question in its own right it needs a bit more information since you clearly seem to be responding to an answer by 'Chad' to some previous question.
sivaramakrishna
on 5 Nov 2014
Answers (2)
Image Analyst
on 5 Nov 2014
0 votes
You can't use surf() with a color image. Extract just one color channel or use rgb2gray() on it to convert (the badly-named) "a" to gray scale.
Mike Garrity
on 5 Nov 2014
I'm just guessing, but you would get that error message if your image was truecolor. In that case, a would be a MxNx3 variable with red, green, and blue values for each pixel. The surf command wants to display a single value as the height. It doesn't know what to do with 3 values.
If that's the case, then you need to convert the RGB triplets into a scalar value. For example:
surf(rgb2gray(a,3))
Once you've done that, you can use the RGB values as CData on the surface, just not as ZData. So you could do something like this:
a = imread('street1.jpg');
surf(rgb2gray(a,3),a,'EdgeColor','none')
Which would let you see the colors of your image on the surface, like this:

2 Comments
sivaramakrishna
on 6 Nov 2014
Mike Garrity
on 6 Nov 2014
Well, I don't have a lot of info about what you're doing, but my guess was that you were trying to create a surface for each of two different images so that you could see the differences in where the bright & dark areas are. If so, it would look something like this:
img1 = imread('street1.jpg');
img2 = imread('street2.jpg');
surf(rgb2gray(img1),'EdgeColor','none','FaceColor','red');
hold on
surf(rgb2gray(img2),'EdgeColor','none','FaceColor','blue');
camlight

The idea is that each of the two calls to rgb2gray turns one of the RGB images into a scalar. Then the two calls to surf each turn one of these 2D scalar images into a surface.
I don't know whether I think it's a very effective visualization though. It might be in some use cases. I don't think that it's very helpful for the images I used here.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!