add color_boost + doc
This commit is contained in:
parent
88aa4a9902
commit
a1b3ba02a7
20
modules/photo/doc/decolor.rst
Normal file
20
modules/photo/doc/decolor.rst
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Decolorization
|
||||||
|
==============
|
||||||
|
|
||||||
|
.. highlight:: cpp
|
||||||
|
|
||||||
|
decolor
|
||||||
|
-------
|
||||||
|
|
||||||
|
Transforms a color image to a grayscale image. It is a basic tool in digital printing, stylized black-and-white photograph rendering, and in many single channel image processing applications.
|
||||||
|
|
||||||
|
.. ocv:function:: void decolor( InputArray src, OutputArray grayscale, OutputArray color_boost )
|
||||||
|
|
||||||
|
:param src: Input 8-bit 3-channel image.
|
||||||
|
|
||||||
|
:param grayscale: Output 8-bit 1-channel image.
|
||||||
|
|
||||||
|
:param color_boost: Output 8-bit 3-channel image.
|
||||||
|
|
||||||
|
This function is to be applied on color images.
|
||||||
|
|
@ -288,7 +288,7 @@ public:
|
|||||||
|
|
||||||
CV_EXPORTS_W Ptr<MergeRobertson> createMergeRobertson();
|
CV_EXPORTS_W Ptr<MergeRobertson> createMergeRobertson();
|
||||||
|
|
||||||
CV_EXPORTS_W void decolor(InputArray src, OutputArray grayscale);
|
CV_EXPORTS_W void decolor(InputArray src, OutputArray grayscale, OutputArray color_boost);
|
||||||
|
|
||||||
} // cv
|
} // cv
|
||||||
|
|
||||||
|
@ -17,14 +17,17 @@ int rounding(double a)
|
|||||||
return int(a + 0.5);
|
return int(a + 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cv::decolor(InputArray _src, OutputArray _dst)
|
void cv::decolor(InputArray _src, OutputArray _dst, OutputArray _boost)
|
||||||
{
|
{
|
||||||
Mat I = _src.getMat();
|
Mat I = _src.getMat();
|
||||||
_dst.create(I.size(), CV_8UC1);
|
_dst.create(I.size(), CV_8UC1);
|
||||||
Mat dst = _dst.getMat();
|
Mat dst = _dst.getMat();
|
||||||
|
|
||||||
if(!I.data )
|
_boost.create(I.size(), CV_8UC3);
|
||||||
{
|
Mat color_boost = _boost.getMat();
|
||||||
|
|
||||||
|
if(!I.data )
|
||||||
|
{
|
||||||
cout << "Could not open or find the image" << endl ;
|
cout << "Could not open or find the image" << endl ;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -162,5 +165,40 @@ void cv::decolor(InputArray _src, OutputArray _dst)
|
|||||||
|
|
||||||
Gray.convertTo(dst,CV_8UC1,255);
|
Gray.convertTo(dst,CV_8UC1,255);
|
||||||
|
|
||||||
|
/////////////////////////////////// Contrast Boosting /////////////////////////////////
|
||||||
|
|
||||||
|
Mat lab = Mat(img.size(),CV_8UC3);
|
||||||
|
Mat color = Mat(img.size(),CV_8UC3);
|
||||||
|
Mat l = Mat(img.size(),CV_8UC1);
|
||||||
|
Mat a = Mat(img.size(),CV_8UC1);
|
||||||
|
Mat b = Mat(img.size(),CV_8UC1);
|
||||||
|
|
||||||
|
cvtColor(I,lab,COLOR_BGR2Lab);
|
||||||
|
|
||||||
|
int h1 = img.size().height;
|
||||||
|
int w1 = img.size().width;
|
||||||
|
|
||||||
|
for(int i =0;i<h1;i++)
|
||||||
|
for(int j=0;j<w1;j++)
|
||||||
|
{
|
||||||
|
l.at<uchar>(i,j) = lab.at<uchar>(i,j*3+0);
|
||||||
|
a.at<uchar>(i,j) = lab.at<uchar>(i,j*3+1);
|
||||||
|
b.at<uchar>(i,j) = lab.at<uchar>(i,j*3+2);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i =0;i<h1;i++)
|
||||||
|
for(int j=0;j<w1;j++)
|
||||||
|
{
|
||||||
|
lab.at<uchar>(i,j*3+0) = l.at<uchar>(i,j);
|
||||||
|
lab.at<uchar>(i,j*3+1) = a.at<uchar>(i,j);
|
||||||
|
lab.at<uchar>(i,j*3+2) = b.at<uchar>(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
cvtColor(lab,color_boost,COLOR_Lab2BGR);
|
||||||
}
|
}
|
||||||
|
@ -16,19 +16,24 @@ TEST(Photo_Decolor, regression)
|
|||||||
{
|
{
|
||||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "decolor/";
|
string folder = string(cvtest::TS::ptr()->get_data_path()) + "decolor/";
|
||||||
string original_path = folder + "color_image_1.png";
|
string original_path = folder + "color_image_1.png";
|
||||||
string expected_path = folder + "grayscale_image_1.png";
|
string expected_path1 = folder + "grayscale_image_1.png";
|
||||||
|
string expected_path2 = folder + "color_boost_image_1.png";
|
||||||
|
|
||||||
Mat original = imread(original_path, IMREAD_COLOR);
|
Mat original = imread(original_path, IMREAD_COLOR);
|
||||||
Mat expected = imread(expected_path, IMREAD_GRAYSCALE);
|
Mat expected1 = imread(expected_path1, IMREAD_GRAYSCALE);
|
||||||
|
Mat expected2 = imread(expected_path2, IMREAD_COLOR);
|
||||||
|
|
||||||
ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path;
|
ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path;
|
||||||
ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path;
|
ASSERT_FALSE(expected1.empty()) << "Could not load reference image " << expected_path1;
|
||||||
|
ASSERT_FALSE(expected2.empty()) << "Could not load reference image " << expected_path2;
|
||||||
|
|
||||||
Mat result;
|
Mat grayscale, color_boost;
|
||||||
decolor(original, result);
|
decolor(original, grayscale, color_boost);
|
||||||
|
|
||||||
DUMP(result, expected_path + ".res.png");
|
DUMP(grayscale, expected_path1 + ".grayscale.png");
|
||||||
|
DUMP(color_boost, expected_path2 + ".color_boost.png");
|
||||||
|
|
||||||
ASSERT_EQ(0, norm(result != expected));
|
ASSERT_EQ(0, norm(grayscale != expected1));
|
||||||
|
ASSERT_EQ(0, norm(color_boost != expected2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user