From 7abf2807659a0a8ab17032e51de1c432bc86031c Mon Sep 17 00:00:00 2001 From: Antoine Lorence <antoine.lorence@insa-rennes.fr> Date: Tue, 18 Nov 2014 13:23:26 +0100 Subject: [PATCH] [plugins] Add missing plugins files --- CMakeLists.txt | 2 +- plugins/CMakeLists.txt | 10 +- plugins/Entropy/Entropy.cpp | 129 ++++++++++++++++++++ plugins/Entropy/EntropyCorrection.cpp | 132 +++++++++++++++++++++ plugins/Entropy/main.cpp | 31 +++++ plugins/Entropy/main.h | 28 +++++ plugins/Segmentation/Segmentation/main.cpp | 31 +++++ plugins/Segmentation/Segmentation/main.h | 28 +++++ plugins/SegmentationTest/segmentation.cpp | 101 ++++++++++++++++ 9 files changed, 490 insertions(+), 2 deletions(-) create mode 100644 plugins/Entropy/Entropy.cpp create mode 100644 plugins/Entropy/EntropyCorrection.cpp create mode 100644 plugins/Entropy/main.cpp create mode 100644 plugins/Entropy/main.h create mode 100644 plugins/Segmentation/Segmentation/main.cpp create mode 100644 plugins/Segmentation/Segmentation/main.h create mode 100644 plugins/SegmentationTest/segmentation.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 68c2bbe..f502354 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,6 @@ add_subdirectory(core) include_directories(core) # Too much compile errors, have to be fixed: -# add_subdirectory(plugins) +add_subdirectory(plugins) add_subdirectory(app) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 2a66c37..f28620e 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -5,4 +5,12 @@ set(SRCS plugin.cpp Segmentation/segmentation.cpp ) -add_library(eiimage_plugins ${SRCS}) + +# add_library(segmentation SHARED Segmentation/segmentation.cpp) + +add_library(segmentation SHARED SegmentationTest/segmentation.cpp) + +add_library(entropy SHARED Entropy/Entropy.cpp) + + + diff --git a/plugins/Entropy/Entropy.cpp b/plugins/Entropy/Entropy.cpp new file mode 100644 index 0000000..94a1f51 --- /dev/null +++ b/plugins/Entropy/Entropy.cpp @@ -0,0 +1,129 @@ +/* + * Copyright 2011-2012 INSA Rennes + * + * This file is part of EIImage. + * + * EIImage 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. + * + * EIImage 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 EIImage. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <iostream> +#include <string> + +#include "Image.h" +#include "Converter.h" + +#include "Operation.h" +#include "Plugin.h" +#include "ImgParam.h" +#include "IntParam.h" +#include "PlugOperation.h" + +#include <cstring> +#include <cstdio> +#include <cmath> + +using namespace std; +using namespace imagein; + + +class EntropyOp : public PlugOperation { + public: + EntropyOp() : PlugOperation("Entropy") { + addParam(CurrentImg(), &EntropyOp::img); +// addParam(IntParam("Entier", 0, 255, 127), &Entropy::threshold); + //this->addParam(ImgParam("Image"), &Entropy::img); + } + + void operation() { + + double entropy = 0.; + + // for each image channel + for(unsigned int c = 0; c < img.getNbChannels(); ++c) { + Histogram histo = img.getHistogram(c); + + // A MODIFIER !!!!! + // histo est un tableau + //img.getWidth() et img.getHeight() peuvent être pratiques pour trouver les dimensions de l'image... + + } + entropy = - entropy / log(2); + + // this->outImage(result); + char buffer[255]; + sprintf( buffer, "Entropy of the image = %.2f bpp", entropy ); + string s = buffer ; + outText(s); + } + private: + Image img; +}; + +extern "C" Plugin* loadPlugin() { + Plugin* plugin = new Plugin("Entropy"); + plugin->addOperation(new EntropyOp()); + return plugin; +} + +extern "C" void unloadPlugin(Plugin* plugin) { + delete plugin; +} + +// +//extern "C" Plugin* getPlugin() { +// Plugin* myPlugin = new MyPlugin("ImageRef"); +// return myPlugin; +//} +// +//class MyOperation : public Operation { +// public: +// MyOperation(string name) : Operation(name) { +// //this->addParam(ImgParam("image"), &MyOperation::image); +// //this->addParam(CurrentImg(), &MyOperation::img); +// //this->addParam(IntParam("Entier", 0, 255, 127), &MyOperation::n); +// } +// +// void operation() { +// cout << "n = " << n << endl; +// +// Image* res = generateRefImg(); +// +// this->addOutput(ImgOutput("ImageRef", *res)); +// } +// private: +// int n; +// Image img; +//}; +// +//class MyPlugin : public Plugin { +// public: +// MyPlugin(string name) : Plugin(name) { +// try { +// MyOperation* op = new MyOperation("Générer image"); +// this->addOperation(op); +// //this->addOperation(new Identity("Identité")); +// /*MyOperation* op2 = new MyOperation("Dilatation"); +// this->addOperation(op2);*/ +// } +// catch(const char* msg) { +// std::cerr << msg << std::endl; +// } +// } +//}; +// +// +//extern "C" Plugin* getPlugin() { +// Plugin* myPlugin = new MyPlugin("ImageRef"); +// return myPlugin; +//} diff --git a/plugins/Entropy/EntropyCorrection.cpp b/plugins/Entropy/EntropyCorrection.cpp new file mode 100644 index 0000000..64c6515 --- /dev/null +++ b/plugins/Entropy/EntropyCorrection.cpp @@ -0,0 +1,132 @@ +/* + * Copyright 2011-2012 INSA Rennes + * + * This file is part of EIImage. + * + * EIImage 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. + * + * EIImage 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 EIImage. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <iostream> +#include <string> + +#include "Image.h" +#include "Converter.h" + +#include "Operation.h" +#include "Plugin.h" +#include "ImgParam.h" +#include "IntParam.h" +#include "PlugOperation.h" + +#include <cstring> +#include <cstdio> +#include <cmath> + +using namespace std; +using namespace imagein; + + +class EntropyOp : public PlugOperation { + public: + EntropyOp() : PlugOperation("Entropy") { + addParam(CurrentImg(), &EntropyOp::img); +// addParam(IntParam("Entier", 0, 255, 127), &Entropy::threshold); + //this->addParam(ImgParam("Image"), &Entropy::img); + } + + void operation() { + + double entropy = 0.; + + // for each image channel + for(unsigned int c = 0; c < img.getNbChannels(); ++c) { + Histogram histo = img.getHistogram(c); + + // A MODIFIER !!!!! + for(int i = 0; i < 256; ++i) { + if(histo[i] > 0) { + double p = (double)histo[i] / img.getWidth() /img.getHeight(); + entropy += p * log(p); + } + } + } + entropy = - entropy / log(2); + + // this->outImage(result); + char buffer[255]; + sprintf( buffer, "Entropy of the image = %.2f bpp", entropy ); + string s = buffer ; + outText(s); + } + private: + Image img; +}; + +extern "C" Plugin* loadPlugin() { + Plugin* plugin = new Plugin("Entropy"); + plugin->addOperation(new EntropyOp()); + return plugin; +} + +extern "C" void unloadPlugin(Plugin* plugin) { + delete plugin; +} + +// +//extern "C" Plugin* getPlugin() { +// Plugin* myPlugin = new MyPlugin("ImageRef"); +// return myPlugin; +//} +// +//class MyOperation : public Operation { +// public: +// MyOperation(string name) : Operation(name) { +// //this->addParam(ImgParam("image"), &MyOperation::image); +// //this->addParam(CurrentImg(), &MyOperation::img); +// //this->addParam(IntParam("Entier", 0, 255, 127), &MyOperation::n); +// } +// +// void operation() { +// cout << "n = " << n << endl; +// +// Image* res = generateRefImg(); +// +// this->addOutput(ImgOutput("ImageRef", *res)); +// } +// private: +// int n; +// Image img; +//}; +// +//class MyPlugin : public Plugin { +// public: +// MyPlugin(string name) : Plugin(name) { +// try { +// MyOperation* op = new MyOperation("Générer image"); +// this->addOperation(op); +// //this->addOperation(new Identity("Identité")); +// /*MyOperation* op2 = new MyOperation("Dilatation"); +// this->addOperation(op2);*/ +// } +// catch(const char* msg) { +// std::cerr << msg << std::endl; +// } +// } +//}; +// +// +//extern "C" Plugin* getPlugin() { +// Plugin* myPlugin = new MyPlugin("ImageRef"); +// return myPlugin; +//} diff --git a/plugins/Entropy/main.cpp b/plugins/Entropy/main.cpp new file mode 100644 index 0000000..9563a95 --- /dev/null +++ b/plugins/Entropy/main.cpp @@ -0,0 +1,31 @@ +#include "main.h" + +// a sample exported function +void DLL_EXPORT SomeFunction(const LPCSTR sometext) +{ + MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION); +} + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + // attach to process + // return FALSE to fail DLL load + break; + + case DLL_PROCESS_DETACH: + // detach from process + break; + + case DLL_THREAD_ATTACH: + // attach to thread + break; + + case DLL_THREAD_DETACH: + // detach from thread + break; + } + return TRUE; // succesful +} diff --git a/plugins/Entropy/main.h b/plugins/Entropy/main.h new file mode 100644 index 0000000..2bd887e --- /dev/null +++ b/plugins/Entropy/main.h @@ -0,0 +1,28 @@ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include <windows.h> + +/* To use this exported function of dll, include this header + * in your project. + */ + +#ifdef BUILD_DLL + #define DLL_EXPORT __declspec(dllexport) +#else + #define DLL_EXPORT __declspec(dllimport) +#endif + + +#ifdef __cplusplus +extern "C" +{ +#endif + +void DLL_EXPORT SomeFunction(const LPCSTR sometext); + +#ifdef __cplusplus +} +#endif + +#endif // __MAIN_H__ diff --git a/plugins/Segmentation/Segmentation/main.cpp b/plugins/Segmentation/Segmentation/main.cpp new file mode 100644 index 0000000..9563a95 --- /dev/null +++ b/plugins/Segmentation/Segmentation/main.cpp @@ -0,0 +1,31 @@ +#include "main.h" + +// a sample exported function +void DLL_EXPORT SomeFunction(const LPCSTR sometext) +{ + MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION); +} + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + // attach to process + // return FALSE to fail DLL load + break; + + case DLL_PROCESS_DETACH: + // detach from process + break; + + case DLL_THREAD_ATTACH: + // attach to thread + break; + + case DLL_THREAD_DETACH: + // detach from thread + break; + } + return TRUE; // succesful +} diff --git a/plugins/Segmentation/Segmentation/main.h b/plugins/Segmentation/Segmentation/main.h new file mode 100644 index 0000000..2bd887e --- /dev/null +++ b/plugins/Segmentation/Segmentation/main.h @@ -0,0 +1,28 @@ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include <windows.h> + +/* To use this exported function of dll, include this header + * in your project. + */ + +#ifdef BUILD_DLL + #define DLL_EXPORT __declspec(dllexport) +#else + #define DLL_EXPORT __declspec(dllimport) +#endif + + +#ifdef __cplusplus +extern "C" +{ +#endif + +void DLL_EXPORT SomeFunction(const LPCSTR sometext); + +#ifdef __cplusplus +} +#endif + +#endif // __MAIN_H__ diff --git a/plugins/SegmentationTest/segmentation.cpp b/plugins/SegmentationTest/segmentation.cpp new file mode 100644 index 0000000..dc73fe4 --- /dev/null +++ b/plugins/SegmentationTest/segmentation.cpp @@ -0,0 +1,101 @@ +/* + * Copyright 2011-2012 INSA Rennes + * + * This file is part of EIImage. + * + * EIImage 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. + * + * EIImage 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 EIImage. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <iostream> +#include <string> + +#include "Image.h" +#include "Algorithm/Binarization.h" +#include "Algorithm/Otsu.h" +#include "Algorithm/Dithering.h" +#include "Converter.h" + +#include "Operation.h" +#include "Plugin.h" +#include "ImgParam.h" +#include "IntParam.h" + +#include "Input.h" +#include "Parameter.h" + +using namespace std; +using namespace imagein; + +class Thresholding : public PlugOperation { + public: + Thresholding() : PlugOperation("Thresholding") { + addParam(CurrentImg(), &Thresholding::img); + addParam(IntParam("Entier", 0, 255, 127), &Thresholding::threshold); + } + + void operation() { + algorithm::Binarization_t<depth_default_t> thresholding(threshold); + GrayscaleImage* grayImg = imagein::Converter<GrayscaleImage>::convert(img); + GrayscaleImage* result = thresholding(grayImg); + outImage(result); + } + private: + int threshold; + Image img; +}; + +class Otsu : public PlugOperation { + public: + Otsu() : PlugOperation("Otsu") { + this->addParam(CurrentImg(), &Otsu::img); + } + + void operation() { + algorithm::Otsu_t<depth_default_t> otsu; + GrayscaleImage* grayImg = imagein::Converter<GrayscaleImage>::convert(img); + GrayscaleImage* result = otsu(grayImg); + outImage(result); + } + private: + Image img; +}; + +class Dithering : public PlugOperation { + public: + Dithering() : PlugOperation("Dithering") { + this->addParam(CurrentImg(), &Dithering::img); +// this->addParam(ImgParam("Image"), &Dithering::img); + } + + void operation() { + algorithm::Dithering_t<depth_default_t> dithering; + Image* result = dithering(&img); + this->outImage(result); + this->outText("test"); + } + private: + Image img; +}; + +extern "C" Plugin* loadPlugin() { + Plugin* plugin = new Plugin("Binarization"); + plugin->addOperation(new Thresholding()); + plugin->addOperation(new Otsu()); + plugin->addOperation(new Dithering()); + return plugin; +} + +extern "C" void unloadPlugin(Plugin* plugin) { + delete plugin; +} -- GitLab