5 * Siddharth Kherada <siddharthkherada27[at]gmail[dot]com>
7 * This tutorial demonstrates how to use OpenCV seamless cloning
12 * 3- Monochrome Transfer
14 * 5- Illumination change
15 * 6- Texture Flattening
17 * The program takes as input a source and a destination image (for 1-3 methods)
18 * and ouputs the cloned image.
20 * Download test images from opencv_extra folder @github.
24 #include "opencv2/photo.hpp"
25 #include "opencv2/imgproc.hpp"
26 #include "opencv2/imgcodecs.hpp"
27 #include "opencv2/highgui.hpp"
28 #include "opencv2/core.hpp"
38 cout << "Cloning Module" << endl;
39 cout << "---------------" << endl;
40 cout << "Options: " << endl;
42 cout << "1) Normal Cloning " << endl;
43 cout << "2) Mixed Cloning " << endl;
44 cout << "3) Monochrome Transfer " << endl;
45 cout << "4) Local Color Change " << endl;
46 cout << "5) Local Illumination Change " << endl;
47 cout << "6) Texture Flattening " << endl;
49 cout << "Press number 1-6 to choose from above techniques: ";
56 string folder = "cloning/Normal_Cloning/";
57 string original_path1 = folder + "source1.png";
58 string original_path2 = folder + "destination1.png";
59 string original_path3 = folder + "mask.png";
61 Mat source = imread(original_path1, IMREAD_COLOR);
62 Mat destination = imread(original_path2, IMREAD_COLOR);
63 Mat mask = imread(original_path3, IMREAD_COLOR);
67 cout << "Could not load source image " << original_path1 << endl;
70 if(destination.empty())
72 cout << "Could not load destination image " << original_path2 << endl;
77 cout << "Could not load mask image " << original_path3 << endl;
86 seamlessClone(source, destination, mask, p, result, 1);
88 imshow("Output",result);
89 imwrite(folder + "cloned.png", result);
93 string folder = "cloning/Mixed_Cloning/";
94 string original_path1 = folder + "source1.png";
95 string original_path2 = folder + "destination1.png";
96 string original_path3 = folder + "mask.png";
98 Mat source = imread(original_path1, IMREAD_COLOR);
99 Mat destination = imread(original_path2, IMREAD_COLOR);
100 Mat mask = imread(original_path3, IMREAD_COLOR);
104 cout << "Could not load source image " << original_path1 << endl;
107 if(destination.empty())
109 cout << "Could not load destination image " << original_path2 << endl;
114 cout << "Could not load mask image " << original_path3 << endl;
120 p.x = destination.size().width/2;
121 p.y = destination.size().height/2;
123 seamlessClone(source, destination, mask, p, result, 2);
125 imshow("Output",result);
126 imwrite(folder + "cloned.png", result);
130 string folder = "cloning/Monochrome_Transfer/";
131 string original_path1 = folder + "source1.png";
132 string original_path2 = folder + "destination1.png";
133 string original_path3 = folder + "mask.png";
135 Mat source = imread(original_path1, IMREAD_COLOR);
136 Mat destination = imread(original_path2, IMREAD_COLOR);
137 Mat mask = imread(original_path3, IMREAD_COLOR);
141 cout << "Could not load source image " << original_path1 << endl;
144 if(destination.empty())
146 cout << "Could not load destination image " << original_path2 << endl;
151 cout << "Could not load mask image " << original_path3 << endl;
157 p.x = destination.size().width/2;
158 p.y = destination.size().height/2;
160 seamlessClone(source, destination, mask, p, result, 3);
162 imshow("Output",result);
163 imwrite(folder + "cloned.png", result);
167 string folder = "cloning/Color_Change/";
168 string original_path1 = folder + "source1.png";
169 string original_path2 = folder + "mask.png";
171 Mat source = imread(original_path1, IMREAD_COLOR);
172 Mat mask = imread(original_path2, IMREAD_COLOR);
176 cout << "Could not load source image " << original_path1 << endl;
181 cout << "Could not load mask image " << original_path2 << endl;
187 colorChange(source, mask, result, 1.5, .5, .5);
189 imshow("Output",result);
190 imwrite(folder + "cloned.png", result);
194 string folder = "cloning/Illumination_Change/";
195 string original_path1 = folder + "source1.png";
196 string original_path2 = folder + "mask.png";
198 Mat source = imread(original_path1, IMREAD_COLOR);
199 Mat mask = imread(original_path2, IMREAD_COLOR);
203 cout << "Could not load source image " << original_path1 << endl;
208 cout << "Could not load mask image " << original_path2 << endl;
214 illuminationChange(source, mask, result, 0.2f, 0.4f);
216 imshow("Output",result);
217 imwrite(folder + "cloned.png", result);
221 string folder = "cloning/Texture_Flattening/";
222 string original_path1 = folder + "source1.png";
223 string original_path2 = folder + "mask.png";
225 Mat source = imread(original_path1, IMREAD_COLOR);
226 Mat mask = imread(original_path2, IMREAD_COLOR);
230 cout << "Could not load source image " << original_path1 << endl;
235 cout << "Could not load mask image " << original_path2 << endl;
241 textureFlattening(source, mask, result, 30, 45, 3);
243 imshow("Output",result);
244 imwrite(folder + "cloned.png", result);