egami
C++ Image Processing program
|
00001 #include <memory> 00002 #include <string> 00003 00004 #include <gtkmm/image.h> 00005 #include <gtkmm/dialog.h> 00006 #include <gtkmm/radiobutton.h> 00007 #include <gtkmm/stock.h> 00008 00009 #include "../display_unit.hpp" 00010 #include "../processing_page.hpp" 00011 #include "../processing_unit.hpp" 00012 #include "../utils.hpp" 00013 #include "convolution.hpp" 00014 00015 namespace{ 00016 class Config: public Gtk::Dialog { 00017 public: 00018 enum Mode {UNKNOW, SIMPLE, WEIGHTED, GAUSSIAN}; 00019 Config(): q("Algorithm:"), bs("Simple"), bw("Weighted"), bg("Gaussian") { 00020 set_resizable(false); 00021 00022 Gtk::RadioButton::Group group = bs.get_group(); 00023 bw.set_group(group); 00024 bg.set_group(group); 00025 00026 get_vbox()->pack_start(q); 00027 get_vbox()->pack_start(bs); 00028 get_vbox()->pack_start(bw); 00029 get_vbox()->pack_start(bg); 00030 00031 bs.set_active(); 00032 00033 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); 00034 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 00035 00036 show_all_children(); 00037 } 00038 00039 Mode mode(){ 00040 if(bs.get_active()) 00041 return SIMPLE; 00042 else if(bw.get_active()) 00043 return WEIGHTED; 00044 else if(bg.get_active()) 00045 return GAUSSIAN; 00046 else 00047 return UNKNOW; 00048 } 00049 00050 private: 00051 Gtk::Label q; 00052 Gtk::RadioButton bs, bw, bg; 00053 }; 00054 00055 Display_unit* impl(const Image_unit *in){ 00056 Config c; 00057 if(c.run()!=Gtk::RESPONSE_OK) 00058 return nullptr; 00059 c.hide(); 00060 00061 switch(c.mode()){ 00062 case Config::SIMPLE:{ 00063 std::array<std::array<double, 3>, 3> kernel={{{{1., 1., 1.}},{{1., 1., 1.}},{{1., 1., 1.}}}}; 00064 return apply<1>(in, kernel, 9); 00065 } case Config::WEIGHTED:{ 00066 std::array<std::array<double, 3>, 3> kernel={{{{1., 2., 1.}},{{2., 4., 2.}},{{1., 2., 1.}}}}; 00067 return apply<1>(in, kernel, 16); 00068 } case Config::GAUSSIAN:{ 00069 std::array<std::array<double, 5>, 5> kernel={{{{1., 4., 6., 4., 1.}}, 00070 {{4., 16., 24., 16., 4.}}, 00071 {{6., 24., 36., 24., 6.}}, 00072 {{4., 16., 24., 16., 4.}}, 00073 {{1., 4., 6., 4., 1.}}}}; 00074 return apply<2>(in, kernel, 256); 00075 } default: 00076 return nullptr; 00077 } 00078 } 00079 } 00080 00081 namespace Processes{ 00082 void blur(){ 00083 Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/blur.png")); 00084 std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "Blur", icon, false)); 00085 Processing_page::add_unit_to_page("Convolutions", pu); 00086 } 00087 }