egami
C++ Image Processing program
/homes/esi30/DCS339/coursework/src/Processes/sharpen.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, SHARPEN4, SHARPEN8};
00020             Config(): q("Algorithm:"), s4("Sharpen 4"), s8("Sharpen 8") {
00021                 set_resizable(false);
00022 
00023                 Gtk::RadioButton::Group group = s4.get_group();
00024                 s8.set_group(group);
00025 
00026                 get_vbox()->pack_start(q);
00027                 get_vbox()->pack_start(s4);
00028                 get_vbox()->pack_start(s8);
00029 
00030                 s4.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(s4.get_active())
00040                     return SHARPEN4;
00041                 else if(s8.get_active())
00042                     return SHARPEN8;
00043                 else
00044                     return UNKNOW;
00045             }
00046 
00047         private:
00048             Gtk::Label q;
00049             Gtk::RadioButton s4, s8;
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::SHARPEN4:{
00060                 std::array<std::array<double, 3>, 3> kernel={{{{0., -1., 0.}},{{-1., 5., -1.}},{{0., -1., 0.}}}};
00061                 return apply<1>(in, kernel, 1);
00062             } case Config::SHARPEN8:{
00063                 std::array<std::array<double, 3>, 3> kernel={{{{-1., -1., -1.}},{{-1., 9., -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 sharpen(){
00073         Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/sharpen.png"));
00074         std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "Sharpen", icon, false));
00075         Processing_page::add_unit_to_page("Convolutions", pu);
00076     }
00077 }
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends