How I Can read 3 MSBs in RGB image
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
e.g the Bit in image is 250 =11111010
I want to red the 3 bits of Most Significit bit =111
How I can do that
0 commentaires
Réponse acceptée
DGM
le 2 Jan 2022
Modifié(e) : DGM
le 2 Jan 2022
Depends what you want the output to be. It might be simple for scalar inputs:
% assume uint8
pixel = uint8(250);
% using dec2bin() to get a character vector
binarypixel = dec2bin(pixel)
msb3 = binarypixel(1:3)
% using bitget() to get a logical vector
msb3_2 = bitget(pixel,8:-1:6)
... but array inputs will need to be handled differently.
% if you want to get bit planes of an array, you can use bitget()
bit8 = bitget(pixel,8)
bit7 = bitget(pixel,7)
bit6 = bitget(pixel,6)
% or just use basic math
bit8 = mod(pixel,256)>=128
bit7 = mod(pixel,128)>=64
bit6 = mod(pixel,64)>=32
Pay attention to the output class and scaling here. Bitget() is returning a uint8() output, while the latter is returning actual logical outputs.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Display and Exploration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!