Block Truncation Coding (BTC):
To my knowledge, BTC is the simplest approach to perform image compression.
BTC- Implementation:
As provided in its title, BTC perform compression in a block wise manner.
Referring to the figure, each block is MxN size, then for each block mean, a and b are computed (please check the paper to find out the formula for 'a' and 'b')
To perform compression, each pixel in the block is thresholded with the block mean value
IF the pixel > mean, then it is assigned 1
ELSE the pixel is assigned 0
This output is termed as the bitmap image.
While transmitting, the bit map image along with it 'a' and 'b' are transmitted.
If suppose the block size is 8x8, and for a typical 8-bit image
Original image = 8x8x8= 512 bits
BTC image: Bitmap=8x8x1=64 bits
'a' and 'b'= 16 bits
Total= 80 bits
Decoding stage: The original image is reconstructed by substituting the bitmap image as follows
'1' is replaced with high mean 'a' and '0' with low mean 'b'
Note: It is important to note that, a) BTC is a lossy compression i.e. we lose some information
b) The maximum compression ratio is 8
c) The compression ratio increase with block size, but it also cause block artifacts and poor image quality.
To my knowledge, BTC is the simplest approach to perform image compression.
BTC- Implementation:
As provided in its title, BTC perform compression in a block wise manner.
Referring to the figure, each block is MxN size, then for each block mean, a and b are computed (please check the paper to find out the formula for 'a' and 'b')
To perform compression, each pixel in the block is thresholded with the block mean value
IF the pixel > mean, then it is assigned 1
ELSE the pixel is assigned 0
This output is termed as the bitmap image.
While transmitting, the bit map image along with it 'a' and 'b' are transmitted.
If suppose the block size is 8x8, and for a typical 8-bit image
Original image = 8x8x8= 512 bits
BTC image: Bitmap=8x8x1=64 bits
'a' and 'b'= 16 bits
Total= 80 bits
Decoding stage: The original image is reconstructed by substituting the bitmap image as follows
'1' is replaced with high mean 'a' and '0' with low mean 'b'
Note: It is important to note that, a) BTC is a lossy compression i.e. we lose some information
b) The maximum compression ratio is 8
c) The compression ratio increase with block size, but it also cause block artifacts and poor image quality.
%Block Truncation Coding
% Ref:Delp, Edward, and O. Mitchell.
%”Image compression using block truncation coding.”
%IEEE transactions on Communications 27.9 (1979): 1335-1342.
% Ref:Delp, Edward, and O. Mitchell.
%”Image compression using block truncation coding.”
%IEEE transactions on Communications 27.9 (1979): 1335-1342.
%Programmed By: Sankarasrinivasan S
%Multimedia Signal Processing Lab, Dept. of Elec Engg. NTUST
%Oct 2016
%Multimedia Signal Processing Lab, Dept. of Elec Engg. NTUST
%Oct 2016
function [H]=btc(in,bs)
%in–> input image, bs-block size(2,4,..)
[s1 s2]=size(in);
[s1 s2]=size(in);
n=bs*bs;
for i=1:bs:s1
for j=1:bs:s2
bl=in(i:i+(bs-1),j:j+(bs-1));
mn=mean(bl(:)) ; %Computing Mean
sd=std(double(bl(:)),1); %Standard Deviation
c=bl>mn;
q=nnz(c);
a=mn-(sd*sqrt((q)/(n-q)));
b=mn+(sd*sqrt((n-q)/(q)));
out=round((c).*b+((~c)).*a);
H(i:i+(bs-1),j:j+(bs-1))=out;
end
end
imshow(H);
end
for j=1:bs:s2
bl=in(i:i+(bs-1),j:j+(bs-1));
mn=mean(bl(:)) ; %Computing Mean
sd=std(double(bl(:)),1); %Standard Deviation
c=bl>mn;
q=nnz(c);
a=mn-(sd*sqrt((q)/(n-q)));
b=mn+(sd*sqrt((n-q)/(q)));
out=round((c).*b+((~c)).*a);
H(i:i+(bs-1),j:j+(bs-1))=out;
end
end
imshow(H);
end
Comments
Post a Comment