How I Can read 3 MSBs in RGB image
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
DGM
on 2 Jan 2022
Edited: DGM
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Feature Detection and Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!