44
Biomedical Signal and Image Processing
Example 3.2
In this example, we explore the implementation of bit-level slicing in MATLAB.
In this example, we show that by preserving the four MSBs and discarding the
remaining bits of the original image (shown in Figure 3.6a), while maintaining
the quality of the original image, one can reduce the size of space needed to
store the image. The MATLAB code of this implementation has been shown as
follows:
I=imread(‘2.jpg’);
I=rgb2gray(I);
imshow(I,[0 255]);
S=size(I);
I=double(I);
I=dec2base(I,2);
newS=size(I);
J= zeros(S(1),S(2) );
for I = 1:newS(1)
k=char(I(i,:) );
k(5)=‘0’;
k(6)=‘0’;
k(7)=‘0’;
k(8)=‘0’;
k=base2dec(k,2);
a=fix(i/S(1) )+1;
b=mod(i,S(1) );
if b==0
b=S(1);
a=a−1;
end
J(b,a)=k;
end
figure,
imshow(J,[0 255]);
As can be seen in the code, first, we read each pixel of the original gray-level
image in 8 bit. Then, we use a “for” loop in which for each pixel, only the four
MSBs are preserved and the rest of the bits are set to 0. Figure 3.6 shows both the
original image (a) and the image after bit-level slicing (b). Evidently, the image after
bit-level slicing has a quality very similar to that of the original image. However,
if we discard one or some of the MSBs, for example, the second MSB, the quality
of the image will decrease very much. Figure 3.6c shows the image after discarding bits 2, 5, 6, 7, and 8. The low quality of the resulting image indicates how the
image quality degrades when some of the MSBs are discarded.
3.2.3 HISTOGRAM EQUALIZATION
Histogram equalization is among the most popular techniques for image enhancement
that is based on the manipulation of images using their histograms. Before describing the technique, the need for such a transformation is explained. Consider cell
Biomedical Signal and Image Processing
Example 3.2
In this example, we explore the implementation of bit-level slicing in MATLAB.
In this example, we show that by preserving the four MSBs and discarding the
remaining bits of the original image (shown in Figure 3.6a), while maintaining
the quality of the original image, one can reduce the size of space needed to
store the image. The MATLAB code of this implementation has been shown as
follows:
I=imread(‘2.jpg’);
I=rgb2gray(I);
imshow(I,[0 255]);
S=size(I);
I=double(I);
I=dec2base(I,2);
newS=size(I);
J= zeros(S(1),S(2) );
for I = 1:newS(1)
k=char(I(i,:) );
k(5)=‘0’;
k(6)=‘0’;
k(7)=‘0’;
k(8)=‘0’;
k=base2dec(k,2);
a=fix(i/S(1) )+1;
b=mod(i,S(1) );
if b==0
b=S(1);
a=a−1;
end
J(b,a)=k;
end
figure,
imshow(J,[0 255]);
As can be seen in the code, first, we read each pixel of the original gray-level
image in 8 bit. Then, we use a “for” loop in which for each pixel, only the four
MSBs are preserved and the rest of the bits are set to 0. Figure 3.6 shows both the
original image (a) and the image after bit-level slicing (b). Evidently, the image after
bit-level slicing has a quality very similar to that of the original image. However,
if we discard one or some of the MSBs, for example, the second MSB, the quality
of the image will decrease very much. Figure 3.6c shows the image after discarding bits 2, 5, 6, 7, and 8. The low quality of the resulting image indicates how the
image quality degrades when some of the MSBs are discarded.
3.2.3 HISTOGRAM EQUALIZATION
Histogram equalization is among the most popular techniques for image enhancement
that is based on the manipulation of images using their histograms. Before describing the technique, the need for such a transformation is explained. Consider cell
