egami
C++ Image Processing program
|
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:"), l0("Line 0"), l45("Line 45"), l90("Line 90"), l135("Line 135") { 00021 set_resizable(false); 00022 00023 get_vbox()->pack_start(q); 00024 get_vbox()->pack_start(l0); 00025 get_vbox()->pack_start(l45); 00026 get_vbox()->pack_start(l90); 00027 get_vbox()->pack_start(l135); 00028 00029 l0.set_active(); 00030 l45.set_active(); 00031 l90.set_active(); 00032 l135.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 l0.get_active() || l45.get_active() || l90.get_active() || l135.get_active(); 00042 } 00043 00044 bool do_l0() const { 00045 return l0.get_active(); 00046 } 00047 00048 bool do_l45() const { 00049 return l45.get_active(); 00050 } 00051 00052 bool do_l90() const { 00053 return l90.get_active(); 00054 } 00055 00056 bool do_l135() const { 00057 return l135.get_active(); 00058 } 00059 00060 private: 00061 Gtk::Label q; 00062 Gtk::CheckButton l0, l45, l90, l135; 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_l0()){ 00074 std::array<std::array<double, 3>, 3> kernel={{{{-1., -1., -1.}},{{2., 2., 2.}},{{-1., -1., -1.}}}}; 00075 std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1)); 00076 add_max(&out, tmp.get()); 00077 } 00078 if(c.do_l45()){ 00079 std::array<std::array<double, 3>, 3> kernel={{{{-1., -1., 2.}},{{-1., 2., -1.}},{{2., -1., -1.}}}}; 00080 std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1)); 00081 add_max(&out, tmp.get()); 00082 } 00083 if(c.do_l90()){ 00084 std::array<std::array<double, 3>, 3> kernel={{{{-1., 2., -1.}},{{-1., 2., -1.}},{{-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_l135()){ 00089 std::array<std::array<double, 3>, 3> kernel={{{{2., -1., -1.}},{{-1., 2., -1.}},{{-1., -1., 2.}}}}; 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 line(){ 00100 Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/line.png")); 00101 std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "Line", icon, false)); 00102 Processing_page::add_unit_to_page("Edge detection", pu); 00103 } 00104 }