How I Can read 3 MSBs in RGB image
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
DGM
il 2 Gen 2022
Modificato: DGM
il 2 Gen 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Feature Detection and Extraction in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!