## how to convert a double image into unit8 in matlab

### maha lakshmi (view profile)

on 5 Feb 2013

how to convert a double image into unit8 in matlab

## Products

No products are associated with this question.

### Walter Roberson (view profile)

on 5 Feb 2013

```uint8(TheImage .* 255)
```

### Jan Simon (view profile)

on 5 Feb 2013
Edited by Jan Simon

on 5 Feb 2013

### Image Analyst (view profile)

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?

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi