I have a bunch of depth map images which are all png files. I need to use these in matlab. When I use imread, I get the image to have the following dimensions, h*w*3. Since it is a depth map, I think it should have only h and w but since it is in .png format, I think the 3rd dimension is included. How do I convert this back to 2 dimensions? Can I use rgb2gray? Is that sensible and why?
Asked
Active
Viewed 1,250 times
0
-
If the 3 components of each pixel have the same value, `rgb2gray` should return that same value. – Mark Ransom Apr 07 '15 at 16:41
1 Answers
0
It has a 3rd dimension probably because your image is True Color or RGB image.
As Mark Ransom say, if you do rgb2gray
it will give the same picture but as 2D, only if all the 3 components are same. (i.e) only if a gray image is stacked three times as *.png
, and if you do rgb2gray
you will obtain the same image without any change but as a 2 Dimension.
Read this answer and this and this.

Community
- 1
- 1

Santhan Salai
- 3,888
- 19
- 29