示例#1
0
void GUI::apply_grayscale_from_menu(Controller &controller, Gtk::ImageMenuItem &imagemenuitem) {

  if ( ! controller.image_file_loaded   ) { return ; }

  // Transform image into a grayscale image according choosen settings:

  switch ( stoi(imagemenuitem.get_name()) ) {

    case 0 :

      grayscale(controller.current_image_to_process, controller.current_image_to_process, "average") ;
      break ;

    case 1 :

      grayscale(controller.current_image_to_process, controller.current_image_to_process, "max")     ;
      break ;

    case 2 :

      grayscale(controller.current_image_to_process, controller.current_image_to_process, "min")     ;
      break ;

    case 3 :

      grayscale(controller.current_image_to_process, controller.current_image_to_process, "red")     ;
      break ;

    case 4 :

      grayscale(controller.current_image_to_process, controller.current_image_to_process, "green")    ;
      break ;

    case 5 :

      grayscale(controller.current_image_to_process, controller.current_image_to_process, "blue")     ;
      break ;

    #ifdef DEBUG
    default :
      // Cannot append due of the GUI interfacing.
      fprintf(stdout,"Error applying grayscale filter !!!\n") ;
      return ;
    #endif
 
  }

  // We register current frame in vector<cv::Mat> for undo-redo.
  controller.process_after_applying() ;

  // It convert current_image_to_process as src to RGB(A) in dst current_image_to_display.
  set_img(controller.current_image_to_process, controller.current_image_to_display, controller) ;  // It auto process conversion to RGB(A).

  // Reset some variables.
  after_applying_reset_settings(controller) ;

}
示例#2
0
void GUI::apply_filter_from_menu(Controller &controller, Gtk::ImageMenuItem &imagemenuitem) {

  if ( ! controller.image_file_loaded   ) { return ; }


  bool is_alpha = controller.current_image_to_process.channels() == 4 ;

  Sharpen sharpen_filter(3, "diamond")      ;

  Sharpen sharpen_filter_more(3, "diamond") ;


  Find_Edges find_edges_filter(3) ;


  Mean mean_filter(3)      ;

  Mean mean_filter_more(5) ;


  cv::Mat kernel = make_kernel("rect", 3)  ;


  cv::Mat tmp = controller.current_image_to_process.clone() ;

  cv::Mat frame ;

  switch ( stoi(imagemenuitem.get_name()) ) {

    case 0 :
      
      // Pencil Sketch filter.
      pencil_sketch_filter(tmp, frame) ;
      break ;

    case 1 :
    
      // Stylisation filter.
      stylisation_filter(tmp, frame) ;
      break ;

    case 2 :
    
      // Detail Enhance filter.
      detail_enhance_filter(tmp, frame) ;
      break ;

    case 3 :
     
      // Edge Preserving filter.
      edge_preserving_filter(tmp, frame) ;
      break ;

    case 4 :

      // Stroke edges filter:
      stroke_edges(tmp, frame) ;
      break ;

    case 5 :

      // Invert Intensity filter:
      invert_intensity(tmp, frame) ;
      break ;

    case 6 :

      // Light Intensity filter:
      effect_light(tmp, frame) ;
      break ;

    case 7 :

      // Recolor-RC (Red-Cyan) filter:
      recolorRC(tmp, frame) ;
      break ;

    case 8 :

      // Recolor-RC (Red-Green-Value) filter:
      recolorRGV(tmp, frame) ;
      break ;

    case 9 :

      // Recolor-RC (Cyan-Magenta-Value) filter:
      recolorCMV(tmp, frame) ;
      break ;

    case 10 :

      // Extrema Maximal Filter:
      extrema(tmp, frame, "max") ;
      break ;

    case 11 :

      // Extrema Minimal Filter:
      extrema(tmp, frame, "min") ;
      break ;



    case 12 :

      // Sharpen filter:
      sharpen_filter.apply(tmp, frame)   ;
      break ;

    case 13 :

      // Sharpen More filter:
      sharpen_filter_more.apply(tmp, frame)   ;
      break ;

    case 14 :

      // Find Edges filter:

      if (is_alpha) {

        cv::Mat frame_rgb ;
        cv::Mat tmp_1     ;

        cvtColor(tmp, frame_rgb, cv::COLOR_BGRA2BGR) ;

        find_edges_filter.apply(frame_rgb, tmp_1)   ;

        vector<cv::Mat> tmp_2 ;
        vector<cv::Mat> tmp_3 ;

        cv::split(tmp,   tmp_2) ;
        cv::split(tmp_1, tmp_3) ;

        // Assign BGR channels.
        tmp_2[0] = tmp_3[0] ;
        tmp_2[1] = tmp_3[1] ;
        tmp_2[2] = tmp_3[2] ;

        // Final channels merging into result with alpha channel unchanged.
        cv::merge(tmp_2, frame) ;

        break ;


      }

      find_edges_filter.apply(tmp, frame)   ;
      break ;

    case 15 :

      // Mean Blur filter:
      mean_filter.apply(tmp, frame)   ;
      break ;

    case 16 :

      // Mean Blur More filter:
      mean_filter_more.apply(tmp, frame)   ;
      break ;


    case 17 :

      // Blur filter:
      blur_filter(tmp, frame) ;
      break ;

    case 18 :

      // Median Blur filter:
      median_blur_filter(tmp, frame) ;
      break ;

    case 19 :

      // Gaussian Blur filter:
      gaussian_blur_filter(tmp, frame) ;
      break ;

    case 20 :

      denoising_filter(tmp, frame) ;
      break ;

    case 21 :

      // Erode filter:
      erode_filter(tmp, frame, kernel, 1)   ;
      break ;

    case 22 :

      // Dilate filter:
      dilate_filter(tmp, frame, kernel, 1)   ;
      break ;

    case 23 :

      // Wave Horizontally filter:
      wave(tmp, frame, -1) ;
      break ;

    case 24 :

      // Wave Vertically filter:
      wave(tmp, frame,  1) ;
      break ;

    case 25 :

      // Wave Twice (Horizontally and Vertically) filter:
      wave(tmp, frame,  0) ;
      break ;

    case 26 :

      // Contours Sobel White filter.
      sobel_drawning(tmp, frame, 3, false, 1) ;
      break ;

    case 27 :

      // Contours Sobel Black filter.
      sobel_drawning(tmp, frame, 3, false, -1) ;
      break ;

    case 28 :

      // Contours Sobel Emboss filter.
      sobel_drawning(tmp, frame, 3, false, 0) ;
      break ;

    case 29 :

      // Emboss Sobel filter:
      sobel_emboss(tmp, frame, 3) ;
      break ;

    case 30 :

      // Emboss Laplacian filter:
      laplacian_emboss(tmp, frame, 3) ;
      break ;


    case 31 :

      // Binary White OTSU filter:
      // Build a binary image (a black and white only image) with white background (@arg value true)
      // based on the OTSU threshold computing algorithm (@arg value -1).
      build_binary_image(tmp, frame, -1, true) ;
      break ;

    case 32 :

      // Binary White TRIANGLE filter:
      // Build a binary image (a black and white only image) with white background (@arg value true)
      // based on the TRIANGLE threshold computing algorithm (@arg value 1).
      build_binary_image(tmp, frame,  1, true) ;
      break ;

    case 33 :

      // Binary White AVERAGE filter:
      // Build a binary image (a black and white only image) with white background (@arg value true)
      // based on the AVERAGE threshold from OTSU and TRIANGLE (@arg value 0).
      build_binary_image(tmp, frame,  0, true) ;
      break ;

    case 34 :

      // Binary Black OTSU filter:
      // Build a binary image (a black and white only image) with black background (@arg value true)
      // based on the OTSU threshold computing algorithm (@arg value -1).
      build_binary_image(tmp, frame, -1, false) ;
      break ;

    case 35 :

      // Binary Black TRIANGLE filter:
      // Build a binary image (a black and white only image) with black background (@arg value true)
      // based on the TRIANGLE threshold computing algorithm (@arg value 1).
      build_binary_image(tmp, frame,  1, false) ;
      break ;

    case 36 :

      // Binary Black AVERAGE filter:
      // Build a binary image (a black and white only image) with black background (@arg value true)
      // based on the AVERAGE threshold from OTSU and TRIANGLE (@arg value 0).
      build_binary_image(tmp, frame,  0, false) ;
      break ;

    case 37 :

      // Binary Contours White filter:
      // Build a binary image (a black and white only image) with contours detction on white background (@arg value false).
      laplacian_zero_crossing(tmp, frame, 19, false)  ;
      break ;

    case 38 :

      // Binary Contours Black filter:
      // Build a binary image (a black and white only image) with contours detction on black background (@arg value true).
      laplacian_zero_crossing(tmp, frame, 19, true)  ;
      break ;







    #ifdef DEBUG
    default :
      // Cannot append due of the GUI interfacing.
      fprintf(stdout,"Error applying filter !!!\n") ;
      return ;
    #endif

  }

  // We register current frame in vector<cv::Mat> for undo-redo.
  controller.process_after_applying(frame) ;

  // It convert current_image_to_process as src to RGB(A) in dst current_image_to_display.
  set_img(frame, controller.current_image_to_display, controller) ;  // It auto process conversion to RGB(A).

  // Reset some variables.
  after_applying_reset_settings(controller) ;

}
示例#3
0
void GUI::apply_colorscale_from_menu(Controller &controller, Gtk::ImageMenuItem &imagemenuitem) {

  if ( ! controller.image_file_loaded   ) { return ; }

  cv::Mat tmp = controller.current_image_to_process.clone() ;

  cv::Mat frame ;


  // Apply a colorscale on the image according choosen settings:

  switch ( stoi(imagemenuitem.get_name()) ) {

    case 0 :

      colorscale(tmp, frame, "red", "average") ;
      break ;

    case 1 :

      colorscale(tmp, frame, "red", "max") ;
      break ;

    case 2 :

      colorscale(tmp, frame, "red", "min") ;
      break ;

    case 3 :

      colorscale(tmp, frame, "red", "red") ;
      break ;

    case 4 :

      colorscale(tmp, frame, "red", "green") ;
      break ;


    case 5 :

      colorscale(tmp, frame, "green", "average") ;
      break ;

    case 6 :

      colorscale(tmp, frame, "green", "max") ;
      break ;

    case 7 :

      colorscale(tmp, frame, "green", "min") ;
      break ;

    case 8 :

      colorscale(tmp, frame, "green", "red") ;
      break ;


    case 9 :

      colorscale(tmp, frame, "green", "blue") ;
      break ;


    case 10 :

      colorscale(tmp, frame, "blue", "average") ;
      break ;

    case 11 :

      colorscale(tmp, frame, "blue", "max") ;
      break ;

    case 12 :

      colorscale(tmp, frame, "blue", "min") ;
      break ;

    case 13 :

      colorscale(tmp, frame, "blue", "red") ;
      break ;

    case 14 :

      colorscale(tmp, frame, "blue", "green") ;
      break ;



    case 15 :

      colorscale(tmp, frame, "yellow", "average") ;
      break ;

    case 16 :

      colorscale(tmp, frame, "yellow", "max") ;
      break ;

    case 17 :

      colorscale(tmp, frame, "yellow", "min") ;
      break ;

    case 18 :

      colorscale(tmp, frame, "yellow", "red") ;
      break ;

    case 19 :

      colorscale(tmp, frame, "yellow", "green") ;
      break ;

    case 20 :

      colorscale(tmp, frame, "yellow", "blue") ;
      break ;


    case 21 :

      colorscale(tmp, frame, "pink", "average") ;
      break ;

    case 22 :

      colorscale(tmp, frame, "pink", "max") ;
      break ;

    case 23 :

      colorscale(tmp, frame, "pink", "min") ;
      break ;

    case 24 :

      colorscale(tmp, frame, "pink", "red") ;
      break ;

    case 25 :

      colorscale(tmp, frame, "pink", "green") ;
      break ;

    case 26 :

      colorscale(tmp, frame, "pink", "blue") ;
      break ;


    case 27 :

      colorscale(tmp, frame, "turquoise", "average") ;
      break ;

    case 28 :

      colorscale(tmp, frame, "turquoise", "max") ;
      break ;

    case 29 :

      colorscale(tmp, frame, "turquoise", "min") ;
      break ;

    case 30 :

      colorscale(tmp, frame, "turquoise", "red") ;
      break ;

    case 31 :

      colorscale(tmp, frame, "turquoise", "green") ;
      break ;

    case 32 :

      colorscale(tmp, frame, "turquoise", "blue") ;
      break ;


    #ifdef DEBUG
    default :
      // Cannot append due of the GUI interfacing.
      fprintf(stdout,"Error applying colorscale filter !!!\n") ;
      return ;
    #endif

  }

  // We register current frame in vector<cv::Mat> for undo-redo.
  controller.process_after_applying(frame) ;

  // It convert current_image_to_process as src to RGB(A) in dst current_image_to_display.
  set_img(frame, controller.current_image_to_display, controller) ;  // It auto process conversion to RGB(A).

  // Reset some variables.
  after_applying_reset_settings(controller) ;

}