how can I read and extract the 2 LSBs of every byte from the RGB image array ?

4 ビュー (過去 30 日間)
Abduellah Elbakoush
Abduellah Elbakoush 2021 年 12 月 26 日
回答済み: yanqi liu 2021 年 12 月 27 日
i want to read the 2 LSbs of every byte for exaple i want to read (00) from this byte (11111100) for the whole of the image

採用された回答

yanqi liu
yanqi liu 2021 年 12 月 27 日
clc; clear all; close all;
img = imread('cameraman.tif');
img2 = blockproc(img,[1 1],@sp);
figure; imshowpair(img,img2,'montage')
function y=sp(x)
% every byte
x2 = dec2bin(x.data);
% 2 LSB of every byte
y=bin2dec(x2(end-1:end));
end

その他の回答 (1 件)

Voss
Voss 2021 年 12 月 26 日
One way is to read the data as bytes (type uint8) like usual, then the 2 LSBs are the remainder after dividing by 4, e.g.:
b = uint8(0:255)
b = 1×256
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
r = rem(b,4)
r = 1×256
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1
s = dec2bin(r)
s = 256×2 char array
'00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11' '00' '01' '10' '11'
a = s-'0'
a = 256×2
0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by