You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.2 KiB
82 lines
2.2 KiB
#include "sagauss.h" |
|
|
|
sagauss::sagauss(QObject *parent) |
|
: QObject{parent} |
|
{ |
|
thread = new QThread(); |
|
thread->start(); |
|
this->moveToThread(thread); |
|
sigmaN = 0; |
|
ready = false; |
|
} |
|
|
|
void sagauss::setpara(int r, double sigma) |
|
{ |
|
this->r = r; |
|
this->sigma = sigma; |
|
// ready = true; |
|
} |
|
|
|
void sagauss::on() |
|
{ |
|
ready = true; |
|
} |
|
|
|
void sagauss::off() |
|
{ |
|
ready = false; |
|
} |
|
|
|
void sagauss::slotprocimg(cv::Mat img) |
|
{ |
|
if(ready){ |
|
cv::Mat src; |
|
img.convertTo(src,CV_32FC1,4); |
|
cv::Mat gauss; |
|
cv::GaussianBlur(src,gauss,cv::Size(2*r+1,2*r+1),sigma); |
|
cv::Mat res = src-gauss; |
|
cv::Mat sigma1 = cv::abs(res); |
|
cv::Mat sigma2; |
|
cv::GaussianBlur(sigma1,sigma2,cv::Size(2*r+1,2*r+1),sigma); |
|
// cv::Mat sigma2t = sigma2/32; |
|
cv::Mat sigma3(src.rows,src.cols,CV_32FC1); |
|
for(int i = 0;i< src.rows;i++){ |
|
for(int j = 0;j<src.cols;j++){ |
|
sigma3.at<float>(i,j) = sigma2.at<float>(i,j)*sigma2.at<float>(i,j)/32; |
|
} |
|
} |
|
cv::Mat sigmaU1 = sigma3-sigmaN; |
|
cv::Mat sigmaU2 = cv::abs(sigmaU1)/2+sigmaU1/2; |
|
// cv::Mat sigmaU3 = sigmaU2/(sigma3+0.00001)*res; |
|
cv::Mat sigmaU3(src.rows,src.cols,CV_32FC1); |
|
for(int i = 0;i< src.rows;i++){ |
|
for(int j = 0;j<src.cols;j++){ |
|
sigmaU3.at<float>(i,j) = sigmaU2.at<float>(i,j)*res.at<float>(i,j)/(sigma3.at<float>(i,j)+0.00001); |
|
} |
|
} |
|
cv::Mat dstt = gauss+sigmaU3; |
|
cv::Mat dst; |
|
dstt.convertTo(dst,CV_16UC1,1/4.0); |
|
emit(signalsendimg(dst)); |
|
double max; |
|
cv::minMaxLoc(sigma3,nullptr,&max); |
|
int* hist = (int*)malloc(sizeof(int)*int(max+1)); |
|
memset(hist,0,sizeof(int)*int(max+1)); |
|
for(int i = 0;i< sigma3.rows;i++){ |
|
for(int j = 0;j<sigma3.cols;j++){ |
|
hist[int(sigma3.at<float>(i,j))] +=1; |
|
} |
|
} |
|
int max1 = hist[0]; |
|
for(int i = 1;i<(max+1);i++){ |
|
max1 = hist[i]>max1?hist[i]:max1; |
|
} |
|
free(hist); |
|
sigmaN = (9*sigmaN+2*max1)/10.0; |
|
} |
|
else{ |
|
cv::Mat temp; |
|
img.copyTo(temp); |
|
emit(signalsendimg(temp)); |
|
} |
|
}
|
|
|