From 66b14d59648664d3848494507ffa4c9911e8ce14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Tue, 21 Jan 2020 21:23:45 +0100 Subject: [PATCH] First prototype --- clahe.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ clahe.h | 23 +++++++++++++++++++++++ clahe.pro | 41 +++++++++++++++++++++++++++++++++++++++++ main.cpp | 11 +++++++++++ mainwindow.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ mainwindow.h | 21 +++++++++++++++++++++ 6 files changed, 194 insertions(+) create mode 100644 clahe.cpp create mode 100644 clahe.h create mode 100644 clahe.pro create mode 100644 main.cpp create mode 100644 mainwindow.cpp create mode 100644 mainwindow.h diff --git a/clahe.cpp b/clahe.cpp new file mode 100644 index 0000000..9c8673c --- /dev/null +++ b/clahe.cpp @@ -0,0 +1,50 @@ +#include "clahe.h" +#include + +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); +} diff --git a/clahe.h b/clahe.h new file mode 100644 index 0000000..293383d --- /dev/null +++ b/clahe.h @@ -0,0 +1,23 @@ +#ifndef CLAHE_H +#define CLAHE_H + +#include +#include +#include +#include +#include + +class CLAHE +{ + cv::Mat _lumImage; + cv::Mat _image[3]; + cv::Ptr _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 diff --git a/clahe.pro b/clahe.pro new file mode 100644 index 0000000..4443899 --- /dev/null +++ b/clahe.pro @@ -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 diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..5fe6922 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,48 @@ +#include "mainwindow.h" +#include +#include +#include +#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); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..fcb7545 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,21 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include + +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