egami
C++ Image Processing program
/homes/esi30/DCS339/coursework/src/Processes/laplacian.cpp
Go to the documentation of this file.
00001 #include <algorithm>
00002 #include <memory>
00003 #include <string>
00004 
00005 #include <gtkmm/image.h>
00006 #include <gtkmm/dialog.h>
00007 #include <gtkmm/radiobutton.h>
00008 #include <gtkmm/stock.h>
00009 
00010 #include "../display_unit.hpp"
00011 #include "../processing_page.hpp"
00012 #include "../processing_unit.hpp"
00013 #include "../utils.hpp"
00014 #include "convolution.hpp"
00015 
00016 namespace{
00017     class Config: public Gtk::Dialog {
00018         public:
00019             enum Mode {UNKNOW, LAPLACIAN4, LAPLACIAN8};
00020             Config(): q("Algorithm:"), l4("Laplacian 4"), l8("Laplacian 8") {
00021                 set_resizable(false);
00022 
00023                 Gtk::RadioButton::Group group = l4.get_group();
00024                 l8.set_group(group);
00025 
00026                 get_vbox()->pack_start(q);
00027                 get_vbox()->pack_start(l4);
00028                 get_vbox()->pack_start(l8);
00029 
00030                 l4.set_active();
00031 
00032                 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
00033                 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
00034 
00035                 show_all_children();
00036             }
00037 
00038             Mode mode(){
00039                 if(l4.get_active())
00040                     return LAPLACIAN4;
00041                 else if(l8.get_active())
00042                     return LAPLACIAN8;
00043                 else
00044                     return UNKNOW;
00045             }
00046 
00047         private:
00048             Gtk::Label q;
00049             Gtk::RadioButton l4, l8;
00050     };
00051 
00052     Display_unit* impl(const Image_unit *in){
00053         Config c;
00054         if(c.run()!=Gtk::RESPONSE_OK)
00055             return nullptr;
00056         c.hide();
00057 
00058         switch(c.mode()){
00059             case Config::LAPLACIAN4:{
00060                 std::array<std::array<double, 3>, 3> kernel={{{{0., -1., 0.}},{{-1., 4., -1.}},{{0., -1., 0.}}}};
00061                 return apply<1>(in, kernel, 1);
00062             } case Config::LAPLACIAN8:{
00063                 std::array<std::array<double, 3>, 3> kernel={{{{-1., -1., -1.}},{{-1., 8., -1.}},{{-1., -1., -1.}}}};
00064                 return apply<1>(in, kernel, 1);
00065             } default:
00066                 return nullptr;
00067         }
00068     }
00069 }
00070 
00071 namespace Processes{
00072     void laplacian(){
00073         Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/laplacian.png"));
00074         std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "Laplacian", icon, false));
00075         Processing_page::add_unit_to_page("Edge detection", pu);
00076     }
00077 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends