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.
65 lines
1.4 KiB
65 lines
1.4 KiB
#include "clhe.h" |
|
#include <QFile> |
|
|
|
clhe::clhe(QObject *parent) |
|
: QObject{parent} |
|
{ |
|
thread = new QThread(); |
|
thread->start(); |
|
this->moveToThread(thread); |
|
hist = (int*)malloc(sizeof(int)*16384); |
|
HIST = (int*)malloc(sizeof(int)*16384); |
|
ready = false; |
|
} |
|
|
|
void clhe::setthreshold(int threshold) |
|
{ |
|
this->threshold = threshold; |
|
ready = true; |
|
} |
|
|
|
void clhe::off() |
|
{ |
|
ready = false; |
|
} |
|
|
|
void clhe::slotprocimg(cv::Mat img) |
|
{ |
|
if(ready){ |
|
|
|
cv::Mat dst(img.rows,img.cols,CV_16UC1); |
|
memset(hist,0,sizeof(int)*16384); |
|
for(int i = 0;i<img.rows;i++){ |
|
for (int j = 0;j<img.cols;j++){ |
|
hist[img.at<ushort>(i,j)/4]+=1; |
|
} |
|
} |
|
|
|
|
|
|
|
HIST[0] = hist[0]>threshold?threshold:hist[0]; |
|
for(int i =1;i<16384;i++){ |
|
HIST[i] = HIST[i-1]+ (hist[i]>threshold?threshold:hist[i]); |
|
} |
|
double sub = double(img.rows*img.cols - HIST[16383])/16384; |
|
for (int i = 0; i < 16384; ++i) { |
|
HIST[i] += sub*(i+1); |
|
} |
|
|
|
|
|
for(int i = 0;i<img.rows;i++){ |
|
for(int j = 0;j<img.cols;j++){ |
|
dst.at<ushort>(i,j) = HIST[img.at<ushort>(i,j)/4]/double(HIST[16383])*65535; |
|
} |
|
} |
|
emit(signalsendimg(dst)); |
|
|
|
|
|
} |
|
else{ |
|
cv::Mat temp; |
|
img.copyTo(temp); |
|
emit(signalsendimg(temp)); |
|
|
|
} |
|
}
|
|
|