egami
C++ Image Processing program
/homes/esi30/DCS339/coursework/src/Processes/prewitt.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:"), pX("Prewitt X"), p45("Prewitt 45"), pY("Prewitt Y"), p135("Prewitt 135") {
00021                 set_resizable(false);
00022 
00023                 get_vbox()->pack_start(q);
00024                 get_vbox()->pack_start(pX);
00025                 get_vbox()->pack_start(p45);
00026                 get_vbox()->pack_start(pY);
00027                 get_vbox()->pack_start(p135);
00028 
00029                 pX.set_active();
00030                 p45.set_active();
00031                 pY.set_active();
00032                 p135.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 pX.get_active() || p45.get_active() || pY.get_active() || p135.get_active();
00042             }
00043 
00044             bool do_pX() const {
00045                 return pX.get_active();
00046             }
00047 
00048             bool do_p45() const {
00049                 return p45.get_active();
00050             }
00051 
00052             bool do_pY() const {
00053                 return pY.get_active();
00054             }
00055 
00056             bool do_p135() const {
00057                 return p135.get_active();
00058             }
00059 
00060         private:
00061             Gtk::Label q;
00062             Gtk::CheckButton pX, p45, pY, p135;
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 
00070         Image_unit *out=nullptr;
00071 
00072         if(c.do_pX()){
00073             std::array<std::array<double, 3>, 3> kernel={{{{-1., -1., -1.}},{{-1., 0., 1.}},{{1., 1., 1.}}}};
00074             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00075             add_max(&out, tmp.get());
00076         }
00077         if(c.do_p45()){
00078             std::array<std::array<double, 3>, 3> kernel={{{{-1., -1., 0.}},{{-1., 0., 1.}},{{0., 1., 1.}}}};
00079             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00080             add_max(&out, tmp.get());
00081         }
00082         if(c.do_pY()){
00083             std::array<std::array<double, 3>, 3> kernel={{{{-1., 0., 1.}},{{-1., 0., 1.}},{{-1., 0., 1.}}}};
00084             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00085             add_max(&out, tmp.get());
00086         }
00087         if(c.do_p135()){
00088             std::array<std::array<double, 3>, 3> kernel={{{{0., -1., -1.}},{{-1., 0., 1.}},{{1., 1., 0.}}}};
00089             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00090             add_max(&out, tmp.get());
00091         }
00092 
00093         return out;
00094     }
00095 }
00096 
00097 namespace Processes{
00098     void prewitt(){
00099         Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/prewitt.png"));
00100         std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "Prewitt", icon, false));
00101         Processing_page::add_unit_to_page("Edge detection", pu);
00102     }
00103 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends