当前位置: 首页 > article >正文

结构光编解码—正反格雷码解码代码

        本篇文章主要给出正反格雷码的解码代码,鉴于自身水平所限,如有错误,欢迎批评指正。(欢迎进Q群交流:874653199)

clc;
clear;

s1='.\graycode\02\';
s2='.bmp';

image_num=24;

vertical_bit=11;

tempImage=imread([s1 num2str(1) s2]);

[rows,cols]=size(tempImage);

for i=1:image_num
    filename=[s1 num2str(i) s2];
    srcImage(:,:,i)=imread(filename);
end

%% 计算mask
white=srcImage(:,:,1);
black=srcImage(:,:,2);

low=1;
high=255;

mask=ones(rows,cols);

indexB=find(black<low);
mask(indexB)=0;
indexW=find(white>high);
mask(indexW)=0;

vertical_image=srcImage(:,:,3:24);

vertical_decodeMat=decode(vertical_image,mask,vertical_bit);


figure
imshow(vertical_decodeMat,[])

%% 正反格雷码解码
function decodeMatrix=decode(srcImage,mask,bit)

[direct,indirect]=estimate_light(srcImage,mask);

[rows,cols]=size(srcImage(:,:,1));

graycodeMat=zeros(rows,cols,bit);

for i=1:bit    
graycodeMat(:,:,i)=robust_bit(srcImage(:,:,2*i-1),srcImage(:,:,2*i),direct,indirect);
end

binarys=zeros(rows,cols,bit);
binarys(:,:,1)=graycodeMat(:,:,1);
for i=2:bit    
 binarys(:,:,i)= xor(binarys(:,:,i-1),graycodeMat(:,:,i));
end

decodeMatrix=zeros(rows,cols);
for i=1:bit
    decodeMatrix=decodeMatrix+2^(bit-i)*binarys(:,:,i);
end
index=find(decodeMatrix<0);
decodeMatrix(index)=-10;
end

%% srcImage包含所有竖条纹格雷码图像或者横条纹,不应包含黑白图
function [direct,indirect]=estimate_light(srcImages,mask)

b_=0.5;
b1 = 1.0 / (1.0 - b_);
b2 = 2.0 / (1.0 - b_ * 1.0 * b_);

[rows,cols,num]=size(srcImages);

direct=zeros(rows,cols);
indirect=zeros(rows,cols);
  
for m=1:rows
    
   for n=1:cols 
       
    if(mask(m,n) ~=0)
      light_max=srcImages(m,n,1);
      light_min=light_max;
   
       for k=1:num
         if(srcImages(m,n,k)>light_max)
           light_max= srcImages(m,n,k); 
         end
         
         if(srcImages(m,n,k)<light_min)
           light_min= srcImages(m,n,k); 
         end
            
       end
       
    direct_light =round( b1 * (light_max - light_min) );
    global_light = round(b2 * (light_min - b_ * light_max) );
    
    if(global_light > 0)
     direct(m,n) =direct_light;
     indirect(m,n) =global_light;
    else
     direct(m,n) = light_max;
     indirect(m,n) =0;  
    end
    
    end
  
       
    end
        
end

end


%% 鲁棒分类,输入正反码图像以及直接分量和间接分量
function binMatrix=robust_bit(normal, inverted,direct_light,global_light)

[rows,cols]=size(normal);

binMatrix=zeros(size(normal));

m_=1;

for i=1:rows
    for j=1:cols
        
        if (direct_light(i,j) < m_)
        binMatrix(i,j)=-10;
        continue;
        end
        
        if (direct_light(i,j) > global_light(i,j)) 
            if(normal(i,j) > inverted(i,j))
                binMatrix(i,j) = 1;   
            else
                binMatrix(i,j) = 0; 
            end      
             continue;
        end
        
        if ((normal(i,j) <= direct_light(i,j)) && (inverted(i,j) > global_light(i,j))) 
            binMatrix(i,j) = 0;
            continue;
        end
        
        if ((normal(i,j) >= global_light(i,j)) && (inverted(i,j) <= direct_light(i,j))) 
            binMatrix(i,j)= 1;
            continue;
        end
        
        
    end
end


end

原始数据:

解码结果:

去噪及重建结果:


http://www.kler.cn/news/329642.html

相关文章:

  • SQL_create_view
  • VR、AR、MR、XR 领域最新科研资讯获取指南
  • CSS链接
  • 查找与排序-快速排序
  • 数造科技入选中国信通院《高质量数字化转型产品及服务全景图》三大板块
  • OpenCV透视变换:原理、应用与实现
  • Mysql 学习——项目实战
  • 企业级版本管理工具(1)----Git
  • WPF之UI进阶--完整了解wpf的控件和布局容器及应用
  • 栏目一:使用echarts绘制简单图形
  • HttpSession使用方法及原理
  • .c、.cpp、.cc、.cxx、.cp后缀的区别
  • YOLOv8改进,YOLOv8改进主干网络为GhostNetV3(2024年华为的轻量化架构,全网首发),助力涨点
  • C++ STL(3)list
  • 卡夫卡的理解
  • 事务原理,以及MVCC如何实现RC,RR隔离级别的
  • 告别PPT熬夜!Kimi+AIPPT一键生成PPT,效率upup!
  • Docker全家桶:从0到加载本地项目
  • docker 部署 Seatunnel 和 Seatunnel Web
  • 浏览器用户行为集群建设-数仓建模-数据计算
  • 828华为云征文|华为云Flexus云服务器X实例搭建部署H5美妆护肤分销商城、前端uniapp
  • pytorch千问模型源码分析
  • leetcode.每日一题.2516.每种字符至少取 K 个
  • 【C++】C++基础
  • 魔都千丝冥缘——软件终端架构思维———未来之窗行业应用跨平台架构
  • D21【python接口自动化学习】-python基础之内置数据类型
  • Git记录
  • C语言:排序(1)
  • 毕业设计选题:基于ssm+vue+uniapp的家庭记账本小程序
  • 在线远程考试|基于springBoot的在线远程考试系统设计与实现(附项目源码+论文+数据库)