How to convert image from double to uint8 in matlab? -


i have image i of type double. want convert image double uint8. have tried using both:

  1. i=uint8(i)
  2. i=im2uint8(i).

when use imshow(i) command, black image , nothing else. doing wrong?

the im2uint8 function assumes double image scaled range [0,1]. if image has values larger 1 or smaller 0, these values clipped. see following example:

im2uint8([-1 0 0.5 1 2]) ans =     0    0  128  255  255 

the solution scale input image [0,1] subtracting minimum value , dividing total range:

i = (i - min(i(:))) / (max(i(:)) - min(i(:))); = im2uint8(i); imshow(i); 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -