MLX90640开发笔记(四)损坏和不良像素的处理

如前“开发笔记(一)”所说,MLX90640可能存在不超过4个像素的损坏或者不良像素,在温度计算过程完成后,这些不良像素点会得到错误的温度数据,对于处理这些不良数据MLX也给出了推荐方法和具体的函数。(其实就是找相邻的正常的温度数据取平均来代替不良数据)

 

前面开发笔记(一)的内容中所说的API库,里面缺少了对不良像素点的处理函数,在这里补上。

int CheckAdjacentPixels(uint16_t pix1, uint16_t pix2)

 {

     int pixPosDif;

    

     pixPosDif = pix1 - pix2;

     if(pixPosDif > -34 && pixPosDif < -30)

     {

         return -6;

     }

     if(pixPosDif > -2 && pixPosDif < 2)

     {

         return -6;

     }

     if(pixPosDif > 30 && pixPosDif < 34)

     {

         return -6;

     }

    

     return 0;   

 }

 

float GetMedian(float *values, int n)

 {

    float temp;

   

    for(int i=0; i<n-1; i++)

    {

        for(int j=i+1; j<n; j++)

        {

            if(values[j] < values[i])

            {               

                temp = values[i];

                values[i] = values[j];

                values[j] = temp;

            }

        }

    }

   

    if(n%2==0)

    {

        return ((values[n/2] + values[n/2 - 1]) / 2.0);

       

    }

    else

    {

        return values[n/2];

    }

   

 }          

 

int IsPixelBad(uint16_t pixel,paramsMLX90640 *params)

{

    for(int i=0; i<5; i++)

    {

        if(pixel == params->outlierPixels[i] || pixel == params->brokenPixels[i])

        {

            return 1;

        }   

    }  

   

    return 0;    

}

void MLX90640_BadPixelsCorrection(uint16_t *pixels, float *to, int mode, paramsMLX90640 *params)

{  

    float ap[4];

    uint8_t pix;

    uint8_t line;

    uint8_t column;

   

    pix = 0;

    while(pixels[pix] != 0xFFFF)

    {

        line = pixels[pix]>>5;

        column = pixels[pix] - (line<<5);

       

        if(mode == 1)

        {       

            if(line == 0)

            {

                if(column == 0)

                {       

                    to[pixels[pix]] = to[33];                   

                }

                else if(column == 31)

                {

                    to[pixels[pix]] = to[62];                     

                }

                else

                {

                    to[pixels[pix]] = (to[pixels[pix]+31] + to[pixels[pix]+33])/2.0;                   

                }       

            }

            else if(line == 23)

            {

                if(column == 0)

                {

                    to[pixels[pix]] = to[705];                   

                }

                else if(column == 31)

                {

                    to[pixels[pix]] = to[734];                      

                }

                else

                {

                    to[pixels[pix]] = (to[pixels[pix]-33] + to[pixels[pix]-31])/2.0;                      

                }                      

            }

            else if(column == 0)

            {

                to[pixels[pix]] = (to[pixels[pix]-31] + to[pixels[pix]+33])/2.0;               

            }

            else if(column == 31)

            {

                to[pixels[pix]] = (to[pixels[pix]-33] + to[pixels[pix]+31])/2.0;               

            }

            else

            {

                ap[0] = to[pixels[pix]-33];

                ap[1] = to[pixels[pix]-31];

                ap[2] = to[pixels[pix]+31];

                ap[3] = to[pixels[pix]+33];

                to[pixels[pix]] = GetMedian(ap,4);

            }                  

        }

        else

        {       

            if(column == 0)

            {

                to[pixels[pix]] = to[pixels[pix]+1];           

            }

            else if(column == 1 || column == 30)

            {

                to[pixels[pix]] = (to[pixels[pix]-1]+to[pixels[pix]+1])/2.0;               

            }

            else if(column == 31)

            {

                to[pixels[pix]] = to[pixels[pix]-1];

            }

            else

            {

                if(IsPixelBad(pixels[pix]-2,params) == 0 && IsPixelBad(pixels[pix]+2,params) == 0)

                {

                    ap[0] = to[pixels[pix]+1] - to[pixels[pix]+2];

                    ap[1] = to[pixels[pix]-1] - to[pixels[pix]-2];

                    if(fabs(ap[0]) > fabs(ap[1]))

                    {

                        to[pixels[pix]] = to[pixels[pix]-1] + ap[1];                       

                    }

                    else

                    {

                        to[pixels[pix]] = to[pixels[pix]+1] + ap[0];                       

                    }

                }

                else

                {

                    to[pixels[pix]] = (to[pixels[pix]-1]+to[pixels[pix]+1])/2.0;                    

                }           

            }                     

        }

        pix = pix + 1;   

    }   

}

用法很简单,在开发笔记(三)MLX90640_CalculateTo(Frame, MLXPars, 0.95, Tr, Temp);之后添加两行即可。如下(斜体是添加的内容):

 

……

MLX90640_CalculateTo(Frame, MLXPars, 0.95, Tr, Temp);

MLX90640_BadPixelsCorrection(MLXPars.brokenPixels, Temp, 1, MLXPars);

MLX90640_BadPixelsCorrection(MLXPars.outlierPixels, Temp, 1, MLXPars);

……

/*

经过上面的处理后,Temp中的损坏和不良像素点已经处理,Temp数组中是处理完成后的768个温度值。

*/

MLX90640开发笔记(一)概述及开发资料准备
MLX90640开发笔记(二)API移植-I2C和关键接口函数
MLX90640开发笔记(三)工作流程和操作MLX90640的一般步骤
MLX90640开发笔记(四)损坏和不良像素的处理
MLX90640开发笔记(五)阵列插值处理-多项式插值由32*24像素到512*384像素
MLX90640开发笔记(六)红外图像伪彩色编码
MLX90640开发笔记(七)小结-注意事项
MLX90640开发笔记(八)扩展知识-辐射率、灵敏度、精度、探测距离
MLX90640开发笔记(九)EEPROM、RAM、寄存器说明
MLX90640开发笔记(十)成果展示-红眼睛相机

邮箱:INFO@GEO-INS.COM

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值