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 30 31 32 33 34 35 36 37 38 39
|
clear all
clc
nRows = 600;
nColumns = 600;
MatriceDeImage = randi([48 49], nRows*nColumns, 24);
MatriceDeImage = char(MatriceDeImage);
tic
r = uint8(reshape(bin2dec(MatriceDeImage(:,1:8)), nRows, nColumns));
g = uint8(reshape(bin2dec(MatriceDeImage(:,9:16)), nRows, nColumns));
b = uint8(reshape(bin2dec(MatriceDeImage(:,17:24)), nRows, nColumns));
img1(:,:,1) = r;
img1(:,:,2) = g;
img1(:,:,3) = b;
toc
tic
power2 = 2.^(7:-1:0).';
img2 = zeros(nRows, nColumns, 3, 'uint8');
img2(1:nRows*nColumns) = (MatriceDeImage(:,1:8)-48)*power2;
img2(nRows*nColumns+1:2*nRows*nColumns) = (MatriceDeImage(:,9:16)-48)*power2;
img2(2*nRows*nColumns+1:end) = (MatriceDeImage(:,17:24)-48)*power2;
toc
all(img1(:)==img2(:))
figure(1)
clf
subplot(211)
imagesc(img1);
subplot(212)
imagesc(img2); |
Partager