Home > Back-end >  For a quick comparison threshold into a matrix of binarization algorithm
For a quick comparison threshold into a matrix of binarization algorithm

Time:04-01

Using MCU + camera processing image data
Have generated a (length * width) (188 * 70) of two-dimensional array and use dajin method to find the threshold,

Is there any algorithm can quickly compare image array into after a threshold generated after binary array

CodePudding user response:

 
Void photo_get ()
{
int num=0;
For (num=0; Num & lt; MT9V03X_H; Num++)
{
Memcpy (dis_image [num], mt9v03x_image [num], MT9V03X_W);//the raw data for mt9v03x_image results memcpy copied to dis_image
}
}
//the following is a dajin method to calculate dis_image threshold of image threshold output for threshold

Uint8 threshold=0;

Void my_adapt_threshold (uint8 * image, uint16 col, uint16 row)
{
# define GrayScale 256
Uint16 width=col;
Uint16 height=row;
Int pixelCount (GrayScale),
Float pixelPro (GrayScale),
Int I, j, pixelSum=width * height/4;
Uint8 * data=https://bbs.csdn.net/topics/image;//?????????????
for (i=0; I & lt; GrayScale. I++)
{
PixelCount [I]=0;
PixelPro [I]=0;
}

Uint32 gray_sum=0;

for (i=0; I & lt; Height; I +=2)
{
For (j=0; J & lt; Width; J +=2)
{
PixelCount [(int) data [I * width + j]] + +;
Gray_sum +=(int) data [I * width + j];
}
}



for (i=0; I & lt; GrayScale. I++)
{
PixelPro [I]=(float) pixelCount [I]/pixelSum;

}


Float w0, w1, u0tmp u1tmp, u0, u1, u, deltaTmp, deltaMax=0;



W0=w1=u0tmp=u1tmp=u0=u1=u=deltaTmp=0;
For (j=0; J & lt; GrayScale. J++)
{

W0 +=pixelPro [j];
U0tmp +=j * pixelPro [j];

W1=1 - w0;
U1tmp=gray_sum/pixelSum - u0tmp;

U0=u0tmp/w0;
U1=u1tmp/w1.
U=u0tmp + u1tmp;
(deltaTmp=w0 * pow (u0 - u), 2) + w1 * pow ((u1 - u), 2);
If (deltaTmp & gt; DeltaMax)
{
DeltaMax=deltaTmp;
Threshold=j;
}
If (deltaTmp & lt; DeltaMax)
{
break;
}

}
//for (I=0; I & lt; Threshold; I++)
//{
//Bin_Array [I]=0;
//}
//for (I=threshold; I & lt; 256; I++)
//{
//Bin_Array [I]=1;
//}
}


  • Related