Effacer les filtres
Effacer les filtres

Always getting 255 while adding.

10 vues (au cours des 30 derniers jours)
Sneha
Sneha le 17 Jan 2018
Commenté : Sneha le 17 Jan 2018
I had a matrix of Red values of an image R of size 65536*1 and i had 3 integer values RR(1),GG(1) and BB(1). I need to add R(1)+GG(1)+BB(1) to get new RR(2). Similarly for the other two. But while am doing Rcomponent = R(1)+GG(1)+BB(1); its showing 255 always. [here R(1) = 68 , GG(1) = 173 , BB(1) = 147] Please help me with this. R matrix is of uint8.
  1 commentaire
Greg
Greg le 17 Jan 2018
Hint: What's the maximum value a uint8 can hold? What happens when you exceed that value?

Connectez-vous pour commenter.

Réponse acceptée

James Tursa
James Tursa le 17 Jan 2018
All of the integer types clip resulting values at both ends. So for uint8 it clips the lower end at 0 and the upper end at 255. You can convert to double first if you want to see what you are apparently expecting. E.g.,
Rcomponent = double(R) + double(GG) + double(BB);
  1 commentaire
Sneha
Sneha le 17 Jan 2018
Got it. Thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by