示例#1
0
void filter_average(AVFrame * pFrame, int width, int height)
{
	int y, k;
	// Aplicando filtro dos borroes
	#pragma omp parallel shared(pFrame) private(y, k)
	{
		#pragma omp for
		for(y = 1; y < height - 1; y++)
		{
			for(k = 3; k < 3 * (width - 1); k += 3)
			{
				uint8_t * center = (pFrame->data[0] + y*pFrame->linesize[0] + k);
				uint8_t left = *(pFrame->data[0] + y*pFrame->linesize[0] + k - 3);
				uint8_t right = *(pFrame->data[0] + y*pFrame->linesize[0] + k + 3);
				uint8_t top = *(pFrame->data[0] + (y - 1)*pFrame->linesize[0] + k);
				uint8_t bottom = *(pFrame->data[0] + (y + 1)*pFrame->linesize[0] + k);
				blur_filter(center, left, right, top, bottom);
			}
		}
	}
}
示例#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) ;

}