有关迭代法图像二值化程序代码的问题!

[复制链接]
813|5
手机看帖
扫描二维码
随时随地手机跟帖
麓山电玩|  楼主 | 2018-8-3 15:09 | 显示全部楼层 |阅读模式
求助各位大佬~~这个迭代法图像二值化的程序设定的长宽是180*320,但是我屏幕是240*320,所以有一部分屏幕是看不到东西的,但是我把宽调成240以后整个屏幕都不亮了!是数据类型定义出问题了么?求助各位大佬帮帮小弟!


#define PIXEL_W      320
#define PIXEL_H    180
#define PIXEL_BREAK  100

//»Ò¶ÈÖ±·½Í¼ÊýÖµ£¬ÓÃÀ´Åжϰ´Í¼ÏñÖÊÁ¿
u32 gray_test_value[26];   //ÏñËصãÊýÊý¾Ý
u8 gray_test_send[28];     //·¢Ë͸øÉÏλ»úµÄÊý¾Ý

//ãÐÖµ·Ö¸î»Ò¶Èͼ
u8 gray_itera_threshold[256];
u16 threshold_h[256];
#define GRAY_BREAK_RANGE     1    //ãÐÖµÔÊÐí²ÎÊý

static u8 pixel[PIXEL_H][PIXEL_W];

/*       320
* -------------------
*|                   |
*|                   |
*|                   |  240
*|                   |
*|                   |
* -------------------
*/
void ImagDisp_T(void)
{
        uint16_t i=0, j=0;
        uint16_t Camera_Data;
        uint16_t R,G,B;uint32_t mux;
  //mux_later;
//        float data = 0.0;

//        LCD_SetCursor(0,0); È·¶¨Òº¾§É¨Ãè·½Ïò
//        LCD_WriteIndex(0x22);ÇåÆÁ×¼±¸Ð´ÈëÊý¾Ý
  ILI9341_GramScan ( 3 );


        for(i = 0; i<PIXEL_H; i++)
        {
                for(j = 0; j<PIXEL_W; j++)
                {
                 //READ_FIFO_PIXEL(Camera_Data);                /* ´ÓFIFO¶Á³öÒ»¸örgb565ÏñËص½Camera_Data±äÁ¿ */
                 //ת»»³É»Ò¶Èͼ       
      READ_FIFO_PIXEL(Camera_Data);                /* ´ÓFIFO¶Á³öÒ»¸örgb565ÏñËص½Camera_Data±äÁ¿ */      
                        R = (uint16_t)GETR_FROM_RGB16(Camera_Data);
                        G = (uint16_t)GETG_FROM_RGB16(Camera_Data);
                        B = (uint16_t)GETB_FROM_RGB16(Camera_Data);
                        mux = (R*30+G*59+B*11)/100;
////                 mux = G;
//      
                        pixel[i][j] = mux;
                       
    //pixel[i][j] = GETGRAY_FROM_RGB16(R,G,B);
                       
  //    mux = pixel[i][j];
//     Camera_Data =  GRAY_TO_RGB(mux);  
//     ILI9341_Write_Data(Camera_Data);
      
                }

        }
}
/****************************************************
* º¯ÊýÃû£ºItera_Threshold
* ¹¦  ÄÜ£ºµü´úãÐÖµ·¨£¬Äܹ»ÕÒµ½»Ò¶ÈͼµÄ×î¼Ñ¶þÖµ»¯µã
****************************************************/
void Itera_Threshold(void)
{
  u16 i=0,j=0,k=0,cnt=0,mux=0,Camera_Data=0;
        u8 newthreshold=0;
        u16 Pmax=0,Pmin=0;
        u32 sum_h1=0,sum_h2=0;
       
       
        //Êý¾ÝÇå¿Õ
        for( i=0; i<256; i++ )
        {
          gray_test_value[i] = 0;
        }
       
        for( i=0; i<PIXEL_H; i++ )
        {
          for( j=0; j<PIXEL_W; j++ )
                {
                  mux = pixel[i][j];//»ñÈ¡»Ò¶ÈͼµÄÊý¾Ý               
                        //ÏñËصãÊý×ÔÔö     
                        gray_itera_threshold[mux]++;       
                }
        }
       
        Pmin = gray_itera_threshold[0];
        Pmax = gray_itera_threshold[0];
        for( cnt=0; cnt<256; cnt++ )
        {
      if( Pmin>gray_itera_threshold[cnt] )
      {
        Pmin = gray_itera_threshold[cnt];
      }
      if( Pmax<gray_itera_threshold[cnt] )
      {
        Pmax = gray_itera_threshold[cnt];
      }
        }
       
        printf("the Pmax is %d\r \n",Pmax);
        printf("the Pmin is %d \r\n",Pmin);
       
        //³õʼãÐÖµ
        threshold_h[0] = ( Pmax + Pmin ) / 2;
       
        //Ñ°ÕÒ×î¼ÑãÐÖµ
        for( k=0; k<256; k++ )
        {
                //·Ö¸îÇ°¾°ºÍ±³¾°
                for( cnt=0; cnt<threshold_h[k]; cnt++ )
                {
                        sum_h1 += gray_itera_threshold[cnt];
                }
                for( cnt=threshold_h[k]; cnt<256; cnt++ )
                {
                        sum_h2 += gray_itera_threshold[cnt];
                }
                sum_h1 /= threshold_h[k];
                sum_h2 /= (256-threshold_h[k]);
               
                //¼ÆËã³öеÄãÐÖµ
                threshold_h[k+1] = ( sum_h1 + sum_h2 ) / 2;
               
                if( fabs(threshold_h[k]-threshold_h[k+1]) <= GRAY_BREAK_RANGE )
    {
                        newthreshold = threshold_h[k+1];
                  break;
                }
               
                sum_h1 = 0;
                sum_h2 = 0;
        }

        printf("the newthreshold is %d\r\n",newthreshold);
       
//        //ÔÚÒº¾§ÆÁÉÏÃæдÈëͼÏñ·Ö¸îºóµÄͼÏñ
//  LCD_SetCursor(0,0);
//        LCD_WriteIndex(0x22);                                        //×¼±¸Ð´ÈëÊý¾Ý
        //¸ù¾Ý×î¼ÑãÐÖµ½«Í¼Ïñ¶þÖµ»¯
  ILI9341_GramScan ( 3 );
//  ILI9341_Clear ( 0, 0, 240, 320, macWHITE);
        for( i=0; i<PIXEL_H; i++ )
        {
          for( j=0; j<PIXEL_W; j++ )
                {
                  mux = pixel[i][j];                     //»ñÈ¡»Ò¶ÈͼµÄÊý¾Ý
                  //ͼÏñ¶þÖµ»¯
                        if( mux > newthreshold )
      {
                          mux = 255;
                        }
                        else
       {
                          mux = 0;
                        }
                       
                        Camera_Data =  GRAY_TO_RGB(mux);
      ILI9341_Write_Data(Camera_Data);
                       
                }
        }

}

相关帖子

caijie001| | 2018-8-3 21:55 | 显示全部楼层
采集是按比例的吧,

使用特权

评论回复
caijie001| | 2018-8-3 21:55 | 显示全部楼层
不能随意改变比例吧。。。按照你说的单纯修改宏应该是没啥问题的

使用特权

评论回复
麓山电玩|  楼主 | 2018-8-4 14:02 | 显示全部楼层
caijie001 发表于 2018-8-3 21:55
不能随意改变比例吧。。。按照你说的单纯修改宏应该是没啥问题的

对呀,我就是修改了宏定义但是为啥他有数值限制,好奇怪哇,只能定义到188以下,再大整个屏幕不亮了哇

使用特权

评论回复
caijie001| | 2018-8-4 14:03 | 显示全部楼层
麓山电玩 发表于 2018-8-4 14:02
对呀,我就是修改了宏定义但是为啥他有数值限制,好奇怪哇,只能定义到188以下,再大整个屏幕不亮了哇 ...

这个看传感器手册,具体我也不知道

使用特权

评论回复
麓山电玩|  楼主 | 2018-8-4 15:42 | 显示全部楼层
caijie001 发表于 2018-8-4 14:03
这个看传感器手册,具体我也不知道

看摄像头还是屏幕呀,就用了这个算法才会出现这种问题,别的显示都没问题

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝