The maximum value is not changing even after adding 1
Afficher commentaires plus anciens
I have an image with values ranging from [0,255]
It's data is attached below as data.mat below.
I read it and added 1 to its data.
The minimum value of data is changed to 1, but the maximum value of data is still 255.
I don't understand why.
Réponse acceptée
Plus de réponses (1)
The reason is quite simple, your data is stored as an "uint8" which stands for "unsigned integers in 8 bit". The range of acceptable values for that type is from 0 to 255, which makes it ideal to store image data.
y = uint8(255)
y = y+1
x = uint8(243);
x = x+1
This is simply a way that MATLAB handles it. If you were to do the same in C, there will be an integer overflow and the value is changed to "0" instead. MATLAB protects this integer overflow and hence retains the value of 255.
1 commentaire
Palguna Gopireddy
le 14 Juin 2024
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!