how to convert a double image into unit8 in matlab

1 view (last 30 days)
how to convert a double image into unit8 in matlab

Answers (3)

Image Analyst
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?

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

Jan
Jan on 5 Feb 2013
Edited: Jan on 5 Feb 2013

Categories

Find more on Convert Image Type 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!