1 /*
2 Copyright (c) 2019 Ferhat Kurtulmuş
3 Boost Software License - Version 1.0 - August 17th, 2003
4 Permission is hereby granted, free of charge, to any person or organization
5 obtaining a copy of the software and accompanying documentation covered by
6 this license (the "Software") to use, reproduce, display, distribute,
7 execute, and transmit the Software, and to prepare derivative works of the
8 Software, and to permit third-parties to whom the Software is furnished to
9 do so, all subject to the following:
10 The copyright notices in the Software and this entire statement, including
11 the above license grant, this restriction and the following disclaimer,
12 must be included in all copies of the Software, in whole or in part, and
13 all derivative works of the Software, unless such copies or derivative
14 works are solely in the form of machine-executable object code generated by
15 a source language processor.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
19 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
20 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24 
25 module opencvd.photo;
26 
27 import opencvd.cvcore;
28 
29 private extern (C){
30     void DetailEnhance(Mat src, Mat dst, float sigma_s, float sigma_r);
31     void EdgePreservingFilter(Mat src, Mat dst, int flags, float sigma_s, float sigma_r);
32     void PencilSketch(Mat src, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor);
33     void Stylization (Mat src, Mat dst, float sigma_s, float sigma_r);
34     
35     void ColorChange(Mat src, Mat mask, Mat dst, float red_mul, float green_mul, float blue_mul);
36     void IlluminationChange(Mat src, Mat mask, Mat dst, float alpha, float beta);
37     void SeamlessClone(Mat src, Mat dst, Mat mask, Point p, Mat blend, int flags);
38     void TextureFlattening(Mat src, Mat mask, Mat dst, float low_threshold, float high_threshold, int kernel_size);
39     
40     void FastNlMeansDenoising2 (Mat src, Mat dst, float h, int templateWindowSize, int searchWindowSize);
41 }
42 
43 enum: int { 
44     RECURS_FILTER = 1, 
45     NORMCONV_FILTER = 2 
46 }
47 
48 void detailEnhance(Mat src, Mat dst, float sigma_s=10, float sigma_r=0.15f){
49     DetailEnhance(src, dst, sigma_s, sigma_r);
50 }
51 
52 void edgePreservingFilter(Mat src, Mat dst, int flags=1, float sigma_s=60, float sigma_r=0.4f){
53     EdgePreservingFilter(src, dst, flags, sigma_s, sigma_r);
54 }
55 
56 void pencilSketch(Mat src, Mat dst1, Mat dst2, float sigma_s=60, float sigma_r=0.07f, float shade_factor=0.02f){
57     PencilSketch(src, dst1, dst2, sigma_s, sigma_r, shade_factor);
58 }
59 void stylization (Mat src, Mat dst, float sigma_s=60, float sigma_r=0.45f){
60     Stylization (src, dst, sigma_s, sigma_r);
61 }
62 
63 enum: int { 
64     NORMAL_CLONE = 1, 
65     MIXED_CLONE = 2, 
66     MONOCHROME_TRANSFER = 3 
67 }
68 
69 void colorChange(Mat src, Mat mask, Mat dst, float red_mul=1.0f, float green_mul=1.0f, float blue_mul=1.0f){
70     ColorChange(src, mask, dst, red_mul, green_mul, blue_mul);
71 }
72 
73 void illuminationChange(Mat src, Mat mask, Mat dst, float alpha=0.2f, float beta=0.4f){
74     IlluminationChange(src, mask, dst, alpha, beta);
75 }
76 
77 void seamlessClone(Mat src, Mat dst, Mat mask, Point p, Mat blend, int flags){
78     SeamlessClone(src, dst, mask, p, blend, flags);
79 }
80 
81 void textureFlattening(Mat src, Mat mask, Mat dst, float low_threshold=30, float high_threshold=45, int kernel_size=3){
82     TextureFlattening(src, mask, dst, low_threshold, high_threshold, kernel_size);
83 }
84 
85 void fastNlMeansDenoising (Mat src, Mat dst, float h =3, int templateWindowSize = 7,  int searchWindowSize = 21){
86     FastNlMeansDenoising2 (src, dst, h, templateWindowSize, searchWindowSize);
87 }