1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
26
// * The name of the copyright holders may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
42
#include "precomp.hpp"
43
#include "opencv2/photo.hpp"
52
void cv::edgePreservingFilter(InputArray _src, OutputArray _dst, int flags, float sigma_s, float sigma_r)
54
Mat I = _src.getMat();
55
_dst.create(I.size(), CV_8UC3);
56
Mat dst = _dst.getMat();
58
int h = I.size().height;
59
int w = I.size().width;
61
Mat res = Mat(h,w,CV_32FC3);
62
dst.convertTo(res,CV_32FC3,1.0/255.0);
66
Mat img = Mat(I.size(),CV_32FC3);
67
I.convertTo(img,CV_32FC3,1.0/255.0);
69
obj.filter(img, res, sigma_s, sigma_r, flags);
71
convertScaleAbs(res, dst, 255,0);
74
void cv::detailEnhance(InputArray _src, OutputArray _dst, float sigma_s, float sigma_r)
76
Mat I = _src.getMat();
77
_dst.create(I.size(), CV_8UC3);
78
Mat dst = _dst.getMat();
80
int h = I.size().height;
81
int w = I.size().width;
84
Mat img = Mat(I.size(),CV_32FC3);
85
I.convertTo(img,CV_32FC3,1.0/255.0);
87
Mat res = Mat(h,w,CV_32FC1);
88
dst.convertTo(res,CV_32FC3,1.0/255.0);
90
Mat result = Mat(img.size(),CV_32FC3);
91
Mat lab = Mat(img.size(),CV_32FC3);
92
vector <Mat> lab_channel;
94
cvtColor(img,lab,COLOR_BGR2Lab);
95
split(lab,lab_channel);
97
Mat L = Mat(img.size(),CV_32FC1);
99
lab_channel[0].convertTo(L,CV_32FC1,1.0/255.0);
103
obj.filter(L, res, sigma_s, sigma_r, 1);
105
Mat detail = Mat(h,w,CV_32FC1);
108
multiply(detail,factor,detail);
111
L.convertTo(lab_channel[0],CV_32FC1,255);
113
merge(lab_channel,lab);
115
cvtColor(lab,result,COLOR_Lab2BGR);
116
result.convertTo(dst,CV_8UC3,255);
119
void cv::pencilSketch(InputArray _src, OutputArray _dst1, OutputArray _dst2, float sigma_s, float sigma_r, float shade_factor)
121
Mat I = _src.getMat();
122
_dst1.create(I.size(), CV_8UC1);
123
Mat dst1 = _dst1.getMat();
125
_dst2.create(I.size(), CV_8UC3);
126
Mat dst2 = _dst2.getMat();
128
Mat img = Mat(I.size(),CV_32FC3);
129
I.convertTo(img,CV_32FC3,1.0/255.0);
133
Mat sketch = Mat(I.size(),CV_32FC1);
134
Mat color_sketch = Mat(I.size(),CV_32FC3);
136
obj.pencil_sketch(img, sketch, color_sketch, sigma_s, sigma_r, shade_factor);
138
sketch.convertTo(dst1,CV_8UC1,255);
139
color_sketch.convertTo(dst2,CV_8UC3,255);
143
void cv::stylization(InputArray _src, OutputArray _dst, float sigma_s, float sigma_r)
145
Mat I = _src.getMat();
146
_dst.create(I.size(), CV_8UC3);
147
Mat dst = _dst.getMat();
149
Mat img = Mat(I.size(),CV_32FC3);
150
I.convertTo(img,CV_32FC3,1.0/255.0);
152
int h = img.size().height;
153
int w = img.size().width;
155
Mat res = Mat(h,w,CV_32FC3);
156
Mat magnitude = Mat(h,w,CV_32FC1);
159
obj.filter(img, res, sigma_s, sigma_r, NORMCONV_FILTER);
161
obj.find_magnitude(res,magnitude);
163
Mat stylized = Mat(h,w,CV_32FC3);
167
multiply(temp[0],magnitude,temp[0]);
168
multiply(temp[1],magnitude,temp[1]);
169
multiply(temp[2],magnitude,temp[2]);
170
merge(temp,stylized);
172
stylized.convertTo(dst,CV_8UC3,255);