whitespaces removed and other minor changes to fix build error
Update 1 update 2 Update 3 Update 4 Update 5 update 6 Update 7 Update 8 Update 9 Update 10 Update 11 Update 12 Update 13 Update 14 Update 15 Update 16 Update 17 Update 18 Update 19 Update 20 Update 21 Update 22 Removed Headers Update 23 Update 24 Update 25 Update 26 Update 27 Update 28
This commit is contained in:
parent
05c7c9325a
commit
f85a615f3f
@ -9,16 +9,16 @@ Image editing tasks concern either global changes (color/intensity corrections,
|
||||
Here we are interested in achieving local changes, ones that are restricted to a region manually selected (ROI), in a seamless and effortless manner.
|
||||
The extent of the changes ranges from slight distortions to complete replacement by novel content.
|
||||
|
||||
.. ocv:function:: void seamlessClone( InputArray src, InputArray dst, InputArray mask, Point p, OutputArray result, int flags)
|
||||
.. ocv:function:: void seamlessClone( InputArray src, InputArray dst, InputArray mask, Point p, OutputArray blend, int flags)
|
||||
|
||||
:param src: Input 8-bit 3-channel image.
|
||||
|
||||
:param dst: Input 8-bit 3-channel image.
|
||||
|
||||
|
||||
:param mask: Input 8-bit 1 or 3-channel image.
|
||||
|
||||
:param Point: Point in dst image where object is placed.
|
||||
|
||||
|
||||
:param p: Point in dst image where object is placed.
|
||||
|
||||
:param result: Output image with the same size and type as ``dst``.
|
||||
|
||||
:param flags: Cloning method that could be one of the following:
|
||||
@ -29,7 +29,7 @@ The extent of the changes ranges from slight distortions to complete replacement
|
||||
masking might be time consuming and often leaves an undesirable halo. Seamless
|
||||
cloning, even averaged with the original image, is not effective. Mixed seamless
|
||||
cloning based on a loose selection proves effective.
|
||||
|
||||
|
||||
* **FEATURE_EXCHANGE** Feature exchange allows the user to replace easily certain
|
||||
features of one object by alternative features.
|
||||
|
||||
@ -44,17 +44,17 @@ Given an original color image, two differently colored versions of this image ca
|
||||
:param src: Input 8-bit 3-channel image.
|
||||
|
||||
:param mask: Input 8-bit 1 or 3-channel image.
|
||||
|
||||
|
||||
:param dst: Output image with the same size and type as ``src`` .
|
||||
|
||||
:param red_mul: R-channel multiply factor.
|
||||
|
||||
|
||||
:param green_mul: G-channel multiply factor.
|
||||
|
||||
|
||||
:param blue_mul: B-channel multiply factor.
|
||||
|
||||
Multiplication factor is between .5 to 2.5.
|
||||
|
||||
|
||||
|
||||
illuminationChange
|
||||
------------------
|
||||
@ -66,11 +66,11 @@ solver, modifies locally the apparent illumination of an image.
|
||||
:param src: Input 8-bit 3-channel image.
|
||||
|
||||
:param mask: Input 8-bit 1 or 3-channel image.
|
||||
|
||||
|
||||
:param dst: Output image with the same size and type as ``src``.
|
||||
|
||||
:param alpha: Value ranges between 0-2.
|
||||
|
||||
|
||||
:param beta: Value ranges between 0-2.
|
||||
|
||||
This is useful to highlight under-exposed foreground objects or to reduce specular reflections.
|
||||
@ -85,13 +85,13 @@ region, giving its contents a flat aspect. Here Canny Edge Detector is used.
|
||||
:param src: Input 8-bit 3-channel image.
|
||||
|
||||
:param mask: Input 8-bit 1 or 3-channel image.
|
||||
|
||||
|
||||
:param dst: Output image with the same size and type as ``src``.
|
||||
|
||||
:param low_threshold: Range from 0 to 100.
|
||||
|
||||
|
||||
:param high_threshold: Value > 100.
|
||||
|
||||
|
||||
:param kernel_size: The size of the Sobel kernel to be used.
|
||||
|
||||
**NOTE:**
|
||||
|
@ -17,4 +17,3 @@ Transforms a color image to a grayscale image. It is a basic tool in digital pri
|
||||
:param color_boost: Output 8-bit 3-channel image.
|
||||
|
||||
This function is to be applied on color images.
|
||||
|
||||
|
@ -8,20 +8,20 @@ edgePreservingFilter
|
||||
|
||||
Filtering is the fundamental operation in image and video processing. Edge-preserving smoothing filters are used in many different applications.
|
||||
|
||||
.. ocv:function:: void edgePreservingFilter(InputArray src, OutputArray dst, int flags = 1, float sigma_s = 60, float sigma_r = 0.4);
|
||||
.. ocv:function:: void edgePreservingFilter(InputArray src, OutputArray dst, int flags = 1, float sigma_s = 60, float sigma_r = 0.4)
|
||||
|
||||
:param src: Input 8-bit 3-channel image.
|
||||
|
||||
:param dst: Output 8-bit 3-channel image.
|
||||
|
||||
|
||||
:param flags: Edge preserving filters:
|
||||
|
||||
* **RECURS_FILTER**
|
||||
* **RECURS_FILTER**
|
||||
|
||||
* **NORMCONV_FILTER**
|
||||
* **NORMCONV_FILTER**
|
||||
|
||||
:param sigma_s: Range between 0 to 200.
|
||||
|
||||
|
||||
:param sigma_r: Range between 0 to 1.
|
||||
|
||||
|
||||
@ -29,33 +29,33 @@ detailEnhance
|
||||
-------------
|
||||
This filter enhances the details of a particular image.
|
||||
|
||||
.. ocv:function:: void detailEnhance(InputArray src, OutputArray dst, float sigma_s = 10, float sigma_r = 0.15);
|
||||
.. ocv:function:: void detailEnhance(InputArray src, OutputArray dst, float sigma_s = 10, float sigma_r = 0.15)
|
||||
|
||||
:param src: Input 8-bit 3-channel image.
|
||||
|
||||
:param dst: Output image with the same size and type as ``src``.
|
||||
|
||||
:param sigma_s: Range between 0 to 200.
|
||||
|
||||
:param sigma_s: Range between 0 to 200.
|
||||
|
||||
:param sigma_r: Range between 0 to 1.
|
||||
|
||||
|
||||
|
||||
pencilSketch
|
||||
------------
|
||||
Pencil-like non-photorealistic line drawing
|
||||
|
||||
.. ocv:function:: void pencilSketch(InputArray src, OutputArray dst1, OutputArray dst2, float sigma_s = 60, float sigma_r = 0.07, float shade_factor = 0.02);
|
||||
.. ocv:function:: void pencilSketch(InputArray src, OutputArray dst1, OutputArray dst2, float sigma_s = 60, float sigma_r = 0.07, float shade_factor = 0.02)
|
||||
|
||||
:param src: Input 8-bit 3-channel image.
|
||||
|
||||
:param dst1: Output 8-bit 1-channel image.
|
||||
|
||||
|
||||
:param dst2: Output image with the same size and type as ``src``.
|
||||
|
||||
:param sigma_s: Range between 0 to 200.
|
||||
|
||||
|
||||
:param sigma_r: Range between 0 to 1.
|
||||
|
||||
|
||||
:param shade_factor: Range between 0 to 0.1.
|
||||
|
||||
|
||||
@ -63,14 +63,14 @@ stylization
|
||||
-----------
|
||||
Stylization aims to produce digital imagery with a wide variety of effects not focused on photorealism. Edge-aware filters are ideal for stylization, as they can abstract regions of low contrast while preserving, or enhancing, high-contrast features.
|
||||
|
||||
.. ocv:function:: void stylization(InputArray src, OutputArray dst, float sigma_s = 60, float sigma_r = 0.45);
|
||||
.. ocv:function:: void stylization(InputArray src, OutputArray dst, float sigma_s = 60, float sigma_r = 0.45)
|
||||
|
||||
:param src: Input 8-bit 3-channel image.
|
||||
|
||||
:param dst: Output image with the same size and type as ``src``.
|
||||
|
||||
:param sigma_s: Range between 0 to 200.
|
||||
|
||||
|
||||
:param sigma_r: Range between 0 to 1.
|
||||
|
||||
|
||||
@ -78,13 +78,12 @@ edgeEnhance
|
||||
-----------
|
||||
Able to suppress low-amplitude details and enhance edges.
|
||||
|
||||
.. ocv:function:: void edgeEnhance(InputArray src, OutputArray dst, float sigma_s = 60, float sigma_r = 0.45);
|
||||
.. ocv:function:: void edgeEnhance(InputArray src, OutputArray dst, float sigma_s = 60, float sigma_r = 0.45)
|
||||
|
||||
:param src: Input 8-bit 3-channel image.
|
||||
|
||||
:param dst: Output 8-bit 1-channel image.
|
||||
|
||||
:param sigma_s: Range between 0 to 200.
|
||||
|
||||
:param sigma_r: Range between 0 to 1.
|
||||
|
||||
:param sigma_r: Range between 0 to 1.
|
||||
|
@ -9,4 +9,7 @@ photo. Computational Photography
|
||||
|
||||
inpainting
|
||||
denoising
|
||||
hdr_imaging
|
||||
hdr_imaging
|
||||
decolor
|
||||
cloning
|
||||
npr
|
||||
|
@ -47,51 +47,51 @@
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
/*! \namespace cv
|
||||
Namespace where all the C++ OpenCV functionality resides
|
||||
Namespace where all the C++ OpenCV functionality resides
|
||||
*/
|
||||
namespace cv
|
||||
{
|
||||
|
||||
//! the inpainting algorithm
|
||||
enum
|
||||
{
|
||||
INPAINT_NS = 0, // Navier-Stokes algorithm
|
||||
INPAINT_TELEA = 1 // A. Telea algorithm
|
||||
};
|
||||
//! the inpainting algorithm
|
||||
enum
|
||||
{
|
||||
INPAINT_NS = 0, // Navier-Stokes algorithm
|
||||
INPAINT_TELEA = 1 // A. Telea algorithm
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
NORMAL_CLONE = 1,
|
||||
MIXED_CLONE = 2,
|
||||
MONOCHROME_TRANSFER = 3
|
||||
};
|
||||
enum
|
||||
{
|
||||
NORMAL_CLONE = 1,
|
||||
MIXED_CLONE = 2,
|
||||
MONOCHROME_TRANSFER = 3
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
RECURS_FILTER = 1,
|
||||
NORMCONV_FILTER = 2
|
||||
};
|
||||
enum
|
||||
{
|
||||
RECURS_FILTER = 1,
|
||||
NORMCONV_FILTER = 2
|
||||
};
|
||||
|
||||
//! restores the damaged image areas using one of the available intpainting algorithms
|
||||
CV_EXPORTS_W void inpaint( InputArray src, InputArray inpaintMask,
|
||||
OutputArray dst, double inpaintRadius, int flags );
|
||||
//! restores the damaged image areas using one of the available intpainting algorithms
|
||||
CV_EXPORTS_W void inpaint( InputArray src, InputArray inpaintMask,
|
||||
OutputArray dst, double inpaintRadius, int flags );
|
||||
|
||||
|
||||
CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, float h = 3,
|
||||
int templateWindowSize = 7, int searchWindowSize = 21);
|
||||
CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, float h = 3,
|
||||
int templateWindowSize = 7, int searchWindowSize = 21);
|
||||
|
||||
CV_EXPORTS_W void fastNlMeansDenoisingColored( InputArray src, OutputArray dst,
|
||||
float h = 3, float hColor = 3,
|
||||
int templateWindowSize = 7, int searchWindowSize = 21);
|
||||
CV_EXPORTS_W void fastNlMeansDenoisingColored( InputArray src, OutputArray dst,
|
||||
float h = 3, float hColor = 3,
|
||||
int templateWindowSize = 7, int searchWindowSize = 21);
|
||||
|
||||
CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst,
|
||||
int imgToDenoiseIndex, int temporalWindowSize,
|
||||
float h = 3, int templateWindowSize = 7, int searchWindowSize = 21);
|
||||
CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst,
|
||||
int imgToDenoiseIndex, int temporalWindowSize,
|
||||
float h = 3, int templateWindowSize = 7, int searchWindowSize = 21);
|
||||
|
||||
CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, OutputArray dst,
|
||||
int imgToDenoiseIndex, int temporalWindowSize,
|
||||
float h = 3, float hColor = 3,
|
||||
int templateWindowSize = 7, int searchWindowSize = 21);
|
||||
CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, OutputArray dst,
|
||||
int imgToDenoiseIndex, int temporalWindowSize,
|
||||
float h = 3, float hColor = 3,
|
||||
int templateWindowSize = 7, int searchWindowSize = 21);
|
||||
|
||||
enum { LDR_SIZE = 256 };
|
||||
|
||||
@ -301,35 +301,35 @@ public:
|
||||
|
||||
CV_EXPORTS_W Ptr<MergeRobertson> createMergeRobertson();
|
||||
|
||||
CV_EXPORTS_W void decolor( InputArray src, OutputArray grayscale, OutputArray color_boost);
|
||||
CV_EXPORTS_W void decolor( InputArray src, OutputArray grayscale, OutputArray color_boost);
|
||||
|
||||
CV_EXPORTS_W void seamlessClone( InputArray src, InputArray dst, InputArray mask, Point p,
|
||||
OutputArray _blend, int flags);
|
||||
CV_EXPORTS_W void seamlessClone( InputArray src, InputArray dst, InputArray mask, Point p,
|
||||
OutputArray blend, int flags);
|
||||
|
||||
CV_EXPORTS_W void colorChange(InputArray src, InputArray mask, OutputArray dst, float red_mul = 1.0,
|
||||
float green_mul = 1.0, float blue_mul = 1.0);
|
||||
CV_EXPORTS_W void colorChange(InputArray src, InputArray mask, OutputArray dst, float red_mul = 1.0,
|
||||
float green_mul = 1.0, float blue_mul = 1.0);
|
||||
|
||||
CV_EXPORTS_W void illuminationChange(InputArray src, InputArray mask, OutputArray dst,
|
||||
float alpha = 0.2, float beta = 0.4);
|
||||
CV_EXPORTS_W void illuminationChange(InputArray src, InputArray mask, OutputArray dst,
|
||||
float alpha = 0.2, float beta = 0.4);
|
||||
|
||||
CV_EXPORTS_W void textureFlattening(InputArray src, InputArray mask, OutputArray dst,
|
||||
double low_threshold, double high_threshold,
|
||||
int kernel_size);
|
||||
CV_EXPORTS_W void textureFlattening(InputArray src, InputArray mask, OutputArray dst,
|
||||
double low_threshold, double high_threshold,
|
||||
int kernel_size);
|
||||
|
||||
CV_EXPORTS_W void edgePreservingFilter(InputArray src, OutputArray dst, int flags = 1,
|
||||
float sigma_s = 60, float sigma_r = 0.4);
|
||||
CV_EXPORTS_W void edgePreservingFilter(InputArray src, OutputArray dst, int flags = 1,
|
||||
float sigma_s = 60, float sigma_r = 0.4);
|
||||
|
||||
CV_EXPORTS_W void detailEnhance(InputArray src, OutputArray dst, float sigma_s = 10,
|
||||
float sigma_r = 0.15);
|
||||
CV_EXPORTS_W void detailEnhance(InputArray src, OutputArray dst, float sigma_s = 10,
|
||||
float sigma_r = 0.15);
|
||||
|
||||
CV_EXPORTS_W void pencilSketch(InputArray src, OutputArray dst, OutputArray dst1,
|
||||
float sigma_s = 60, float sigma_r = 0.07, float shade_factor = 0.02);
|
||||
CV_EXPORTS_W void pencilSketch(InputArray src, OutputArray dst1, OutputArray dst2,
|
||||
float sigma_s = 60, float sigma_r = 0.07, float shade_factor = 0.02);
|
||||
|
||||
CV_EXPORTS_W void stylization(InputArray src, OutputArray dst, float sigma_s = 60,
|
||||
float sigma_r = 0.45);
|
||||
CV_EXPORTS_W void stylization(InputArray src, OutputArray dst, float sigma_s = 60,
|
||||
float sigma_r = 0.45);
|
||||
|
||||
CV_EXPORTS_W void edgeEnhance(InputArray src, OutputArray dst, float sigma_s = 60,
|
||||
float sigma_r = 0.45);
|
||||
CV_EXPORTS_W void edgeEnhance(InputArray src, OutputArray dst, float sigma_s = 60,
|
||||
float sigma_r = 0.45);
|
||||
|
||||
} // cv
|
||||
|
||||
|
@ -42,8 +42,6 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include "math.h"
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
@ -53,21 +51,21 @@
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
double norm(double);
|
||||
double norm_m(double);
|
||||
|
||||
double norm(double E)
|
||||
double norm_m(double E)
|
||||
{
|
||||
return (sqrt(pow(E,2)));
|
||||
return sqrt(pow(E,2));
|
||||
}
|
||||
|
||||
void cv::decolor(InputArray _src, OutputArray _dst, OutputArray _boost)
|
||||
void cv::decolor(InputArray _src, OutputArray _dst, OutputArray _color_boost)
|
||||
{
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC1);
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
_boost.create(I.size(), CV_8UC3);
|
||||
Mat color_boost = _boost.getMat();
|
||||
_color_boost.create(I.size(), CV_8UC3);
|
||||
Mat color_boost = _color_boost.getMat();
|
||||
|
||||
if(!I.data )
|
||||
{
|
||||
@ -82,7 +80,7 @@ void cv::decolor(InputArray _src, OutputArray _dst, OutputArray _boost)
|
||||
|
||||
int maxIter = 15;
|
||||
int iterCount = 0;
|
||||
float tol = .0001;
|
||||
double tol = .0001;
|
||||
double E = 0;
|
||||
double pre_E = std::numeric_limits<double>::infinity();
|
||||
|
||||
@ -113,7 +111,7 @@ void cv::decolor(InputArray _src, OutputArray _dst, OutputArray _boost)
|
||||
|
||||
//////////////////////////////// main loop starting ////////////////////////////////////////
|
||||
|
||||
while(norm(E-pre_E) > tol)
|
||||
while(norm_m(E-pre_E) > tol)
|
||||
{
|
||||
iterCount +=1;
|
||||
pre_E = E;
|
||||
@ -223,7 +221,7 @@ void cv::decolor(InputArray _src, OutputArray _dst, OutputArray _boost)
|
||||
for(int i =0;i<h1;i++)
|
||||
for(int j=0;j<w1;j++)
|
||||
{
|
||||
l.at<uchar>(i,j) = 255.0*Gray.at<float>(i,j);
|
||||
l.at<uchar>(i,j) = dst.at<uchar>(i,j);
|
||||
}
|
||||
|
||||
for(int i =0;i<h1;i++)
|
||||
|
@ -41,7 +41,6 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "math.h"
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
@ -124,12 +123,12 @@ void Decolor::init()
|
||||
vector<double> Decolor::product(vector < vector<int> > &comb, vector <double> &initRGB)
|
||||
{
|
||||
vector <double> res;
|
||||
float dp;
|
||||
double dp;
|
||||
for (unsigned int i=0;i<comb.size();i++)
|
||||
{
|
||||
dp = 0.0f;
|
||||
dp = 0.0;
|
||||
for(int j=0;j<3;j++)
|
||||
dp += comb[i][j] * initRGB[j];
|
||||
dp = dp + (comb[i][j] * initRGB[j]);
|
||||
res.push_back(dp);
|
||||
}
|
||||
return res;
|
||||
@ -413,14 +412,14 @@ void Decolor::wei_update_matrix(vector < vector <double> > &poly, vector <double
|
||||
|
||||
for(unsigned int i =0;i<poly.size();i++)
|
||||
for(unsigned int j=0;j<poly[0].size();j++)
|
||||
P.at<float>(i,j) = poly[i][j];
|
||||
P.at<float>(i,j) = (float) poly[i][j];
|
||||
|
||||
Mat P_trans = P.t();
|
||||
Mat P_trans = P.t();
|
||||
Mat B = Mat(poly.size(),poly[0].size(), CV_32FC1);
|
||||
for(unsigned int i =0;i < poly.size();i++)
|
||||
{
|
||||
for(unsigned int j=0;j<Cg.size();j++)
|
||||
B.at<float>(i,j) = poly[i][j]*Cg[j];
|
||||
B.at<float>(i,j) = (float) (poly[i][j] * Cg[j]);
|
||||
}
|
||||
|
||||
A = P*P_trans;
|
||||
@ -486,14 +485,14 @@ void Decolor::grayImContruct(vector <double> &wei, Mat img, Mat &Gray)
|
||||
for(int i = 0;i<h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
Gray.at<float>(i,j)=Gray.at<float>(i,j) +
|
||||
wei[kk]*pow(red.at<float>(i,j),r)*pow(green.at<float>(i,j),g)*
|
||||
(float) wei[kk]*pow(red.at<float>(i,j),r)*pow(green.at<float>(i,j),g)*
|
||||
pow(blue.at<float>(i,j),b);
|
||||
|
||||
kk=kk+1;
|
||||
}
|
||||
|
||||
double minval = INT_MAX;
|
||||
double maxval = INT_MIN;
|
||||
float minval = INT_MAX;
|
||||
float maxval = INT_MIN;
|
||||
|
||||
for(int i=0;i<h;i++)
|
||||
for(int j =0;j<w;j++)
|
||||
|
@ -41,9 +41,6 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -54,215 +51,215 @@ using namespace cv;
|
||||
|
||||
void cv::edgePreservingFilter(InputArray _src, OutputArray _dst, int flags, float sigma_s, float sigma_r)
|
||||
{
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC3);
|
||||
Mat dst = _dst.getMat();
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC3);
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
int h = I.size().height;
|
||||
int w = I.size().width;
|
||||
int h = I.size().height;
|
||||
int w = I.size().width;
|
||||
|
||||
Mat res = Mat(h,w,CV_32FC3);
|
||||
dst.convertTo(res,CV_32FC3,1.0/255.0);
|
||||
Mat res = Mat(h,w,CV_32FC3);
|
||||
dst.convertTo(res,CV_32FC3,1.0/255.0);
|
||||
|
||||
Domain_Filter obj;
|
||||
Domain_Filter obj;
|
||||
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
|
||||
obj.filter(img, res, sigma_s, sigma_r, flags);
|
||||
obj.filter(img, res, sigma_s, sigma_r, flags);
|
||||
|
||||
convertScaleAbs(res, dst, 255,0);
|
||||
convertScaleAbs(res, dst, 255,0);
|
||||
}
|
||||
|
||||
void cv::detailEnhance(InputArray _src, OutputArray _dst, float sigma_s, float sigma_r)
|
||||
{
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC3);
|
||||
Mat dst = _dst.getMat();
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC3);
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
int h = I.size().height;
|
||||
int w = I.size().width;
|
||||
int channel = I.channels();
|
||||
float factor = 3.0;
|
||||
int h = I.size().height;
|
||||
int w = I.size().width;
|
||||
int channel = I.channels();
|
||||
float factor = 3.0;
|
||||
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
|
||||
Mat res = Mat(h,w,CV_32FC3);
|
||||
dst.convertTo(res,CV_32FC3,1.0/255.0);
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
|
||||
Mat result = Mat(img.size(),CV_32FC3);
|
||||
Mat lab = Mat(img.size(),CV_32FC3);
|
||||
Mat l_channel = Mat(img.size(),CV_32FC1);
|
||||
Mat a_channel = Mat(img.size(),CV_32FC1);
|
||||
Mat b_channel = Mat(img.size(),CV_32FC1);
|
||||
Mat res = Mat(h,w,CV_32FC3);
|
||||
dst.convertTo(res,CV_32FC3,1.0/255.0);
|
||||
|
||||
cvtColor(img,lab,COLOR_BGR2Lab);
|
||||
Mat result = Mat(img.size(),CV_32FC3);
|
||||
Mat lab = Mat(img.size(),CV_32FC3);
|
||||
Mat l_channel = Mat(img.size(),CV_32FC1);
|
||||
Mat a_channel = Mat(img.size(),CV_32FC1);
|
||||
Mat b_channel = Mat(img.size(),CV_32FC1);
|
||||
|
||||
for(int i = 0; i < h; i++)
|
||||
for(int j = 0; j < w; j++)
|
||||
{
|
||||
l_channel.at<float>(i,j) = lab.at<float>(i,j*channel+0);
|
||||
a_channel.at<float>(i,j) = lab.at<float>(i,j*channel+1);
|
||||
b_channel.at<float>(i,j) = lab.at<float>(i,j*channel+2);
|
||||
}
|
||||
cvtColor(img,lab,COLOR_BGR2Lab);
|
||||
|
||||
Mat L = Mat(img.size(),CV_32FC1);
|
||||
for(int i = 0; i < h; i++)
|
||||
for(int j = 0; j < w; j++)
|
||||
{
|
||||
l_channel.at<float>(i,j) = lab.at<float>(i,j*channel+0);
|
||||
a_channel.at<float>(i,j) = lab.at<float>(i,j*channel+1);
|
||||
b_channel.at<float>(i,j) = lab.at<float>(i,j*channel+2);
|
||||
}
|
||||
|
||||
l_channel.convertTo(L,CV_32FC1,1.0/255.0);
|
||||
Mat L = Mat(img.size(),CV_32FC1);
|
||||
|
||||
Domain_Filter obj;
|
||||
l_channel.convertTo(L,CV_32FC1,1.0/255.0);
|
||||
|
||||
obj.filter(L, res, sigma_s, sigma_r, 1);
|
||||
Domain_Filter obj;
|
||||
|
||||
Mat detail = Mat(h,w,CV_32FC1);
|
||||
obj.filter(L, res, sigma_s, sigma_r, 1);
|
||||
|
||||
for(int i = 0; i < h; i++)
|
||||
for(int j = 0; j < w; j++)
|
||||
detail.at<float>(i,j) = L.at<float>(i,j) - res.at<float>(i,j);
|
||||
Mat detail = Mat(h,w,CV_32FC1);
|
||||
|
||||
for(int i = 0; i < h; i++)
|
||||
for(int j = 0; j < w; j++)
|
||||
L.at<float>(i,j) = res.at<float>(i,j) + factor*detail.at<float>(i,j);
|
||||
for(int i = 0; i < h; i++)
|
||||
for(int j = 0; j < w; j++)
|
||||
detail.at<float>(i,j) = L.at<float>(i,j) - res.at<float>(i,j);
|
||||
|
||||
L.convertTo(l_channel,CV_32FC1,255);
|
||||
for(int i = 0; i < h; i++)
|
||||
for(int j = 0; j < w; j++)
|
||||
L.at<float>(i,j) = res.at<float>(i,j) + factor*detail.at<float>(i,j);
|
||||
|
||||
for(int i = 0; i < h; i++)
|
||||
for(int j = 0; j < w; j++)
|
||||
{
|
||||
lab.at<float>(i,j*channel+0) = l_channel.at<float>(i,j);
|
||||
lab.at<float>(i,j*channel+1) = a_channel.at<float>(i,j);
|
||||
lab.at<float>(i,j*channel+2) = b_channel.at<float>(i,j);
|
||||
}
|
||||
L.convertTo(l_channel,CV_32FC1,255);
|
||||
|
||||
cvtColor(lab,result,COLOR_Lab2BGR);
|
||||
result.convertTo(dst,CV_8UC3,255);
|
||||
for(int i = 0; i < h; i++)
|
||||
for(int j = 0; j < w; j++)
|
||||
{
|
||||
lab.at<float>(i,j*channel+0) = l_channel.at<float>(i,j);
|
||||
lab.at<float>(i,j*channel+1) = a_channel.at<float>(i,j);
|
||||
lab.at<float>(i,j*channel+2) = b_channel.at<float>(i,j);
|
||||
}
|
||||
|
||||
cvtColor(lab,result,COLOR_Lab2BGR);
|
||||
result.convertTo(dst,CV_8UC3,255);
|
||||
}
|
||||
|
||||
void cv::pencilSketch(InputArray _src, OutputArray _dst, OutputArray _dst1, float sigma_s, float sigma_r, float shade_factor)
|
||||
void cv::pencilSketch(InputArray _src, OutputArray _dst1, OutputArray _dst2, float sigma_s, float sigma_r, float shade_factor)
|
||||
{
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC1);
|
||||
Mat dst = _dst.getMat();
|
||||
Mat I = _src.getMat();
|
||||
_dst1.create(I.size(), CV_8UC1);
|
||||
Mat dst1 = _dst1.getMat();
|
||||
|
||||
_dst1.create(I.size(), CV_8UC3);
|
||||
Mat dst1 = _dst1.getMat();
|
||||
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
_dst2.create(I.size(), CV_8UC3);
|
||||
Mat dst2 = _dst2.getMat();
|
||||
|
||||
Domain_Filter obj;
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
|
||||
Mat sketch = Mat(I.size(),CV_32FC1);
|
||||
Mat color_sketch = Mat(I.size(),CV_32FC3);
|
||||
Domain_Filter obj;
|
||||
|
||||
obj.pencil_sketch(img, sketch, color_sketch, sigma_s, sigma_r, shade_factor);
|
||||
Mat sketch = Mat(I.size(),CV_32FC1);
|
||||
Mat color_sketch = Mat(I.size(),CV_32FC3);
|
||||
|
||||
sketch.convertTo(dst,CV_8UC1,255);
|
||||
color_sketch.convertTo(dst1,CV_8UC3,255);
|
||||
obj.pencil_sketch(img, sketch, color_sketch, sigma_s, sigma_r, shade_factor);
|
||||
|
||||
sketch.convertTo(dst1,CV_8UC1,255);
|
||||
color_sketch.convertTo(dst2,CV_8UC3,255);
|
||||
|
||||
}
|
||||
|
||||
void cv::stylization(InputArray _src, OutputArray _dst, float sigma_s, float sigma_r)
|
||||
{
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC3);
|
||||
Mat dst = _dst.getMat();
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC3);
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
|
||||
int h = img.size().height;
|
||||
int w = img.size().width;
|
||||
int channel = img.channels();
|
||||
int h = img.size().height;
|
||||
int w = img.size().width;
|
||||
int channel = img.channels();
|
||||
|
||||
Mat res = Mat(h,w,CV_32FC3);
|
||||
Mat res = Mat(h,w,CV_32FC3);
|
||||
|
||||
Domain_Filter obj;
|
||||
obj.filter(img, res, sigma_s, sigma_r, NORMCONV_FILTER);
|
||||
Domain_Filter obj;
|
||||
obj.filter(img, res, sigma_s, sigma_r, NORMCONV_FILTER);
|
||||
|
||||
vector <Mat> planes;
|
||||
split(res, planes);
|
||||
vector <Mat> planes;
|
||||
split(res, planes);
|
||||
|
||||
Mat magXR = Mat(h, w, CV_32FC1);
|
||||
Mat magYR = Mat(h, w, CV_32FC1);
|
||||
Mat magXR = Mat(h, w, CV_32FC1);
|
||||
Mat magYR = Mat(h, w, CV_32FC1);
|
||||
|
||||
Mat magXG = Mat(h, w, CV_32FC1);
|
||||
Mat magYG = Mat(h, w, CV_32FC1);
|
||||
Mat magXG = Mat(h, w, CV_32FC1);
|
||||
Mat magYG = Mat(h, w, CV_32FC1);
|
||||
|
||||
Mat magXB = Mat(h, w, CV_32FC1);
|
||||
Mat magYB = Mat(h, w, CV_32FC1);
|
||||
Mat magXB = Mat(h, w, CV_32FC1);
|
||||
Mat magYB = Mat(h, w, CV_32FC1);
|
||||
|
||||
Sobel(planes[0], magXR, CV_32FC1, 1, 0, 3);
|
||||
Sobel(planes[0], magYR, CV_32FC1, 0, 1, 3);
|
||||
Sobel(planes[0], magXR, CV_32FC1, 1, 0, 3);
|
||||
Sobel(planes[0], magYR, CV_32FC1, 0, 1, 3);
|
||||
|
||||
Sobel(planes[1], magXG, CV_32FC1, 1, 0, 3);
|
||||
Sobel(planes[1], magYG, CV_32FC1, 0, 1, 3);
|
||||
Sobel(planes[1], magXG, CV_32FC1, 1, 0, 3);
|
||||
Sobel(planes[1], magYG, CV_32FC1, 0, 1, 3);
|
||||
|
||||
Sobel(planes[2], magXB, CV_32FC1, 1, 0, 3);
|
||||
Sobel(planes[2], magYB, CV_32FC1, 0, 1, 3);
|
||||
Sobel(planes[2], magXB, CV_32FC1, 1, 0, 3);
|
||||
Sobel(planes[2], magYB, CV_32FC1, 0, 1, 3);
|
||||
|
||||
Mat magx = Mat(h,w,CV_32FC1);
|
||||
Mat magy = Mat(h,w,CV_32FC1);
|
||||
Mat magx = Mat(h,w,CV_32FC1);
|
||||
Mat magy = Mat(h,w,CV_32FC1);
|
||||
|
||||
Mat mag1 = Mat(h,w,CV_32FC1);
|
||||
Mat mag2 = Mat(h,w,CV_32FC1);
|
||||
Mat mag3 = Mat(h,w,CV_32FC1);
|
||||
Mat mag1 = Mat(h,w,CV_32FC1);
|
||||
Mat mag2 = Mat(h,w,CV_32FC1);
|
||||
Mat mag3 = Mat(h,w,CV_32FC1);
|
||||
|
||||
magnitude(magXR,magYR,mag1);
|
||||
magnitude(magXG,magYG,mag2);
|
||||
magnitude(magXB,magYB,mag3);
|
||||
magnitude(magXR,magYR,mag1);
|
||||
magnitude(magXG,magYG,mag2);
|
||||
magnitude(magXB,magYB,mag3);
|
||||
|
||||
Mat magnitude = Mat(h,w,CV_32FC1);
|
||||
Mat magnitude = Mat(h,w,CV_32FC1);
|
||||
|
||||
for(int i =0;i < h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
{
|
||||
magnitude.at<float>(i,j) = mag1.at<float>(i,j) + mag2.at<float>(i,j) + mag3.at<float>(i,j);
|
||||
}
|
||||
for(int i =0;i < h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
{
|
||||
magnitude.at<float>(i,j) = mag1.at<float>(i,j) + mag2.at<float>(i,j) + mag3.at<float>(i,j);
|
||||
}
|
||||
|
||||
for(int i =0;i < h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
{
|
||||
magnitude.at<float>(i,j) = 1.0 - magnitude.at<float>(i,j);
|
||||
}
|
||||
for(int i =0;i < h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
{
|
||||
magnitude.at<float>(i,j) = 1.0f - magnitude.at<float>(i,j);
|
||||
}
|
||||
|
||||
Mat stylized = Mat(h,w,CV_32FC3);
|
||||
Mat stylized = Mat(h,w,CV_32FC3);
|
||||
|
||||
for(int i =0;i < h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
for(int c=0;c<channel;c++)
|
||||
{
|
||||
stylized.at<float>(i,j*channel + c) = res.at<float>(i,j*channel + c) * magnitude.at<float>(i,j);
|
||||
}
|
||||
for(int i =0;i < h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
for(int c=0;c<channel;c++)
|
||||
{
|
||||
stylized.at<float>(i,j*channel + c) = res.at<float>(i,j*channel + c) * magnitude.at<float>(i,j);
|
||||
}
|
||||
|
||||
stylized.convertTo(dst,CV_8UC3,255);
|
||||
stylized.convertTo(dst,CV_8UC3,255);
|
||||
}
|
||||
|
||||
void cv::edgeEnhance(InputArray _src, OutputArray _dst, float sigma_s, float sigma_r)
|
||||
{
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC1);
|
||||
Mat dst = _dst.getMat();
|
||||
Mat I = _src.getMat();
|
||||
_dst.create(I.size(), CV_8UC1);
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
Mat img = Mat(I.size(),CV_32FC3);
|
||||
I.convertTo(img,CV_32FC3,1.0/255.0);
|
||||
|
||||
Mat orig = img.clone();
|
||||
Mat orig = img.clone();
|
||||
|
||||
int h = img.size().height;
|
||||
int w = img.size().width;
|
||||
int h = img.size().height;
|
||||
int w = img.size().width;
|
||||
|
||||
Mat res = Mat(h,w,CV_32FC3);
|
||||
Mat magnitude = Mat(h,w,CV_32FC1);
|
||||
Mat res = Mat(h,w,CV_32FC3);
|
||||
Mat magnitude = Mat(h,w,CV_32FC1);
|
||||
|
||||
Mat mag8 = Mat(h,w,CV_32FC1);
|
||||
Mat mag8 = Mat(h,w,CV_32FC1);
|
||||
|
||||
Domain_Filter obj;
|
||||
Domain_Filter obj;
|
||||
|
||||
obj.filter(img, res, sigma_s, sigma_r, NORMCONV_FILTER);
|
||||
obj.filter(img, res, sigma_s, sigma_r, NORMCONV_FILTER);
|
||||
|
||||
obj.find_magnitude(res,magnitude);
|
||||
obj.find_magnitude(res,magnitude);
|
||||
|
||||
magnitude.convertTo(dst,CV_8UC1,255);
|
||||
magnitude.convertTo(dst,CV_8UC1,255);
|
||||
}
|
||||
|
@ -41,12 +41,12 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <limits>
|
||||
#include "math.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
@ -79,7 +79,7 @@ void Domain_Filter::diffx(const Mat &img, Mat &temp)
|
||||
{
|
||||
for(int c =0; c < channel; c++)
|
||||
{
|
||||
temp.at<float>(i,j*channel+c) =
|
||||
temp.at<float>(i,j*channel+c) =
|
||||
img.at<float>(i,(j+1)*channel+c) - img.at<float>(i,j*channel+c);
|
||||
}
|
||||
}
|
||||
@ -94,7 +94,7 @@ void Domain_Filter::diffy(const Mat &img, Mat &temp)
|
||||
{
|
||||
for(int c =0; c < channel; c++)
|
||||
{
|
||||
temp.at<float>(i,j*channel+c) =
|
||||
temp.at<float>(i,j*channel+c) =
|
||||
img.at<float>((i+1),j*channel+c) - img.at<float>(i,j*channel+c);
|
||||
}
|
||||
}
|
||||
@ -179,7 +179,7 @@ void Domain_Filter::find_magnitude(Mat &img, Mat &mag)
|
||||
for(int i =0;i < h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
{
|
||||
mag.at<float>(i,j) = 1.0 - mag.at<float>(i,j);
|
||||
mag.at<float>(i,j) = 1.0f - mag.at<float>(i,j);
|
||||
}
|
||||
|
||||
}
|
||||
@ -193,7 +193,7 @@ void Domain_Filter::compute_Rfilter(Mat &output, Mat &hz, float sigma_h)
|
||||
int w = output.cols;
|
||||
int channel = output.channels();
|
||||
|
||||
a = exp(-sqrt(2) / sigma_h);
|
||||
a = (float) exp((-1.0 * sqrt(2.0)) / sigma_h);
|
||||
|
||||
Mat temp = Mat(h,w,CV_32FC3);
|
||||
|
||||
@ -202,21 +202,19 @@ void Domain_Filter::compute_Rfilter(Mat &output, Mat &hz, float sigma_h)
|
||||
for(int c=0;c<channel;c++)
|
||||
temp.at<float>(i,j*channel+c) = output.at<float>(i,j*channel+c);
|
||||
|
||||
|
||||
Mat V = Mat(h,w,CV_32FC1);
|
||||
|
||||
for(int i=0;i<h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
V.at<float>(i,j) = pow(a,hz.at<float>(i,j));
|
||||
|
||||
|
||||
for(int i=0; i<h; i++)
|
||||
{
|
||||
for(int j =1; j < w; j++)
|
||||
{
|
||||
for(int c = 0; c<channel; c++)
|
||||
{
|
||||
temp.at<float>(i,j*channel+c) = temp.at<float>(i,j*channel+c) +
|
||||
temp.at<float>(i,j*channel+c) = temp.at<float>(i,j*channel+c) +
|
||||
(temp.at<float>(i,(j-1)*channel+c) - temp.at<float>(i,j*channel+c)) * V.at<float>(i,j);
|
||||
}
|
||||
}
|
||||
@ -267,7 +265,7 @@ void Domain_Filter::compute_boxfilter(Mat &output, Mat &hz, Mat &psketch, float
|
||||
{
|
||||
for(int j=0;j<w;j++)
|
||||
domain_row.at<float>(0,j) = hz.at<float>(i,j);
|
||||
domain_row.at<float>(0,w) = myinf;
|
||||
domain_row.at<float>(0,w) = (float) myinf;
|
||||
|
||||
Mat lower_pos_row = Mat::zeros(1,w,CV_32FC1);
|
||||
Mat upper_pos_row = Mat::zeros(1,w,CV_32FC1);
|
||||
@ -285,7 +283,7 @@ void Domain_Filter::compute_boxfilter(Mat &output, Mat &hz, Mat &psketch, float
|
||||
{
|
||||
if(domain_row.at<float>(0,j) > lower_pos_row.at<float>(0,0))
|
||||
{
|
||||
temp_lower_idx.at<float>(0,0) = j;
|
||||
temp_lower_idx.at<float>(0,0) = (float) j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -293,7 +291,7 @@ void Domain_Filter::compute_boxfilter(Mat &output, Mat &hz, Mat &psketch, float
|
||||
{
|
||||
if(domain_row.at<float>(0,j) > upper_pos_row.at<float>(0,0))
|
||||
{
|
||||
temp_upper_idx.at<float>(0,0) = j;
|
||||
temp_upper_idx.at<float>(0,0) = (float) j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -302,7 +300,7 @@ void Domain_Filter::compute_boxfilter(Mat &output, Mat &hz, Mat &psketch, float
|
||||
for(int j=1;j<w;j++)
|
||||
{
|
||||
int count=0;
|
||||
for(int k=temp_lower_idx.at<float>(0,j-1);k<w+1;k++)
|
||||
for(int k=(int) temp_lower_idx.at<float>(0,j-1);k<w+1;k++)
|
||||
{
|
||||
if(domain_row.at<float>(0,k) > lower_pos_row.at<float>(0,j))
|
||||
{
|
||||
@ -315,7 +313,7 @@ void Domain_Filter::compute_boxfilter(Mat &output, Mat &hz, Mat &psketch, float
|
||||
temp_lower_idx.at<float>(0,j) = temp_lower_idx.at<float>(0,j-1) + temp;
|
||||
|
||||
count = 0;
|
||||
for(int k=temp_upper_idx.at<float>(0,j-1);k<w+1;k++)
|
||||
for(int k=(int) temp_upper_idx.at<float>(0,j-1);k<w+1;k++)
|
||||
{
|
||||
|
||||
|
||||
@ -374,7 +372,7 @@ void Domain_Filter::compute_NCfilter(Mat &output, Mat &hz, Mat &psketch, float r
|
||||
|
||||
for(int i=0;i<h;i++)
|
||||
for(int j=0;j<w;j++)
|
||||
indices.at<float>(i,j) = i+1;
|
||||
indices.at<float>(i,j) = (float) i+1;
|
||||
|
||||
Mat a = Mat::zeros(h,w,CV_32FC1);
|
||||
Mat b = Mat::zeros(h,w,CV_32FC1);
|
||||
@ -402,8 +400,8 @@ void Domain_Filter::compute_NCfilter(Mat &output, Mat &hz, Mat &psketch, float r
|
||||
for(int j=0;j<w;j++)
|
||||
{
|
||||
|
||||
r = b.at<float>(i,j)/(h*(w+1));
|
||||
rem = b.at<float>(i,j) - r*h*(w+1);
|
||||
r = (int) b.at<float>(i,j)/(h*(w+1));
|
||||
rem = (int) b.at<float>(i,j) - r*h*(w+1);
|
||||
q = rem/h;
|
||||
p = rem - q*h;
|
||||
if(q==0)
|
||||
@ -419,8 +417,8 @@ void Domain_Filter::compute_NCfilter(Mat &output, Mat &hz, Mat &psketch, float r
|
||||
}
|
||||
|
||||
|
||||
r1 = a.at<float>(i,j)/(h*(w+1));
|
||||
rem1 = a.at<float>(i,j) - r1*h*(w+1);
|
||||
r1 = (int) a.at<float>(i,j)/(h*(w+1));
|
||||
rem1 = (int) a.at<float>(i,j) - r1*h*(w+1);
|
||||
q1 = rem1/h;
|
||||
p1 = rem1 - q1*h;
|
||||
if(p1==0)
|
||||
@ -465,7 +463,7 @@ void Domain_Filter::init(const Mat &img, int flags, float sigma_s, float sigma_r
|
||||
for(int j = 0,k=1; j < w-1; j++,k++)
|
||||
for(int c = 0; c < channel; c++)
|
||||
{
|
||||
distx.at<float>(i,k) =
|
||||
distx.at<float>(i,k) =
|
||||
distx.at<float>(i,k) + abs(derivx.at<float>(i,j*channel+c));
|
||||
}
|
||||
|
||||
@ -473,7 +471,7 @@ void Domain_Filter::init(const Mat &img, int flags, float sigma_s, float sigma_r
|
||||
for(int j = 0; j < w; j++)
|
||||
for(int c = 0; c < channel; c++)
|
||||
{
|
||||
disty.at<float>(k,j) =
|
||||
disty.at<float>(k,j) =
|
||||
disty.at<float>(k,j) + abs(derivy.at<float>(i,j*channel+c));
|
||||
}
|
||||
|
||||
@ -539,11 +537,11 @@ void Domain_Filter::filter(const Mat &img, Mat &res, float sigma_s = 60, float s
|
||||
|
||||
if(flags == 1)
|
||||
{
|
||||
Mat vert_t = vert.t();
|
||||
Mat vert_t = vert.t();
|
||||
|
||||
for(int i=0;i<no_of_iter;i++)
|
||||
{
|
||||
sigma_h = sigma_s * sqrt(3) * pow(2.0,(no_of_iter - (i+1))) / sqrt(pow(4.0,no_of_iter) -1);
|
||||
sigma_h = (float) (sigma_s * sqrt(3.0) * pow(2.0,(no_of_iter - (i+1))) / sqrt(pow(4.0,no_of_iter) -1));
|
||||
|
||||
compute_Rfilter(O, horiz, sigma_h);
|
||||
|
||||
@ -566,9 +564,9 @@ void Domain_Filter::filter(const Mat &img, Mat &res, float sigma_s = 60, float s
|
||||
|
||||
for(int i=0;i<no_of_iter;i++)
|
||||
{
|
||||
sigma_h = sigma_s * sqrt(3) * pow(2.0,(no_of_iter - (i+1))) / sqrt(pow(4.0,no_of_iter) -1);
|
||||
sigma_h = (float) (sigma_s * sqrt(3.0) * pow(2.0,(no_of_iter - (i+1))) / sqrt(pow(4.0,no_of_iter) -1));
|
||||
|
||||
radius = sqrt(3) * sigma_h;
|
||||
radius = (float) sqrt(3.0) * sigma_h;
|
||||
|
||||
compute_NCfilter(O, ct_H, temp,radius);
|
||||
|
||||
@ -616,9 +614,9 @@ void Domain_Filter::pencil_sketch(const Mat &img, Mat &sketch, Mat &color_res, f
|
||||
|
||||
for(int i=0;i<no_of_iter;i++)
|
||||
{
|
||||
sigma_h = sigma_s * sqrt(3) * pow(2.0,(no_of_iter - (i+1))) / sqrt(pow(4.0,no_of_iter) -1);
|
||||
sigma_h = (float) (sigma_s * sqrt(3.0) * pow(2.0,(no_of_iter - (i+1))) / sqrt(pow(4.0,no_of_iter) -1));
|
||||
|
||||
radius = sqrt(3) * sigma_h;
|
||||
radius = (float) sqrt(3.0) * sigma_h;
|
||||
|
||||
compute_boxfilter(O, ct_H, penx, radius);
|
||||
|
||||
|
@ -41,9 +41,6 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -243,4 +240,3 @@ void cv::textureFlattening(InputArray _src, InputArray _mask, OutputArray _dst,
|
||||
Cloning obj;
|
||||
obj.texture_flatten(src,cs_mask,gray,low_threshold,high_threshold,kernel_size,blend);
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,6 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <complex>
|
||||
@ -162,7 +159,7 @@ void Cloning::dst(double *gtest, double *gfinal,int h,int w)
|
||||
for(int j=0,r=1;j<h;j++,r++)
|
||||
{
|
||||
idx = j*w+i;
|
||||
temp.at<float>(r,0) = gtest[idx];
|
||||
temp.at<float>(r,0) = (float) gtest[idx];
|
||||
}
|
||||
|
||||
temp.at<float>(h+1,0)=0.0;
|
||||
@ -170,7 +167,7 @@ void Cloning::dst(double *gtest, double *gfinal,int h,int w)
|
||||
for(int j=h-1, r=h+2;j>=0;j--,r++)
|
||||
{
|
||||
idx = j*w+i;
|
||||
temp.at<float>(r,0) = -1*gtest[idx];
|
||||
temp.at<float>(r,0) = (float) (-1.0 * gtest[idx]);
|
||||
}
|
||||
|
||||
merge(planes, 2, complex1);
|
||||
@ -179,7 +176,7 @@ void Cloning::dst(double *gtest, double *gfinal,int h,int w)
|
||||
|
||||
Mat planes1[] = {Mat::zeros(complex1.size(), CV_32F), Mat::zeros(complex1.size(), CV_32F)};
|
||||
|
||||
split(complex1, planes1);
|
||||
split(complex1, planes1);
|
||||
|
||||
std::complex<double> two_i = std::sqrt(std::complex<double>(-1));
|
||||
|
||||
@ -187,7 +184,7 @@ void Cloning::dst(double *gtest, double *gfinal,int h,int w)
|
||||
|
||||
for(int c=1,z=0;c<h+1;c++,z++)
|
||||
{
|
||||
res.at<float>(z,0) = planes1[1].at<float>(c,0)/fac;
|
||||
res.at<float>(z,0) = (float) (planes1[1].at<float>(c,0)/fac);
|
||||
}
|
||||
|
||||
for(int q=0,z=0;q<h;q++,z++)
|
||||
@ -222,14 +219,14 @@ void Cloning::transpose(double *mat, double *mat_t,int h,int w)
|
||||
{
|
||||
|
||||
Mat tmp = Mat(h,w,CV_32FC1);
|
||||
unsigned long int idx;
|
||||
unsigned long int idx;
|
||||
for(int i = 0 ; i < h;i++)
|
||||
{
|
||||
for(int j = 0 ; j < w; j++)
|
||||
{
|
||||
|
||||
idx = i*(w) + j;
|
||||
tmp.at<float>(i,j) = mat[idx];
|
||||
tmp.at<float>(i,j) = (float) mat[idx];
|
||||
}
|
||||
}
|
||||
Mat tmp_t = tmp.t();
|
||||
@ -264,7 +261,7 @@ void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result)
|
||||
for(int i =1;i<h-1;i++)
|
||||
for(int j=1;j<w-1;j++)
|
||||
{
|
||||
bound.at<uchar>(i,j) = 0.0;
|
||||
bound.at<uchar>(i,j) = 0;
|
||||
}
|
||||
|
||||
double *f_bp = new double[h*w];
|
||||
@ -284,7 +281,7 @@ void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result)
|
||||
for(int j=0;j<w;j++)
|
||||
{
|
||||
idx = i*w+j;
|
||||
diff.at<float>(i,j) = (lap.at<float>(i,j) - f_bp[idx]);
|
||||
diff.at<float>(i,j) = (float) (lap.at<float>(i,j) - f_bp[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,7 +333,6 @@ void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result)
|
||||
gfinal_t[idx] = gfinal_t[idx]/denom[idx];
|
||||
}
|
||||
|
||||
|
||||
idst(gfinal_t,f3,h-2,w-2);
|
||||
|
||||
transpose(f3,f3_t,h-2,w-2);
|
||||
@ -350,7 +346,7 @@ void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result)
|
||||
for(int j = 0 ; j < w; j++)
|
||||
{
|
||||
idx = i*w + j;
|
||||
img_d[idx] = (double)img.at<uchar>(i,j);
|
||||
img_d[idx] = (double)img.at<uchar>(i,j);
|
||||
}
|
||||
}
|
||||
for(int i = 1 ; i < h-1;i++)
|
||||
@ -358,7 +354,7 @@ void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result)
|
||||
for(int j = 1 ; j < w-1; j++)
|
||||
{
|
||||
idx = i*w + j;
|
||||
img_d[idx] = 0.0;
|
||||
img_d[idx] = 0.0;
|
||||
}
|
||||
}
|
||||
for(int i = 1,id1=0 ; i < h-1;i++,id1++)
|
||||
@ -367,7 +363,7 @@ void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result)
|
||||
{
|
||||
idx = i*w + j;
|
||||
idx1= id1*(w-2) + id2;
|
||||
img_d[idx] = f3_t[idx1];
|
||||
img_d[idx] = f3_t[idx1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,9 +375,9 @@ void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result)
|
||||
if(img_d[idx] < 0.0)
|
||||
result.at<uchar>(i,j) = 0;
|
||||
else if(img_d[idx] > 255.0)
|
||||
result.at<uchar>(i,j) = 255.0;
|
||||
result.at<uchar>(i,j) = 255;
|
||||
else
|
||||
result.at<uchar>(i,j) = img_d[idx];
|
||||
result.at<uchar>(i,j) = (uchar) img_d[idx];
|
||||
}
|
||||
}
|
||||
|
||||
@ -410,8 +406,8 @@ void Cloning::init(Mat &I, Mat &wmask)
|
||||
for(int i=0;i<I.size().height;i++)
|
||||
for(int j=0;j<I.size().width;j++)
|
||||
{
|
||||
r_channel.at<uchar>(i,j) = I.at<uchar>(i,j*3+0);
|
||||
g_channel.at<uchar>(i,j) = I.at<uchar>(i,j*3+1);
|
||||
r_channel.at<uchar>(i,j) = I.at<uchar>(i,j*3+0);
|
||||
g_channel.at<uchar>(i,j) = I.at<uchar>(i,j*3+1);
|
||||
b_channel.at<uchar>(i,j) = I.at<uchar>(i,j*3+2);
|
||||
}
|
||||
|
||||
@ -453,8 +449,8 @@ void Cloning::calc(Mat &I, Mat &gx, Mat &gy, Mat &sx, Mat &sy)
|
||||
for(int i=0;i<I.size().height;i++)
|
||||
for(int j=0;j<I.size().width;j++)
|
||||
{
|
||||
rx_channel.at<float>(i,j) = gxx.at<float>(i,j*3+0);
|
||||
gx_channel.at<float>(i,j) = gxx.at<float>(i,j*3+1);
|
||||
rx_channel.at<float>(i,j) = gxx.at<float>(i,j*3+0);
|
||||
gx_channel.at<float>(i,j) = gxx.at<float>(i,j*3+1);
|
||||
bx_channel.at<float>(i,j) = gxx.at<float>(i,j*3+2);
|
||||
}
|
||||
|
||||
@ -465,8 +461,8 @@ void Cloning::calc(Mat &I, Mat &gx, Mat &gy, Mat &sx, Mat &sy)
|
||||
for(int i=0;i<I.size().height;i++)
|
||||
for(int j=0;j<I.size().width;j++)
|
||||
{
|
||||
ry_channel.at<float>(i,j) = gyy.at<float>(i,j*3+0);
|
||||
gy_channel.at<float>(i,j) = gyy.at<float>(i,j*3+1);
|
||||
ry_channel.at<float>(i,j) = gyy.at<float>(i,j*3+0);
|
||||
gy_channel.at<float>(i,j) = gyy.at<float>(i,j*3+1);
|
||||
by_channel.at<float>(i,j) = gyy.at<float>(i,j*3+2);
|
||||
}
|
||||
|
||||
@ -474,18 +470,10 @@ void Cloning::calc(Mat &I, Mat &gx, Mat &gy, Mat &sx, Mat &sy)
|
||||
resultg = Mat(I.size(),CV_8UC1);
|
||||
resultb = Mat(I.size(),CV_8UC1);
|
||||
|
||||
clock_t tic = clock();
|
||||
|
||||
|
||||
poisson_solver(r_channel,rx_channel, ry_channel,resultr);
|
||||
poisson_solver(g_channel,gx_channel, gy_channel,resultg);
|
||||
poisson_solver(b_channel,bx_channel, by_channel,resultb);
|
||||
|
||||
clock_t toc = clock();
|
||||
|
||||
printf("Execution time: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Cloning::normal_clone(Mat &I, Mat &mask, Mat &wmask, Mat &final, int num)
|
||||
@ -562,8 +550,8 @@ void Cloning::normal_clone(Mat &I, Mat &mask, Mat &wmask, Mat &final, int num)
|
||||
for(int i=0;i<mask.size().height;i++)
|
||||
for(int j=0;j<mask.size().width;j++)
|
||||
{
|
||||
gray8.at<uchar>(i,j*3+0) = gray.at<uchar>(i,j);
|
||||
gray8.at<uchar>(i,j*3+1) = gray.at<uchar>(i,j);
|
||||
gray8.at<uchar>(i,j*3+0) = gray.at<uchar>(i,j);
|
||||
gray8.at<uchar>(i,j*3+1) = gray.at<uchar>(i,j);
|
||||
gray8.at<uchar>(i,j*3+2) = gray.at<uchar>(i,j);
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ TEST(Photo_SeamlessClone_featureExchange, regression)
|
||||
|
||||
TEST(Photo_SeamlessClone_colorChange, regression)
|
||||
{
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Color_Change/";
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/color_change/";
|
||||
string original_path1 = folder + "source1.png";
|
||||
string original_path2 = folder + "mask.png";
|
||||
|
||||
@ -179,4 +179,3 @@ TEST(Photo_SeamlessClone_textureFlattening, regression)
|
||||
imwrite(folder + "cloned.png", result);
|
||||
|
||||
}
|
||||
|
||||
|
@ -65,4 +65,3 @@ TEST(Photo_Decolor, regression)
|
||||
imwrite(folder + "color_boost.png",color_boost);
|
||||
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ using namespace std;
|
||||
|
||||
TEST(Photo_NPR_EdgePreserveSmoothing_RecursiveFilter, regression)
|
||||
{
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/Smoothing/";
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
|
||||
string original_path = folder + "test1.png";
|
||||
|
||||
Mat source = imread(original_path, IMREAD_COLOR);
|
||||
@ -66,7 +66,7 @@ TEST(Photo_NPR_EdgePreserveSmoothing_RecursiveFilter, regression)
|
||||
|
||||
TEST(Photo_NPR_EdgePreserveSmoothing_NormConvFilter, regression)
|
||||
{
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/Smoothing/";
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
|
||||
string original_path = folder + "test1.png";
|
||||
|
||||
Mat source = imread(original_path, IMREAD_COLOR);
|
||||
@ -82,7 +82,7 @@ TEST(Photo_NPR_EdgePreserveSmoothing_NormConvFilter, regression)
|
||||
|
||||
TEST(Photo_NPR_DetailEnhance, regression)
|
||||
{
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/Detail_Enhance/";
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
|
||||
string original_path = folder + "test1.png";
|
||||
|
||||
Mat source = imread(original_path, IMREAD_COLOR);
|
||||
@ -98,7 +98,7 @@ TEST(Photo_NPR_DetailEnhance, regression)
|
||||
|
||||
TEST(Photo_NPR_PencilSketch, regression)
|
||||
{
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/Pencil_Sketch/";
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
|
||||
string original_path = folder + "test1.png";
|
||||
|
||||
Mat source = imread(original_path, IMREAD_COLOR);
|
||||
@ -115,7 +115,7 @@ TEST(Photo_NPR_PencilSketch, regression)
|
||||
|
||||
TEST(Photo_NPR_Stylization, regression)
|
||||
{
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/Stylization/";
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
|
||||
string original_path = folder + "test1.png";
|
||||
|
||||
Mat source = imread(original_path, IMREAD_COLOR);
|
||||
@ -131,7 +131,7 @@ TEST(Photo_NPR_Stylization, regression)
|
||||
|
||||
TEST(Photo_NPR_EdgeEnhance, regression)
|
||||
{
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/Edge_Enhance/";
|
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
|
||||
string original_path = folder + "test1.png";
|
||||
|
||||
Mat source = imread(original_path, IMREAD_COLOR);
|
||||
|
@ -46,14 +46,14 @@ int main()
|
||||
int num;
|
||||
cin >> num;
|
||||
cout << endl;
|
||||
|
||||
|
||||
if(num == 1)
|
||||
{
|
||||
string folder = "cloning/Normal_Cloning/";
|
||||
string original_path1 = folder + "source1.png";
|
||||
string original_path2 = folder + "destination1.png";
|
||||
string original_path3 = folder + "mask.png";
|
||||
|
||||
|
||||
Mat source = imread(original_path1, IMREAD_COLOR);
|
||||
Mat destination = imread(original_path2, IMREAD_COLOR);
|
||||
Mat mask = imread(original_path3, IMREAD_COLOR);
|
||||
@ -63,7 +63,7 @@ int main()
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(destination.empty())
|
||||
if(destination.empty())
|
||||
{
|
||||
cout << "Could not load destination image " << original_path2 << endl;
|
||||
exit(0);
|
||||
@ -78,24 +78,24 @@ int main()
|
||||
Point p;
|
||||
p.x = 400;
|
||||
p.y = 100;
|
||||
|
||||
|
||||
seamlessClone(source, destination, mask, p, result, 1);
|
||||
|
||||
|
||||
imshow("Output",result);
|
||||
imwrite(folder + "cloned.png", result);
|
||||
}
|
||||
else if(num == 2)
|
||||
{
|
||||
{
|
||||
string folder = "cloning/Mixed_Cloning/";
|
||||
string original_path1 = folder + "source1.png";
|
||||
string original_path2 = folder + "destination1.png";
|
||||
string original_path3 = folder + "mask.png";
|
||||
|
||||
|
||||
Mat source = imread(original_path1, IMREAD_COLOR);
|
||||
Mat destination = imread(original_path2, IMREAD_COLOR);
|
||||
Mat mask = imread(original_path3, IMREAD_COLOR);
|
||||
|
||||
if(source.empty())
|
||||
if(source.empty())
|
||||
{
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
@ -105,7 +105,7 @@ int main()
|
||||
cout << "Could not load destination image " << original_path2 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(mask.empty())
|
||||
if(mask.empty())
|
||||
{
|
||||
cout << "Could not load mask image " << original_path3 << endl;
|
||||
exit(0);
|
||||
@ -115,7 +115,7 @@ int main()
|
||||
Point p;
|
||||
p.x = destination.size().width/2;
|
||||
p.y = destination.size().height/2;
|
||||
|
||||
|
||||
seamlessClone(source, destination, mask, p, result, 2);
|
||||
|
||||
imshow("Output",result);
|
||||
@ -137,12 +137,12 @@ int main()
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(destination.empty())
|
||||
if(destination.empty())
|
||||
{
|
||||
cout << "Could not load destination image " << original_path2 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(mask.empty())
|
||||
if(mask.empty())
|
||||
{
|
||||
cout << "Could not load mask image " << original_path3 << endl;
|
||||
exit(0);
|
||||
@ -152,7 +152,7 @@ int main()
|
||||
Point p;
|
||||
p.x = destination.size().width/2;
|
||||
p.y = destination.size().height/2;
|
||||
|
||||
|
||||
seamlessClone(source, destination, mask, p, result, 3);
|
||||
|
||||
imshow("Output",result);
|
||||
@ -179,7 +179,7 @@ int main()
|
||||
}
|
||||
|
||||
Mat result;
|
||||
|
||||
|
||||
colorChange(source, mask, result, 1.5, .5, .5);
|
||||
|
||||
imshow("Output",result);
|
||||
@ -194,7 +194,7 @@ int main()
|
||||
Mat source = imread(original_path1, IMREAD_COLOR);
|
||||
Mat mask = imread(original_path2, IMREAD_COLOR);
|
||||
|
||||
if(source.empty())
|
||||
if(source.empty())
|
||||
{
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
@ -206,7 +206,7 @@ int main()
|
||||
}
|
||||
|
||||
Mat result;
|
||||
|
||||
|
||||
illuminationChange(source, mask, result, .2, .4);
|
||||
|
||||
imshow("Output",result);
|
||||
@ -233,7 +233,7 @@ int main()
|
||||
}
|
||||
|
||||
Mat result;
|
||||
|
||||
|
||||
textureFlattening(source, mask, result, 30, 45, 3);
|
||||
|
||||
imshow("Output",result);
|
||||
|
@ -52,9 +52,6 @@ Point* pts = new Point[100];
|
||||
Point* pts2 = new Point[100];
|
||||
Point* pts_diff = new Point[100];
|
||||
|
||||
char src[50];
|
||||
char dest[50];
|
||||
|
||||
int var = 0;
|
||||
int flag = 0, flag1 = 0, flag4 = 0;
|
||||
|
||||
@ -76,39 +73,38 @@ void checkfile(char*);
|
||||
void source(int event, int x, int y, int, void*)
|
||||
{
|
||||
|
||||
if (event == EVENT_LBUTTONDOWN && !drag)
|
||||
{
|
||||
if(flag1 == 0)
|
||||
{
|
||||
if(var==0)
|
||||
img1 = img0.clone();
|
||||
point = Point(x, y);
|
||||
circle(img1,point,2,Scalar(0, 0, 255),-1, 8, 0);
|
||||
pts[var] = point;
|
||||
var++;
|
||||
drag = 1;
|
||||
if(var>1)
|
||||
line(img1,pts[var-2], point, Scalar(0, 0, 255), 2, 8, 0);
|
||||
if (event == EVENT_LBUTTONDOWN && !drag)
|
||||
{
|
||||
if(flag1 == 0)
|
||||
{
|
||||
if(var==0)
|
||||
img1 = img0.clone();
|
||||
point = Point(x, y);
|
||||
circle(img1,point,2,Scalar(0, 0, 255),-1, 8, 0);
|
||||
pts[var] = point;
|
||||
var++;
|
||||
drag = 1;
|
||||
if(var>1)
|
||||
line(img1,pts[var-2], point, Scalar(0, 0, 255), 2, 8, 0);
|
||||
|
||||
imshow("Source", img1);
|
||||
}
|
||||
}
|
||||
imshow("Source", img1);
|
||||
}
|
||||
}
|
||||
|
||||
if (event == EVENT_LBUTTONUP && drag)
|
||||
{
|
||||
imshow("Source", img1);
|
||||
|
||||
if (event == EVENT_LBUTTONUP && drag)
|
||||
{
|
||||
imshow("Source", img1);
|
||||
drag = 0;
|
||||
}
|
||||
if (event == EVENT_RBUTTONDOWN)
|
||||
{
|
||||
flag1 = 1;
|
||||
img1 = img0.clone();
|
||||
for(int i = var; i < numpts ; i++)
|
||||
pts[i] = point;
|
||||
|
||||
drag = 0;
|
||||
}
|
||||
if (event == EVENT_RBUTTONDOWN)
|
||||
{
|
||||
flag1 = 1;
|
||||
img1 = img0.clone();
|
||||
for(int i = var; i < numpts ; i++)
|
||||
pts[i] = point;
|
||||
|
||||
if(var!=0)
|
||||
if(var!=0)
|
||||
{
|
||||
const Point* pts3[1] = {&pts[0]};
|
||||
polylines( img1, pts3, &numpts,1, 1, Scalar(0,0,0), 2, 8, 0);
|
||||
@ -169,67 +165,67 @@ void source(int event, int x, int y, int, void*)
|
||||
waitKey(0);
|
||||
}
|
||||
|
||||
}
|
||||
if (event == EVENT_MBUTTONDOWN)
|
||||
{
|
||||
for(int i = 0; i < numpts ; i++)
|
||||
{
|
||||
pts[i].x=0;
|
||||
pts[i].y=0;
|
||||
}
|
||||
var = 0;
|
||||
flag1 = 0;
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
imshow("Source", img0);
|
||||
}
|
||||
if (event == EVENT_MBUTTONDOWN)
|
||||
{
|
||||
for(int i = 0; i < numpts ; i++)
|
||||
{
|
||||
pts[i].x=0;
|
||||
pts[i].y=0;
|
||||
}
|
||||
var = 0;
|
||||
flag1 = 0;
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
imshow("Source", img0);
|
||||
if(num == 1 || num == 2 || num == 3)
|
||||
imshow("Destination",img2);
|
||||
drag = 0;
|
||||
}
|
||||
drag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void destination(int event, int x, int y, int, void*)
|
||||
{
|
||||
|
||||
Mat im1;
|
||||
minxd = INT_MAX; minyd = INT_MAX; maxxd = INT_MIN; maxyd = INT_MIN;
|
||||
im1 = img2.clone();
|
||||
if (event == EVENT_LBUTTONDOWN)
|
||||
{
|
||||
Mat im1;
|
||||
minxd = INT_MAX; minyd = INT_MAX; maxxd = INT_MIN; maxyd = INT_MIN;
|
||||
im1 = img2.clone();
|
||||
if (event == EVENT_LBUTTONDOWN)
|
||||
{
|
||||
flag4 = 1;
|
||||
if(flag1 == 1)
|
||||
{
|
||||
point = Point(x, y);
|
||||
if(flag1 == 1)
|
||||
{
|
||||
point = Point(x, y);
|
||||
|
||||
for(int i=0;i<var;i++)
|
||||
{
|
||||
pts2[i].x = point.x + pts_diff[i].x;
|
||||
pts2[i].y = point.y + pts_diff[i].y;
|
||||
}
|
||||
|
||||
|
||||
for(int i=var;i<numpts;i++)
|
||||
{
|
||||
pts2[i].x = point.x + pts_diff[0].x;
|
||||
pts2[i].y = point.y + pts_diff[0].y;
|
||||
}
|
||||
|
||||
const Point* pts5[1] = {&pts2[0]};
|
||||
polylines( im1, pts5, &numpts,1, 1, Scalar(0,0,255), 2, 8, 0);
|
||||
const Point* pts5[1] = {&pts2[0]};
|
||||
polylines( im1, pts5, &numpts,1, 1, Scalar(0,0,255), 2, 8, 0);
|
||||
|
||||
destx = x;
|
||||
desty = y;
|
||||
destx = x;
|
||||
desty = y;
|
||||
|
||||
imshow("Destination", im1);
|
||||
}
|
||||
}
|
||||
if (event == EVENT_RBUTTONUP)
|
||||
{
|
||||
for(int i=0;i<flag;i++)
|
||||
{
|
||||
minxd = min(minxd,pts2[i].x);
|
||||
maxxd = max(maxxd,pts2[i].x);
|
||||
minyd = min(minyd,pts2[i].y);
|
||||
maxyd = max(maxyd,pts2[i].y);
|
||||
}
|
||||
imshow("Destination", im1);
|
||||
}
|
||||
}
|
||||
if (event == EVENT_RBUTTONUP)
|
||||
{
|
||||
for(int i=0;i<flag;i++)
|
||||
{
|
||||
minxd = min(minxd,pts2[i].x);
|
||||
maxxd = max(maxxd,pts2[i].x);
|
||||
minyd = min(minyd,pts2[i].y);
|
||||
maxyd = max(maxyd,pts2[i].y);
|
||||
}
|
||||
|
||||
if(maxxd > im1.size().width || maxyd > im1.size().height || minxd < 0 || minyd < 0)
|
||||
{
|
||||
@ -254,7 +250,7 @@ void destination(int event, int x, int y, int, void*)
|
||||
|
||||
if(num == 1 || num == 2 || num == 3)
|
||||
{
|
||||
seamlessClone(img0,img2,res1,point,blend,num);
|
||||
seamlessClone(img0,img2,res1,point,blend,num);
|
||||
imshow("Cloned Image", blend);
|
||||
imwrite("cloned.png",blend);
|
||||
waitKey(0);
|
||||
@ -302,25 +298,24 @@ int main()
|
||||
cin >> num;
|
||||
cout << endl;
|
||||
|
||||
char s[]="Source";
|
||||
char d[]="Destination";
|
||||
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
|
||||
minxd = INT_MAX; minyd = INT_MAX; maxxd = INT_MIN; maxyd = INT_MIN;
|
||||
|
||||
int flag3 = 0;
|
||||
|
||||
if(num == 1 || num == 2 || num == 3)
|
||||
{
|
||||
|
||||
string src,dest;
|
||||
cout << "Enter Source Image: ";
|
||||
cin >> src;
|
||||
|
||||
|
||||
cout << "Enter Destination Image: ";
|
||||
cin >> dest;
|
||||
|
||||
img0 = imread(src);
|
||||
|
||||
|
||||
img2 = imread(dest);
|
||||
|
||||
if(!img0.data)
|
||||
@ -333,7 +328,7 @@ int main()
|
||||
cout << "Destination Image does not exist" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
channel = img0.channels();
|
||||
|
||||
res = Mat::zeros(img2.size(),CV_8UC1);
|
||||
@ -358,7 +353,7 @@ int main()
|
||||
string src;
|
||||
cout << "Enter Source Image: ";
|
||||
cin >> src;
|
||||
|
||||
|
||||
cout << "Enter RGB values: " << endl;
|
||||
cout << "Red: ";
|
||||
cin >> red;
|
||||
@ -428,10 +423,10 @@ int main()
|
||||
|
||||
cout << "high_threshold: ";
|
||||
cin >> high_t;
|
||||
|
||||
|
||||
cout << "kernel_size: ";
|
||||
cin >> kernel_size;
|
||||
|
||||
|
||||
img0 = imread(src);
|
||||
|
||||
if(!img0.data)
|
||||
@ -439,7 +434,7 @@ int main()
|
||||
cout << "Source Image does not exist" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
|
||||
@ -449,12 +444,15 @@ int main()
|
||||
setMouseCallback("Source", source, NULL);
|
||||
imshow("Source", img0);
|
||||
}
|
||||
|
||||
int flag3 = 0;
|
||||
|
||||
while(true)
|
||||
else
|
||||
{
|
||||
char key = waitKey(0);
|
||||
cout << "Wrong Option Choosen" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
for(;;)
|
||||
{
|
||||
char key = (char) waitKey(0);
|
||||
|
||||
if(key == 'd' && flag3 == 0)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* create_mask.cpp
|
||||
*
|
||||
* Author:
|
||||
@ -9,8 +9,6 @@
|
||||
* mask image.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
@ -41,86 +39,85 @@ void mouseHandler(int, int, int, int, void*);
|
||||
void mouseHandler(int event, int x, int y, int, void*)
|
||||
{
|
||||
|
||||
if (event == EVENT_LBUTTONDOWN && !drag)
|
||||
{
|
||||
if(flag1 == 0)
|
||||
{
|
||||
if(var==0)
|
||||
img1 = img0.clone();
|
||||
point = Point(x, y);
|
||||
circle(img1,point,2,Scalar(0, 0, 255),-1, 8, 0);
|
||||
pts[var] = point;
|
||||
var++;
|
||||
drag = 1;
|
||||
if(var>1)
|
||||
line(img1,pts[var-2], point, Scalar(0, 0, 255), 2, 8, 0);
|
||||
if (event == EVENT_LBUTTONDOWN && !drag)
|
||||
{
|
||||
if(flag1 == 0)
|
||||
{
|
||||
if(var==0)
|
||||
img1 = img0.clone();
|
||||
point = Point(x, y);
|
||||
circle(img1,point,2,Scalar(0, 0, 255),-1, 8, 0);
|
||||
pts[var] = point;
|
||||
var++;
|
||||
drag = 1;
|
||||
if(var>1)
|
||||
line(img1,pts[var-2], point, Scalar(0, 0, 255), 2, 8, 0);
|
||||
|
||||
imshow("Source", img1);
|
||||
}
|
||||
}
|
||||
imshow("Source", img1);
|
||||
}
|
||||
}
|
||||
|
||||
if (event == EVENT_LBUTTONUP && drag)
|
||||
{
|
||||
imshow("Source", img1);
|
||||
|
||||
if (event == EVENT_LBUTTONUP && drag)
|
||||
{
|
||||
imshow("Source", img1);
|
||||
drag = 0;
|
||||
}
|
||||
if (event == EVENT_RBUTTONDOWN)
|
||||
{
|
||||
flag1 = 1;
|
||||
img1 = img0.clone();
|
||||
for(int i = var; i < numpts ; i++)
|
||||
pts[i] = point;
|
||||
|
||||
drag = 0;
|
||||
}
|
||||
if (event == EVENT_RBUTTONDOWN)
|
||||
{
|
||||
flag1 = 1;
|
||||
img1 = img0.clone();
|
||||
for(int i = var; i < numpts ; i++)
|
||||
pts[i] = point;
|
||||
if(var!=0)
|
||||
{
|
||||
const Point* pts3[1] = {&pts[0]};
|
||||
polylines( img1, pts3, &numpts,1, 1, Scalar(0,0,0), 2, 8, 0);
|
||||
}
|
||||
|
||||
if(var!=0)
|
||||
{
|
||||
const Point* pts3[1] = {&pts[0]};
|
||||
polylines( img1, pts3, &numpts,1, 1, Scalar(0,0,0), 2, 8, 0);
|
||||
}
|
||||
for(int i=0;i<var;i++)
|
||||
{
|
||||
minx = min(minx,pts[i].x);
|
||||
maxx = max(maxx,pts[i].x);
|
||||
miny = min(miny,pts[i].y);
|
||||
maxy = max(maxy,pts[i].y);
|
||||
}
|
||||
lenx = maxx - minx;
|
||||
leny = maxy - miny;
|
||||
|
||||
for(int i=0;i<var;i++)
|
||||
{
|
||||
minx = min(minx,pts[i].x);
|
||||
maxx = max(maxx,pts[i].x);
|
||||
miny = min(miny,pts[i].y);
|
||||
maxy = max(maxy,pts[i].y);
|
||||
}
|
||||
lenx = maxx - minx;
|
||||
leny = maxy - miny;
|
||||
imshow("Source", img1);
|
||||
}
|
||||
|
||||
imshow("Source", img1);
|
||||
}
|
||||
if (event == EVENT_RBUTTONUP)
|
||||
{
|
||||
flag = var;
|
||||
|
||||
if (event == EVENT_RBUTTONUP)
|
||||
{
|
||||
flag = var;
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
const Point* pts4[1] = {&pts[0]};
|
||||
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
const Point* pts4[1] = {&pts[0]};
|
||||
|
||||
fillPoly(res1, pts4,&numpts, 1, Scalar(255, 255, 255), 8, 0);
|
||||
bitwise_and(img0, img0, final,res1);
|
||||
fillPoly(res1, pts4,&numpts, 1, Scalar(255, 255, 255), 8, 0);
|
||||
bitwise_and(img0, img0, final,res1);
|
||||
imshow("mask",res1);
|
||||
imwrite("mask.png",res1);
|
||||
|
||||
imshow("Source", img1);
|
||||
imshow("Source", img1);
|
||||
|
||||
}
|
||||
if (event == EVENT_MBUTTONDOWN)
|
||||
{
|
||||
for(int i = 0; i < numpts ; i++)
|
||||
{
|
||||
pts[i].x=0;
|
||||
pts[i].y=0;
|
||||
}
|
||||
var = 0;
|
||||
flag1 = 0;
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
imshow("Source", img0);
|
||||
drag = 0;
|
||||
}
|
||||
}
|
||||
if (event == EVENT_MBUTTONDOWN)
|
||||
{
|
||||
for(int i = 0; i < numpts ; i++)
|
||||
{
|
||||
pts[i].x=0;
|
||||
pts[i].y=0;
|
||||
}
|
||||
var = 0;
|
||||
flag1 = 0;
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
imshow("Source", img0);
|
||||
drag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -134,21 +131,21 @@ int main(int argc, char **argv)
|
||||
|
||||
Mat src = imread(argv[1]);
|
||||
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
|
||||
img0 = src;
|
||||
img0 = src;
|
||||
|
||||
channel = img0.channels();
|
||||
channel = img0.channels();
|
||||
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
//////////// source image ///////////////////
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
//////////// source image ///////////////////
|
||||
|
||||
namedWindow("Source", 1);
|
||||
setMouseCallback("Source", mouseHandler, NULL);
|
||||
imshow("Source", img0);
|
||||
namedWindow("Source", 1);
|
||||
setMouseCallback("Source", mouseHandler, NULL);
|
||||
imshow("Source", img0);
|
||||
waitKey(0);
|
||||
|
||||
img0.release();
|
||||
img1.release();
|
||||
img0.release();
|
||||
img1.release();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user