/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2013, OpenCV Foundation, all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of the copyright holders may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "precomp.hpp"42#include "opencv2/photo.hpp"43#include <iostream>44#include <stdlib.h>4546#include "npr.hpp"4748using namespace std;49using namespace cv;5051void cv::edgePreservingFilter(InputArray _src, OutputArray dst, int flags, float sigma_s, float sigma_r)52{53CV_INSTRUMENT_REGION();5455Mat I = _src.getMat();5657Domain_Filter obj;5859Mat img;60I.convertTo(img,CV_32FC3,1.0/255.0);6162Mat res;63obj.filter(img, res, sigma_s, sigma_r, flags);6465convertScaleAbs(res, dst, 255,0);66}6768void cv::detailEnhance(InputArray _src, OutputArray dst, float sigma_s, float sigma_r)69{70CV_INSTRUMENT_REGION();7172Mat I = _src.getMat();7374float factor = 3.0f;7576Mat img;77I.convertTo(img,CV_32FC3,1.0/255.0);7879Mat lab;80vector <Mat> lab_channel;81cvtColor(img,lab,COLOR_BGR2Lab);82split(lab,lab_channel);8384Mat L;85lab_channel[0].convertTo(L,CV_32FC1,1.0/255.0);8687Domain_Filter obj;8889Mat res;90obj.filter(L, res, sigma_s, sigma_r, 1);9192Mat detail = L - res;93multiply(detail,factor,detail);94L = res + detail;9596L.convertTo(lab_channel[0],CV_32FC1,255);9798merge(lab_channel,lab);99100cvtColor(lab,res,COLOR_Lab2BGR);101res.convertTo(dst,CV_8UC3,255);102}103104void cv::pencilSketch(InputArray _src, OutputArray _dst1, OutputArray _dst2, float sigma_s, float sigma_r, float shade_factor)105{106CV_INSTRUMENT_REGION();107108Mat I = _src.getMat();109_dst1.create(I.size(), CV_8UC1);110Mat dst1 = _dst1.getMat();111112_dst2.create(I.size(), CV_8UC3);113Mat dst2 = _dst2.getMat();114115Mat img = Mat(I.size(),CV_32FC3);116I.convertTo(img,CV_32FC3,1.0/255.0);117118Domain_Filter obj;119120Mat sketch = Mat(I.size(),CV_32FC1);121Mat color_sketch = Mat(I.size(),CV_32FC3);122123obj.pencil_sketch(img, sketch, color_sketch, sigma_s, sigma_r, shade_factor);124125sketch.convertTo(dst1,CV_8UC1,255);126color_sketch.convertTo(dst2,CV_8UC3,255);127128}129130void cv::stylization(InputArray _src, OutputArray _dst, float sigma_s, float sigma_r)131{132CV_INSTRUMENT_REGION();133134Mat I = _src.getMat();135_dst.create(I.size(), CV_8UC3);136Mat dst = _dst.getMat();137138Mat img;139I.convertTo(img,CV_32FC3,1.0/255.0);140141int h = img.size().height;142int w = img.size().width;143144Mat res;145Mat magnitude = Mat(h,w,CV_32FC1);146147Domain_Filter obj;148obj.filter(img, res, sigma_s, sigma_r, NORMCONV_FILTER);149150obj.find_magnitude(res,magnitude);151152Mat stylized;153154vector <Mat> temp;155split(res,temp);156multiply(temp[0],magnitude,temp[0]);157multiply(temp[1],magnitude,temp[1]);158multiply(temp[2],magnitude,temp[2]);159merge(temp,stylized);160161stylized.convertTo(dst,CV_8UC3,255);162}163164165