官术网_书友最值得收藏!

  • Mastering OpenCV 3(Second Edition)
  • Daniel Lélis Baggio Shervin Emami David Millán Escrivá Khvedchenia Ievgen Jason Saragih Roy Shilkrot
  • 263字
  • 2021-07-02 23:29:09

Generating an evil mode using edge filters

Cartoons and comics always have both good and bad characters. With the right combination of edge filters, a scary image can be generated from the most innocent looking people! The trick is to use a small-edge filter that will find many edges all over the image, then merge the edges using a small Median filter.

We will perform this on a grayscale image with some noise reduction, so the preceding code for converting the original image to grayscale and applying a 7x7 Median filter should still be used (the first image in the following figure shows the output of the grayscale Median blur). Instead of following it with a Laplacian filter and Binary threshold, we can get a more scary look if we apply a 3x3 Scharr gradient filter along x and y (second image in the figure), then a binary threshold with a very low cutoff (third image in the figure),and a 3x3 Median blur, producing the final evil mask (fourth image in the figure):

    Mat gray;
    cvtColor(srcColor, gray, CV_BGR2GRAY);
    const int MEDIAN_BLUR_FILTER_SIZE = 7;
    medianBlur(gray, gray, MEDIAN_BLUR_FILTER_SIZE);
    Mat edges, edges2;
    Scharr(srcGray, edges, CV_8U, 1, 0);
    Scharr(srcGray, edges2, CV_8U, 1, 0, -1);
    edges += edges2;
    // Combine the x & y edges together.
    const int EVIL_EDGE_THRESHOLD = 12
    threshold(edges, mask, EVIL_EDGE_THRESHOLD, 255,
    THRESH_BINARY_INV);
    medianBlur(mask, mask, 3)

Now that we have an evil mask, we can overlay this mask onto the cartoonified painting image like we did with the regular sketch edge mask. The final result is shown on the right side of the following figure:

主站蜘蛛池模板: 龙海市| 南京市| 牟定县| 定远县| 东方市| 碌曲县| 阿鲁科尔沁旗| 观塘区| 抚宁县| 陵川县| 桃园市| 湾仔区| 辉县市| 永福县| 绵竹市| 汨罗市| 确山县| 丰城市| 扬中市| 军事| 阿合奇县| 西宁市| 宁德市| 嘉荫县| 沁源县| 鱼台县| 湖口县| 柞水县| 佛冈县| 石楼县| 门源| 英德市| 浑源县| 松江区| 上饶市| 玉田县| 聊城市| 淅川县| 福海县| 长乐市| 陆川县|