egami
C++ Image Processing program
/homes/esi30/DCS339/coursework/src/Processes/sobel.cpp
Go to the documentation of this file.
00001 #include <array>
00002 #include <memory>
00003 #include <string>
00004 
00005 #include <gtkmm/image.h>
00006 #include <gtkmm/dialog.h>
00007 #include <gtkmm/checkbutton.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 #include "utils.hpp"
00016 
00017 namespace{
00018     class Config: public Gtk::Dialog {
00019         public:
00020             Config(): q("Algorithm:"), sX("Sobel X"), s45("Sobel 45"), sY("Sobel Y"), s135("Sobel 135") {
00021                 set_resizable(false);
00022 
00023                 get_vbox()->pack_start(q);
00024                 get_vbox()->pack_start(sX);
00025                 get_vbox()->pack_start(s45);
00026                 get_vbox()->pack_start(sY);
00027                 get_vbox()->pack_start(s135);
00028 
00029                 sX.set_active();
00030                 s45.set_active();
00031                 sY.set_active();
00032                 s135.set_active();
00033 
00034                 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
00035                 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
00036 
00037                 show_all_children();
00038             }
00039 
00040             bool is_act() const {
00041                 return sX.get_active() || s45.get_active() || sY.get_active() || s135.get_active();
00042             }
00043 
00044             bool do_sX() const {
00045                 return sX.get_active();
00046             }
00047 
00048             bool do_s45() const {
00049                 return s45.get_active();
00050             }
00051 
00052             bool do_sY() const {
00053                 return sY.get_active();
00054             }
00055 
00056             bool do_s135() const {
00057                 return s135.get_active();
00058             }
00059 
00060         private:
00061             Gtk::Label q;
00062             Gtk::CheckButton sX, s45, sY, s135;
00063     };
00064 
00065     Display_unit* impl(const Image_unit *in){
00066         Config c;
00067         if(c.run()!=Gtk::RESPONSE_OK || !(c.is_act()))
00068             return nullptr;
00069         c.hide();
00070 
00071         Image_unit *out=nullptr;
00072 
00073         if(c.do_sX()){
00074             std::array<std::array<double, 3>, 3> kernel={{{{-1., 0., 1.}},{{-2., 0., 2.}},{{-1., 0., 1.}}}};
00075             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00076             add_max(&out, tmp.get());
00077         }
00078         if(c.do_s45()){
00079             std::array<std::array<double, 3>, 3> kernel={{{{-2., -1., 0.}},{{-1., 0., 1.}},{{0., 1., 2.}}}};
00080             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00081             add_max(&out, tmp.get());
00082         }
00083         if(c.do_sY()){
00084             std::array<std::array<double, 3>, 3> kernel={{{{-1., -2., -1.}},{{0., 0., 0.}},{{1., 2., 1.}}}};
00085             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00086             add_max(&out, tmp.get());
00087         }
00088         if(c.do_s135()){
00089             std::array<std::array<double, 3>, 3> kernel={{{{0., 1., 2.}},{{-1., 0., 1.}},{{-2., -1., 0.}}}};
00090             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00091             add_max(&out, tmp.get());
00092         }
00093 
00094         return out;
00095     }
00096 }
00097 
00098 namespace Processes{
00099     void sobel(){
00100         Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/sobel.png"));
00101         std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "Sobel", icon, false));
00102         Processing_page::add_unit_to_page("Edge detection", pu);
00103     }
00104 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends