59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
#include "clahe.h"
|
|
#include <QDebug>
|
|
#include <opencv2/highgui.hpp>
|
|
|
|
CLAHE::CLAHE()
|
|
{
|
|
}
|
|
|
|
void CLAHE::loadFile(const QString &path)
|
|
{
|
|
cv::Mat tmp;
|
|
tmp = cv::imread(path.toStdString(), cv::IMREAD_COLOR | cv::IMREAD_ANYDEPTH);
|
|
int type = tmp.depth();
|
|
_scale = type==CV_8U ? 1.0/255 : 1.0/65535;
|
|
tmp.convertTo(tmp, CV_32F, _scale);
|
|
cv::cvtColor(tmp, tmp, cv::COLOR_BGR2Lab);
|
|
cv::split(tmp, _image);
|
|
_image[0].convertTo(_lumImage, type, 0.01/_scale);
|
|
}
|
|
|
|
void CLAHE::saveFile(const QString &path)
|
|
{
|
|
cv::Mat tmp;
|
|
cv::merge(_image, 3, tmp);
|
|
cv::cvtColor(tmp, tmp, cv::COLOR_Lab2BGR);
|
|
tmp.convertTo(tmp, _lumImage.depth(), 1/_scale);
|
|
cv::imwrite(path.toStdString(), tmp);
|
|
}
|
|
|
|
void CLAHE::apply(float clipLimit, int kernelSize)
|
|
{
|
|
cv::Mat lum;
|
|
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit, cv::Size(kernelSize, kernelSize));
|
|
clahe->apply(_lumImage, lum);
|
|
lum.convertTo(_image[0], CV_32F, 100*_scale);
|
|
double min, max;
|
|
cv::minMaxLoc(_image[0], &min, &max);
|
|
qDebug() << min << max;
|
|
}
|
|
|
|
QPixmap CLAHE::getImage() const
|
|
{
|
|
cv::Mat tmp;
|
|
cv::merge(_image, 3, tmp);
|
|
cv::cvtColor(tmp, tmp, cv::COLOR_Lab2RGB);
|
|
tmp.convertTo(tmp, CV_8U, 255);
|
|
QImage ret(tmp.data, tmp.cols, tmp.rows, tmp.step1(), QImage::Format_RGB888);
|
|
//ret.bits();//perform deep copy of tmp.data pointer
|
|
return QPixmap::fromImage(ret);
|
|
}
|
|
|
|
QPixmap CLAHE::getLumImage() const
|
|
{
|
|
cv::Mat tmp;
|
|
_image[0].convertTo(tmp, CV_8U, 2.55);
|
|
QImage ret(tmp.data, tmp.cols, tmp.rows, tmp.step1(), QImage::Format_Grayscale8);
|
|
return QPixmap::fromImage(ret);
|
|
}
|