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) 2010-2012, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
18 // Fangfang Bai, fangfang@multicorewareinc.com
19 // Jin Ma, jin@multicorewareinc.com
21 // Redistribution and use in source and binary forms, with or without modification,
22 // are permitted provided that the following conditions are met:
24 // * Redistribution's of source code must retain the above copyright notice,
25 // this list of conditions and the following disclaimer.
27 // * Redistribution's in binary form must reproduce the above copyright notice,
28 // this list of conditions and the following disclaimer in the documentation
29 // and/or other oclMaterials provided with the distribution.
31 // * The name of the copyright holders may not be used to endorse or promote products
32 // derived from this software without specific prior written permission.
34 // This software is provided by the copyright holders and contributors as is and
35 // any express or implied warranties, including, but not limited to, the implied
36 // warranties of merchantability and fitness for a particular purpose are disclaimed.
37 // In no event shall the Intel Corporation or contributors be liable for any direct,
38 // indirect, incidental, special, exemplary, or consequential damages
39 // (including, but not limited to, procurement of substitute goods or services;
40 // loss of use, data, or profits; or business interruption) however caused
41 // and on any theory of liability, whether in contract, strict liability,
42 // or tort (including negligence or otherwise) arising in any way out of
43 // the use of this software, even if advised of the possibility of such damage.
47 #include "precomp.hpp"
48 ///////////// blend ////////////////////////
50 void blendLinearGold(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &weights1, const cv::Mat &weights2, cv::Mat &result_gold)
52 result_gold.create(img1.size(), img1.type());
54 int cn = img1.channels();
56 for (int y = 0; y < img1.rows; ++y)
58 const float *weights1_row = weights1.ptr<float>(y);
59 const float *weights2_row = weights2.ptr<float>(y);
60 const T *img1_row = img1.ptr<T>(y);
61 const T *img2_row = img2.ptr<T>(y);
62 T *result_gold_row = result_gold.ptr<T>(y);
64 for (int x = 0; x < img1.cols * cn; ++x)
66 float w1 = weights1_row[x / cn];
67 float w2 = weights2_row[x / cn];
68 result_gold_row[x] = static_cast<T>((img1_row[x] * w1 + img2_row[x] * w2) / (w1 + w2 + 1e-5f));
74 Mat src1, src2, weights1, weights2, dst, ocl_dst;
75 ocl::oclMat d_src1, d_src2, d_weights1, d_weights2, d_dst;
77 int all_type[] = {CV_8UC1, CV_8UC4};
78 std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
80 for (int size = Min_Size; size <= Max_Size; size *= Multiple)
82 for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
84 SUBTEST << size << 'x' << size << "; " << type_name[j] << " and CV_32FC1";
86 gen(src1, size, size, all_type[j], 0, 256);
87 gen(src2, size, size, all_type[j], 0, 256);
88 gen(weights1, size, size, CV_32FC1, 0, 1);
89 gen(weights2, size, size, CV_32FC1, 0, 1);
91 blendLinearGold<uchar>(src1, src2, weights1, weights2, dst);
94 blendLinearGold<uchar>(src1, src2, weights1, weights2, dst);
99 d_weights1.upload(weights1);
100 d_weights2.upload(weights2);
103 ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
107 ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
113 d_weights1.upload(weights1);
114 d_weights2.upload(weights2);
115 ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
116 d_dst.download(ocl_dst);
119 TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.f);