diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index c3f26e926910838cdf25bc77466802f72c6c66f3..adb04e2c9fc5d6d836974d31f1b89279d6349960 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -19,6 +19,8 @@ set(imageinsa_SOURCES Algorithms/Pyramid.h Operations/AbsoluteConvertOp.cpp Operations/AbsoluteConvertOp.h + Operations/BinaryMaskOp.cpp + Operations/BinaryMaskOp.h Operations/BFlitOp.cpp Operations/BFlitOp.h Operations/CenterOp.cpp diff --git a/app/Operations/BinaryMaskOp.cpp b/app/Operations/BinaryMaskOp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3536e4bda1a0832027d05458b29d6b609b2ba2d7 --- /dev/null +++ b/app/Operations/BinaryMaskOp.cpp @@ -0,0 +1,129 @@ +/* + * Copyright 2011-2012 INSA Rennes + * + * This file is part of ImageINSA. + * + * ImageINSA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ImageINSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ImageINSA. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "BinaryMaskOp.h" +#include "Widgets/ImageListBox.h" +#include <Widgets/ImageWidgets/StandardImageWindow.h> +#include <QFormLayout> +#include <QDialogButtonBox> + +using namespace std; +using namespace imagein; +using namespace genericinterface; + +BinaryMaskOp::BinaryMaskOp() : GenericOperation(qApp->translate("Operations", "Apply mask").toStdString()) +{ +} + +bool BinaryMaskOp::needCurrentImg() const { + return true; +} + +void BinaryMaskOp::operator()(const ImageWindow *currentWnd, + const vector<const ImageWindow *> &imgWndList) { + + QString currentImgName = currentWnd->windowTitle(); + map<const Image*,string> stdImgList; + map<const Image_t<double>*,string> dblImgList; + for(auto it : imgWndList) { + if(it->isStandard()) { + const auto* stdImgWnd = dynamic_cast<const StandardImageWindow*>(it); + stdImgList.insert(pair<const Image*, string>(stdImgWnd->getImage(), stdImgWnd->windowTitle().toStdString())); + } + else if(it->isDouble()) { + const auto* dblImgWnd = dynamic_cast<const DoubleImageWindow*>(it); + dblImgList.insert(pair<const Image_t<double>*, string>(dblImgWnd->getImage(), dblImgWnd->windowTitle().toStdString())); + } + } + + +/* QDialog* dialog = new QDialog(currentWnd);*/ + auto* dialog = new QDialog(QApplication::activeWindow()); + /*dialog = new QuantificationDialog(QApplication::activeWindow(), imgName);*/ + + dialog->setWindowTitle(currentImgName); + auto* layout = new QFormLayout(dialog); + auto* imgBox = new MixImageListBox(dialog, currentImgName.toStdString(), stdImgList, dblImgList); + layout->insertRow(0, tr("Mask to apply : "), imgBox); + auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, dialog); + layout->insertRow(1, buttonBox); + QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); + QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); + + auto code = static_cast<QDialog::DialogCode>(dialog->exec()); + + if(code!=QDialog::Accepted) return; + + Image_t<double>* mask; + if(imgBox->currentType() == MixImageListBox::STDIMG) { + const Image* stdImg = imgBox->getStdImage(imgBox->currentText().toStdString()); + if(stdImg == nullptr) return; + mask = Converter<Image_t<double> >::convert(*stdImg); + } + else if(imgBox->currentType() == MixImageListBox::DBLIMG) { + const Image_t<double>* dblImg = imgBox->getDblImage(imgBox->currentText().toStdString()); + if(dblImg == nullptr) return; + mask = new Image_t<double>(*dblImg); + } + else return; + + Image_t<double>* img; + if(currentWnd->isStandard()) { + const auto* siw = dynamic_cast<const StandardImageWindow*>(currentWnd); + img = Converter<Image_t<double> >::convert(*siw->getImage()); + } + else if(currentWnd->isDouble()) { + const auto* diw = dynamic_cast<const DoubleImageWindow*>(currentWnd); + img = new Image_t<double>(*diw->getImage()); + } + +// const double mean = (mask->max() - mask->min()) / 2.; + const double max = mask->max(); + for(Image_t<double>::iterator it = mask->begin(); it < mask->end(); ++it) { +// *it = (*it < mean) ? 0. : 1.; + *it = *it / max; + } + + const unsigned int width = min(mask->getWidth(), img->getWidth()); + const unsigned int height = min(mask->getHeight(), img->getHeight()); + auto* resImg = new Image_t<double>(width, height, img->getNbChannels()); + for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) { + const unsigned int maskChannel = mask->getNbChannels() >= img->getNbChannels() ? c : 0; + for(unsigned int j = 0; j < resImg->getHeight(); ++j) { + for(unsigned int i = 0; i < resImg->getWidth(); ++i) { + resImg->pixelAt(i, j, c) = img->pixelAt(i, j, c) * mask->pixelAt(i, j, maskChannel); + } + } + } + delete img; + delete mask; + + if(currentWnd->isStandard()) { + Image* stdImg = Converter<Image>::convertAndRound(*resImg); + delete resImg; + this->outImage(stdImg, currentImgName.toStdString()); + } + else if(currentWnd->isDouble()) { + this->outDoubleImage(resImg, currentImgName.toStdString()); + } +} + +bool BinaryMaskOp::isValidImgWnd(const genericinterface::ImageWindow *imgWnd) const { + return (imgWnd && (imgWnd->isStandard() || imgWnd->isDouble())); +} diff --git a/app/Operations/BinaryMaskOp.h b/app/Operations/BinaryMaskOp.h new file mode 100644 index 0000000000000000000000000000000000000000..bed62c47312945f1424a35a789eb772cc6106d41 --- /dev/null +++ b/app/Operations/BinaryMaskOp.h @@ -0,0 +1,38 @@ +/* + * Copyright 2011-2012 INSA Rennes + * + * This file is part of ImageINSA. + * + * ImageINSA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ImageINSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ImageINSA. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef IMAGEINSA_BINARYMASKOP_H +#define IMAGEINSA_BINARYMASKOP_H + +#include <Operation.h> + +class BinaryMaskOp : public GenericOperation{ + + public: + BinaryMaskOp(); + void operator()(const genericinterface::ImageWindow* currentWnd, const std::vector<const genericinterface::ImageWindow*>& imgWndList) override; + + bool needCurrentImg() const override; + + bool isValidImgWnd(const genericinterface::ImageWindow* imgWnd) const override; + +}; + + +#endif //IMAGEINSA_BINARYMASKOP_H \ No newline at end of file diff --git a/app/main.cpp b/app/main.cpp index bedb6fcec3f293443d099aeddc839f8a87e0df7a..9e4eda0e2d6022b4280b000fc69ad0e814a60693 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -31,6 +31,7 @@ #include "Services/ImageINSAService.h" #include "Operations/AbsoluteConvertOp.h" +#include "Operations/BinaryMaskOp.h" #include "Operations/DoubleConvertOp.h" #include "Operations/PointOp.h" #include "Operations/ThresholdOp.h" @@ -148,11 +149,14 @@ int main(int argc, char** argv) image->addOperation(new QuantificationOp()); image->addOperation(new ThresholdOp()); image->addOperation(new SeparatorOp()); + image->addOperation(new BinaryMaskOp()); + image->addOperation(new SeparatorOp()); image->addOperation(new HistogramOp()); image->addOperation(new PointOp()); image->addOperation(new SeparatorOp()); image->addOperation(new NoiseOp()); + //Ã mettre dans oclors /* */ diff --git a/lib/detiq-t b/lib/detiq-t index f6418cfd71c2e8b3b02743b8984d41daa0a9cdbc..1c3344bb8e8d93d17b97d4fa96e24554d72c3b6f 160000 --- a/lib/detiq-t +++ b/lib/detiq-t @@ -1 +1 @@ -Subproject commit f6418cfd71c2e8b3b02743b8984d41daa0a9cdbc +Subproject commit 1c3344bb8e8d93d17b97d4fa96e24554d72c3b6f