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

how to convert a double image into unit8 in matlab

Asked by maha lakshmi on 5 Feb 2013

how to convert a double image into unit8 in matlab

0 Comments

maha lakshmi

Products

No products are associated with this question.

3 Answers

Answer by Walter Roberson on 5 Feb 2013
uint8(TheImage .* 255)

0 Comments

Walter Roberson
Answer by Jan Simon on 5 Feb 2013
Edited by Jan Simon on 5 Feb 2013

0 Comments

Jan Simon
Answer by Image Analyst on 5 Feb 2013

It really depends on how you want to do it, and if you have values outside the 0-1 range. I'll just add a third method: mat2gray(). Now, look at this demo and see how Walter's suggestion, Jan's suggestion, and mat2gray() produce 3 different uint8 matrices:

m = 5*rand(4)
maxValue = max(m(:));
m8a = round(255*m/maxValue)
m8b = im2uint8(m)
m8c = uint8(255*mat2gray(m))
m =
      0.48227        2.876        4.106       3.2456
      0.65987       0.2989     0.077017       3.6586
       4.7103       1.1739      0.21512       3.2387
       4.7807       1.7658      0.84495       2.2546
m8a =
    26   153   219   173
    35    16     4   195
   251    63    11   173
   255    94    45   120
m8b =
  123  255  255  255
  168   76   20  255
  255  255   55  255
  255  255  215  255
m8c =
   22  152  218  172
   32   12    0  194
  251   59    7  171
  255   92   42  118

So, now, which way would you like to do it?

0 Comments

Image Analyst

Contact us