ApplyColorMap for pseudocoloring

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// ApplyColorMap for pseudocoloring
// using OpenCV 3.0 Version
 
#include <cv.hpp>
 
using namespace cv;
using namespace std;
 
string colormap_name(int id)
{
    switch (id){
    case COLORMAP_AUTUMN:
        return "COLORMAP_AUTUMN";
    case COLORMAP_BONE:
        return "COLORMAP_BONE";
    case COLORMAP_JET:
        return "COLORMAP_JET";
    case COLORMAP_WINTER:
        return "COLORMAP_WINTER";
    case COLORMAP_RAINBOW:
        return "COLORMAP_RAINBOW";
    case COLORMAP_OCEAN:
        return "COLORMAP_OCEAN";
    case COLORMAP_SUMMER:
        return "COLORMAP_SUMMER";
    case COLORMAP_SPRING:
        return "COLORMAP_SPRING";
    case COLORMAP_COOL:
        return "COLORMAP_COOL";
    case COLORMAP_HSV:
        return "COLORMAP_HSV";
    case COLORMAP_PINK:
        return "COLORMAP_PINK";
    case COLORMAP_HOT:
        return "COLORMAP_HOT";
    }
 
    return "NONE";
}
 
int main()
{
    Mat im = imread("img/pluto.jpg", IMREAD_GRAYSCALE);
 
    Mat im_out = Mat::zeros(600800, CV_8UC3);
 
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 3; j++){
            int k = i + j * 4;
            Mat im_color = im_out(Rect(i * 200, j * 200200200));
            applyColorMap(im, im_color, k);
            putText(im_color, colormap_name(k), Point(30180), 
                CV_FONT_HERSHEY_DUPLEX, 0.5, Scalar::all(255), 1, CV_AA);
        }
    }
 
    imshow("Pseudo Colored", im_out);
    imwrite("img/Pseudo COlored.jpg", im_out);
    waitKey(0);
    
    return 0;
}
cs





Non-Photorealistic Rendering

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Non-Photorealistic Rendering using OpenCV
// using OpenCV 3.0 Version
 
#include <cv.hpp>
 
using namespace std;
using namespace cv;
 
int main()
{
    Mat im = imread("img/cow.jpg");
    Mat imout, imout_gray;
 
    // Edge preserving filter with two different flags;
    edgePreservingFilter(im, imout, RECURS_FILTER);
    imwrite("img/edge-preserving-recursive-filter.jpg", imout);
 
    edgePreservingFilter(im, imout, NORMCONV_FILTER);
    imwrite("img/edge-preserving-normlized-convolution-filter.jpg", imout);
 
    // Detail enhance filter
    detailEnhance(im, imout);
    imwrite("img/detail-enhance.jpg", imout);
 
    // Pencil sketch filter
    pencilSketch(im, imout_gray, imout);
    imwrite("img/pencil-sketch.jpg", imout_gray);
 
    // stylization filter
    stylization(im, imout);
    imwrite("img/stylization.jpg", imout);
}
cs


Domain Transform for Edge-aware Filtering












OpenCV SeamlessCloning

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Examples : seamlessClone.cpp
// Using OpenCV 3.0 version
 
#include <cv.hpp>
 
using namespace std;
using namespace cv;
 
int main()
{
    Mat src = imread("img/iloveyouticket.jpg");
    Mat dst = imread("img/wood-texture.jpg");
 
    // create an all white mask
    Mat src_mask = 255 * Mat::ones(src.rows, src.cols, src.depth());
 
    // The location of the center of the src in the dst
    Point center(dst.cols / 2, dst.rows / 2 );
 
    // Seamlessly Clone src into dst and put the result in output
    Mat normal_clone, mixed_clone;
 
    seamlessClone(src, dst, src_mask, center, normal_clone, NORMAL_CLONE);
    seamlessClone(src, dst, src_mask, center, mixed_clone, MIXED_CLONE);
 
    namedWindow("normal_clone");
    imshow("normal_clone", normal_clone);
    namedWindow("mixed_clone");
    imshow("mixed_clone", mixed_clone);
 
    waitKey(0);
 
    return 0;
}
cs





입력 이미지 예1)


  <그림 1 source image>


                  <그림 2 dst image>


                <그림 3 normal clone


               <그림 4 mixed clone




입력 이미지 예2)

         <그림 5 source image


                          <그림 6 dst image


normal clone

                         <그림 7 normal clone


mixed clone

                          <그림 8 mixed clone