how to convert the pixel values of the image in the range of (0-255) into (0-1)?
Afficher commentaires plus anciens
Hi i have to convert the image pixel values in the range of (0-255) into (0-1) Is there any function or program available?
Réponses (3)
Azzi Abdelmalek
le 28 Fév 2013
Modifié(e) : Azzi Abdelmalek
le 28 Fév 2013
im1=imread('yourfile');
b=linspace(0,1,255);
im2=arrayfun(@(x) b(x+1),im1)
4 commentaires
Jan
le 28 Fév 2013
Again I would definitely avoid the slow array fun, because a lookup table method can be solved directly much faster:
im2 = b(im1 + 1);
Azzi Abdelmalek
le 28 Fév 2013
I've tried this, it works only for mxn array, for jpg (mxnx3) array, it does not work.
Jan
le 28 Fév 2013
Surprising. Then I'd suggest:
im2 = reshape(b(im1(:) + 1), size(im1));
But this looks less attractive, of course. Anyway, it is still faster.
Azzi Abdelmalek
le 28 Fév 2013
Modifié(e) : Azzi Abdelmalek
le 28 Fév 2013
Surprising. You are right, I messed up, in fact I've tried b(im) instead of b(im+1), did not even read the error message, thinking it was caused by the matrix dimension. im contains 0 that causes the error. b(im1) worked for a tif image that does not contains a 0
imageUINT8 = randi([0, 255], 640, 480);
imageDOUBLE = image / 255;
Image Analyst
le 28 Fév 2013
Yes, there is a built-in function. It is called mat2gray().
normalizedImage = mat2gray(grayLevelImage);
Catégories
En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!