Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab rgb values dilemma

Tags:

matlab

When i wrote these commands

out = ones(size(ben))
imshow(out)

the output is a white picture but i expect almost dark picture because the rgb values are 1,1,1. when i give 255,255,255 it also gives a white picture. Isn't this a dilemma ?

like image 833
kml_ckr Avatar asked Jan 02 '26 08:01

kml_ckr


1 Answers

Try out = ones(size(ben), 'uint8');

ones() by default creates an array of doubles. When imshow() gets an array of doubles it assumes that the pixel values range between 0 and 1, and assigns the white color to anything greater than 1. However, if you pass an array of uint8 to imshow() it will assume the range to be between 0 and 255.

You can also try using imagesc(); instead of imshow(), but you may need to do colormap gray after wards to get a grayscale image.

Another alternative is to rescale the image before display:

imshow(out / max(out(:)));
like image 130
Dima Avatar answered Jan 04 '26 04:01

Dima



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!