im2uint8 only generates 0 or 255

1 visualización (últimos 30 días)
Hadi Ghahremannezhad
Hadi Ghahremannezhad el 10 de Feb. de 2021
Comentada: Hadi Ghahremannezhad el 11 de Feb. de 2021
I am trying to present an image of class double using imshow.
suppose this is the image:
a = [78.4630409671845,90,0;
78.4630409671845,36.8698976458440,62.5135737496187;
0,0,0]
now when I try to convert it to uint8 in order to show it, this is what I get:
b = im2uint8(a) = [255,255,0;
255,255,255;
0,0,0]
but I expect something like this:
b = [78,90,0;
78,37,63;
0,0,0]
so the imshow command shows a weird black an white image:
imshow(a);
imshow(a,[]);
imshow(b);
imshow(b,[]);
How can I properly present a double image?

Respuesta aceptada

Jan
Jan el 10 de Feb. de 2021
Editada: Jan el 10 de Feb. de 2021
im2uint8 expects the input to be an RGB image, which is a 3D array with values from 0 to 1. So normalize your data at first by dividing by 255:
a = [78.4630409671845,90,0;
78.4630409671845,36.8698976458440,62.5135737496187;
0,0,0]
im2uint8(a / 255)
  2 comentarios
Steven Lord
Steven Lord el 11 de Feb. de 2021
Or even more simply, just call uint8 on it.
a = [78.4630409671845,90,0;
78.4630409671845,36.8698976458440,62.5135737496187;
0,0,0];
aJan = im2uint8(a / 255)
aJan = 3×3
78 90 0 78 37 63 0 0 0
aSteve = uint8(a)
aSteve = 3×3
78 90 0 78 37 63 0 0 0
Hadi Ghahremannezhad
Hadi Ghahremannezhad el 11 de Feb. de 2021
@Steven Lord thanks. this worked great.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by