matlab - Combine a (m x n x p) matrix (image) of 8 bit numbers to a (m x n) matrix of 24 bit numbers and vice versa -
say there matrix of (m x n x p), esp. color image r g , b channel. each channel information 8-bit integer.
but, analysis, 3 8-bit values have combined 24-bit value , analysis done on (m x n) matrix of 24-bit values.
after analysis, matrix has decomposed 3 8-bit channels displaying results.
what doing right now:
- iterating through values in matrix
- convert each decimal value binary (using
dec2bin
) - combine 3 binary values 24-bit number (using
strcat
,bin2dec
)
code:
i=1:m j=1:n new_img(i,j) = bin2dec(strcat(... sprintf('%.8d',str2double(dec2bin(img(i,j,1)))), ... sprintf('%.8d',str2double(dec2bin(img(i,j,2)))), ... sprintf('%.8d',str2double(dec2bin(img(i,j,3)))))); end end
for decomposition 3 8-bits after analysis, exact reverse process done, still iterating through (m x n) values.
the problem huge computation time.
i know not correct way of doing this. there matrix operation can achieve computation done quickly?
although don't understand why you'd "combine" rgb planes way, this'll you're looking in 1 command.
a = bitshift(img(:,:,1),16)+... bitshift(img(:,:,2,8)+... img(:,:,3);
and invert process requires binary masking in addition shifting right.
a=zeros(size(img)); a(:,:,1)=bitshift(a,-16); a(:,:,2)=bitshift(bitand(a,2^16-2^8),-8); a(:,:,3)=bitand(a,2^8-2^0);
Comments
Post a Comment