@@ -3196,5 +3196,103 @@ INSTANTIATE_TEST_CASE_P(Core_CartPolar, Core_PolarToCart_inplace,
31963196 )
31973197);
31983198
3199+ CV_ENUM (LutMatType, CV_8U, CV_16U, CV_16F, CV_32S, CV_32F, CV_64F)
3200+
3201+ struct Core_LUT: public testing::TestWithParam<LutMatType>
3202+ {
3203+ template <typename T,int ch>
3204+ cv::MatreferenceWithType (cv::Mat input, cv::Mat table)
3205+ {
3206+ cv::Matref (input.size (),CV_MAKE_TYPE (table.type (), ch));
3207+ for (int i =0 ; i < input.rows ; i++)
3208+ {
3209+ for (int j =0 ; j < input.cols ; j++)
3210+ {
3211+ if (ch ==1 )
3212+ {
3213+ ref.at <T>(i, j) = table.at <T>(input.at <uchar>(i, j));
3214+ }
3215+ else
3216+ {
3217+ Vec<T, ch> val;
3218+ for (int k =0 ; k < ch; k++)
3219+ {
3220+ val[k] = table.at <T>(input.at <Vec<uchar, ch>>(i, j)[k]);
3221+ }
3222+ ref.at <Vec<T, ch>>(i, j) = val;
3223+ }
3224+ }
3225+ }
3226+ return ref;
3227+ }
3228+
3229+ template <int ch =1 >
3230+ cv::Matreference (cv::Mat input, cv::Mat table)
3231+ {
3232+ if (table.type () == CV_8U)
3233+ {
3234+ return referenceWithType<uchar, ch>(input, table);
3235+ }
3236+ else if (table.type () == CV_16U)
3237+ {
3238+ return referenceWithType<ushort, ch>(input, table);
3239+ }
3240+ else if (table.type () == CV_16F)
3241+ {
3242+ return referenceWithType<ushort, ch>(input, table);
3243+ }
3244+ else if (table.type () == CV_32S)
3245+ {
3246+ return referenceWithType<int , ch>(input, table);
3247+ }
3248+ else if (table.type () == CV_32F)
3249+ {
3250+ return referenceWithType<float , ch>(input, table);
3251+ }
3252+ else if (table.type () == CV_64F)
3253+ {
3254+ return referenceWithType<double , ch>(input, table);
3255+ }
3256+
3257+ return cv::Mat ();
3258+ }
3259+ };
3260+
3261+ TEST_P (Core_LUT, accuracy)
3262+ {
3263+ int type =GetParam ();
3264+ cv::Matinput (117 ,113 , CV_8UC1);
3265+ randu (input,0 ,256 );
3266+
3267+ cv::Mattable (1 ,256 ,CV_MAKE_TYPE (type,1 ));
3268+ randu (table,0 ,127 );
3269+
3270+ cv::Mat output;
3271+ cv::LUT (input, table, output);
3272+
3273+ cv::Mat gt =reference (input, table);
3274+
3275+ ASSERT_EQ (0 ,cv::norm (output, gt, cv::NORM_INF));
3276+ }
3277+
3278+ TEST_P (Core_LUT, accuracy_multi)
3279+ {
3280+ int type = (int )GetParam ();
3281+ cv::Matinput (117 ,113 , CV_8UC3);
3282+ randu (input,0 ,256 );
3283+
3284+ cv::Mattable (1 ,256 ,CV_MAKE_TYPE (type,1 ));
3285+ randu (table,0 ,127 );
3286+
3287+ cv::Mat output;
3288+ cv::LUT (input, table, output);
3289+
3290+ cv::Mat gt = reference<3 >(input, table);
3291+
3292+ ASSERT_EQ (0 ,cv::norm (output, gt, cv::NORM_INF));
3293+ }
3294+
3295+
3296+ INSTANTIATE_TEST_CASE_P (/* */ , Core_LUT, LutMatType::all());
31993297
32003298}}// namespace