egami
C++ Image Processing program
|
00001 #include <algorithm> 00002 #include <memory> 00003 #include <string> 00004 00005 #include <gtkmm/image.h> 00006 00007 #include "../display_unit.hpp" 00008 #include "../processing_page.hpp" 00009 #include "../processing_unit.hpp" 00010 #include "../utils.hpp" 00011 #include "convolution.hpp" 00012 00013 namespace{ 00014 Display_unit* impl(const Image_unit *in){ 00015 std::array<double, 256> red_hist{{}}, green_hist{{}}, blue_hist{{}}; 00016 00017 for(auto pixel: *in){ 00018 red_hist[pixel.r]++; 00019 green_hist[pixel.g]++; 00020 blue_hist[pixel.b]++; 00021 } 00022 00023 for(unsigned short i=1; i<256; ++i){ 00024 red_hist[i]+=red_hist[i-1]; 00025 green_hist[i]+=green_hist[i-1]; 00026 blue_hist[i]+=blue_hist[i-1]; 00027 } 00028 00029 for(unsigned short i=1; i<256; ++i){ 00030 red_hist[i]/=static_cast<double>(in->height()*in->width())/255; 00031 green_hist[i]/=static_cast<double>(in->height()*in->width())/255; 00032 blue_hist[i]/=static_cast<double>(in->height()*in->width())/255; 00033 } 00034 00035 Image_unit *out(new Image_unit(*in)); 00036 for(auto pixel: *out){ 00037 pixel.r=red_hist[pixel.r]; 00038 pixel.g=green_hist[pixel.g]; 00039 pixel.b=blue_hist[pixel.b]; 00040 } 00041 00042 return out; 00043 } 00044 } 00045 00046 namespace Processes{ 00047 void histogram_equalisation(){ 00048 Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/histogram_equalisation.png")); 00049 std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "H. equalisation", icon, false)); 00050 Processing_page::add_unit_to_page("Colours", pu); 00051 } 00052 }