1
0

First prototype

This commit is contained in:
2020-01-21 21:23:45 +01:00
commit 66b14d5964
6 changed files with 194 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
#include "clahe.h"
#include <QDebug>
CLAHE::CLAHE()
{
_clahe = cv::createCLAHE();
}
void CLAHE::loadFile(const QString &path)
{
cv::Mat tmp;
tmp = cv::imread(path.toStdString(), cv::IMREAD_COLOR | cv::IMREAD_ANYDEPTH);
double scale = tmp.depth()==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, CV_16U, 655.35);
double min, max;
cv::minMaxLoc(_image[0], &min, &max);
qDebug() << scale << min << max;
}
void CLAHE::saveFile(const QString &path)
{
}
void CLAHE::apply(float clipLimit, int kernelSize)
{
cv::Mat lum;
_clahe->setClipLimit(clipLimit);
_clahe->setTilesGridSize(cv::Size(kernelSize, kernelSize));
_clahe->apply(_lumImage, lum);
//lum = _lumImage;
lum.convertTo(_image[0], CV_32F, 1.0/655.35);
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.step, QImage::Format_RGB888);
//ret.bits();//perform deep copy of tmp.data pointer
return QPixmap::fromImage(ret);
}
+23
View File
@@ -0,0 +1,23 @@
#ifndef CLAHE_H
#define CLAHE_H
#include <QImage>
#include <QPixmap>
#include <QString>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
class CLAHE
{
cv::Mat _lumImage;
cv::Mat _image[3];
cv::Ptr<cv::CLAHE> _clahe;
public:
CLAHE();
void loadFile(const QString &path);
void saveFile(const QString &path);
void apply(float clipLimit, int kernelSize);
QPixmap getImage() const;
};
#endif // CLAHE_H
+41
View File
@@ -0,0 +1,41 @@
#-------------------------------------------------
#
# Project created by QtCreator 2020-01-21T16:48:44
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = clahe
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11 link_pkgconfig
PKGCONFIG += opencv
SOURCES += \
main.cpp \
mainwindow.cpp \
clahe.cpp
HEADERS += \
mainwindow.h \
clahe.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
+11
View File
@@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
+48
View File
@@ -0,0 +1,48 @@
#include "mainwindow.h"
#include <QStandardPaths>
#include <QFileDialog>
#include <QMenuBar>
#include "clahe.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
setupUI();
}
MainWindow::~MainWindow()
{
}
void MainWindow::openFile()
{
QStringList list = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::PicturesLocation);
list.append("");
QString path = QFileDialog::getOpenFileName(this, tr("Open image"), list.first(), tr("Images (*.png *.jpg *.jpeg);;All files (*)"));
if(!path.isEmpty())
{
CLAHE cl;
cl.loadFile(path);
cl.apply(5, 64);
QPixmap pixmap;
pixmap = cl.getImage();
_image->setPixmap(pixmap);
}
}
void MainWindow::saveFile()
{
}
void MainWindow::setupUI()
{
resize(1024, 768);
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(tr("Open file"), this, SLOT(openFile()), QKeySequence("Ctrl+O"));
fileMenu->addAction(tr("Save file"), this, SLOT(saveFile()), QKeySequence("Ctrl+S"));
fileMenu->addAction(tr("Quit"), this, SLOT(close()), QKeySequence("Ctrl+Q"));
_image = new QLabel(this);
setCentralWidget(_image);
}
+21
View File
@@ -0,0 +1,21 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
class MainWindow : public QMainWindow
{
Q_OBJECT
QLabel *_image;
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
public slots:
void openFile();
void saveFile();
private:
void setupUI();
};
#endif // MAINWINDOW_H