📜  在Matlab中从图像中提取位平面

📅  最后修改于: 2021-04-17 02:20:59             🧑  作者: Mango

图像基本上是单个像素(点)信息的组合。当我们写出的图像尺寸为620 X 480时,表示图像的水平方向为620像素,垂直方向为480像素。因此,总共有620 X 480像素,每个像素包含一些有关图像的信息。

灰度图像基本上就是我们所说的黑白图像。灰度图像的每个像素都有一个介于0到255之间的值,该值决定图像在哪个位置为黑色,在哪个位置为白色。

如果pixel值为0 ,则表示像素颜色将为全黑,如果pixel值为255 ,则该像素将为全白,而具有中间值的像素将具有黑白阴影。

我们得到一个灰度图像。由于灰度图像的像素值在0 -255之间,因此它的信息包含8位。因此,我们可以将这些图像划分为8个平面(8个二进制图像)。二值图像是那些像素值可以为01的图像

因此,我们的任务是提取原始图像的每个位平面以制作8个二进制图像

让特定的灰度图像像素值为212。因此,其二进制值为11010100。因此,其第1位为0,第2位为0,第3位为1,第4位为0,第5位为1,第6位为0,第7位为1 ,8th是1。这样,我们将取所有像素的这8位,并绘制8个二进制图像。我们必须对所有像素执行此操作并生成新图像。

下面是上述思想在matlab中的实现。

% clearing the output screen
clc;
  
% reading image's pixel in c
c = imread('cameraman.tif');
  
% storing image information in cd
cd = double(c);
  
% extracting all bit one by one
% from 1st to 8th in variable
% from c1 to c8 respectively
c1 = mod(cd, 2);
c2 = mod(floor(cd/2), 2);
c3 = mod(floor(cd/4), 2);
c4 = mod(floor(cd/8), 2);
c5 = mod(floor(cd/16), 2);
c6 = mod(floor(cd/32), 2);
c7 = mod(floor(cd/64), 2);
c8 = mod(floor(cd/128), 2);
  
% combining image again to form equivalent to original grayscale image
cc = (2 * (2 * (2 * (2 * (2 * (2 * (2 * c8 + c7) + c6) + c5) + c4) + c3) + c2) + c1);
  
% plotting original image in first subplot
subplot(2, 5, 1);
imshow(c);
title('Original Image');
  
% plotting binary image having extracted bit from 1st to 8th
% in subplot from 2nd to 9th
subplot(2, 5, 2);
imshow(c1);
title('Bit Plane 1');
subplot(2, 5, 3);
imshow(c2);
title('Bit Plane 2');
subplot(2, 5, 4);
imshow(c3);
title('Bit Plane 3');
subplot(2, 5, 5);
imshow(c4);
title('Bit Plane 4');
subplot(2, 5, 6);
imshow(c5);
title('Bit Plane 5');
subplot(2, 5, 7);
imshow(c6);
title('Bit Plane 6');
subplot(2, 5, 8);
imshow(c7);
title('Bit Plane 7');
subplot(2, 5, 9);
imshow(c8);
title('Bit Plane 8');
  
% plotting recombined image in 10th subplot
subplot(2, 5, 10);
imshow(uint8(cc));
title('Recombined Image');

以下是获得的输出的屏幕截图,这些输出是10个子图中的10个图像。第一个是原始图像。第二图像是提取的第一位(最低有效位)图像的表示,第三位是第二位的图像,依此类推。将第9位图像提取为第8位(最高有效位)图像,并在将所有8位提取的位重新组合后获得第10位图像。

原始图片参考:此处