# matlab8位分解

clc;
clear all;
% 显示原始图像
subplot(3,3,1);
imshow(A);title('原始图像');
% 显示8个位平面图像
for i=8:-1:1
A_bitplane = bitshift(bitget(A,i),i-1);
subplot(3, 3, 9-i+1);
imshow(A_bitplane);
title(['位平面 ' num2str(i)]);
end 

# matlab8位合并复原

clc;
clear all;
Array=cell(1,8);
% 显示8个位平面图像
for i=8:-1:1
Array{i} = bitshift(bitget(A,i),i-1);
end

%%%复原
%%定义全0矩阵
[M,N]=size(Array{1});
B=zeros(M,N,'uint8');

for i=1:8
B=bitset(B,i,bitget(Array{i},i));
end
figure;
subplot(1,2,1);
imshow(A);title('原始图像');
subplot(1,2,2)
imshow(B);title('复原后图像');


# halcon分解

### 方法一，自己实现

void Bit()
{
using namespace Halcon;

cout << endl << "Shifting & cutting out bit values:" << endl;

HByteImage image("mreut");
HWindow  w(0,0,image.Width(),image.Height());
w.SetPart(0,0,image.Height()-1,image.Width()-1);
image.Display(w);

int i;

cout << "- cutting out bit slices" << endl;
for (i=0; i<8; i++)
{
HRegion reg = (image & (1<<i)) != 0; //按照位切片
w.ClearWindow();
reg.Display(w);
cout << "  & bit " << i << endl;
}

}

### 方法二，使用自带函数

void Bit()
{
using namespace Halcon;

cout << endl << "Shifting & cutting out bit values:" << endl;

HByteImage image("mreut");
HWindow  w(0,0,image.Width(),image.Height());
w.SetPart(0,0,image.Height()-1,image.Width()-1);
image.Display(w);

int i;
cout << "- cutting out bit slices2" << endl;
for (i = 0; i < 8; i++)
{
HRegion reg = (image.BitSlice(i+1)) != 0; //按照位切片
w.ClearWindow();
reg.Display(w);
cout << "  & bit " << i << endl;
}

}

xiamentingtao

• 擅长领域：
• cv
• math
• 考博
• 算法
• AI