0

I want to understand how mat2gray works? I mean back end work and formula etc. then I want to scale the image using it so that it follows the format, 0 for max value and 255 for min value.

Anyone, please suggest me a formula to convert uint16 depth image in the range 0 to 255.but 0 for max value of depth and 255 for min value of depth

Thanks

Mayank
  • 353
  • 6
  • 20

1 Answers1

0

If you want to know how mat2gray works, you can open the function file within MATLAB by highlighting the function name and pressing Ctrl+D, which will open the file in the MATLAB editor so you can view the source code (side note: this doesn't work with all MATLAB functions, as a lot are "built-in" functions).

To change the image as you're requesting, you'd simply do the following:

I = (1-I)*255;
MrAzzaman
  • 4,734
  • 12
  • 25
  • can u explain how u r formula will work ? since my image is uint16.. its range is 0 to 65536.but my camera depth value range is 0 to 8000. now i want to map it in 0 to 255 range and mapping as 0 for maxVal and 255 for minVal – Mohammad Yakub Jul 10 '17 at 09:16
  • If you use `mat2gray`, it normalizes the matrix to between 0-1, with the max being at 1 and the min at 0. You can invert this by doing `1-I`, and then scale it to 0-255 by multiplying by 255. – MrAzzaman Jul 10 '17 at 10:36