标签:row color bsp first abs highlight int lin mat
常规方法:
1 void SobelAmplitude(Mat &sobelx, Mat &sobely, Mat &SobelXY) { 2 SobelXY = Mat::zeros(sobelx.size(), CV_32FC1); 3 for (int i = 0; i < SobelXY.rows; i++) { 4 float *data = SobelXY.ptr<float>(i); 5 short *datax = sobelx.ptr<short>(i); 6 short *datay = sobely.ptr<short>(i); 7 for (int j = 0; j < SobelXY.cols; j++) { 8 data[j] = sqrt(datax[j] * datax[j] + datay[j] * datay[j]); 9 } 10 } 11 // convertScaleAbs(SobelXY, SobelXY); 12 }
上述,图像在x和y方向上的梯度数据类型为CV_16S。
当然,也可以为uchar!
自己修改,uchar类型,就有很多种方式,比如:
查表法:提供者:GiantPandaCV
unsigned char Table[65026]; for (int Y = 0; Y < 65026; Y++) Table[Y] = (sqrtf(Y + 0.0f) + 0.5f); for (int X = 0; X < Width; X++) { int GX = First[X] - First[X + 2] + (Second[X] - Second[X + 2]) * 2 + Third[X] - Third[X + 2]; int GY = First[X] + First[X + 2] + (First[X + 1] - Third[X + 1]) * 2 - Third[X] - Third[X + 2]; LinePD[X] = Table[min(GX * GX + GY * GY, 65025)]; }
标签:row color bsp first abs highlight int lin mat
原文地址:https://www.cnblogs.com/almn/p/13204108.html