Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita102b24

Browse files
committed
Added LUT for FP16 and accuracy test.
1 parentd1b643a commita102b24

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

‎modules/core/src/lut.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ static void LUT8u_32s( const uchar* src, const int* lut, int* dst, int len, int
5656
LUT8u_( src, lut, dst, len, cn, lutcn );
5757
}
5858

59+
staticvoidLUT8u_16f(const uchar* src,const hfloat* lut, hfloat* dst,int len,int cn,int lutcn )
60+
{
61+
LUT8u_( src, lut, dst, len, cn, lutcn );
62+
}
63+
5964
staticvoidLUT8u_32f(const uchar* src,constfloat* lut,float* dst,int len,int cn,int lutcn )
6065
{
6166
LUT8u_( src, lut, dst, len, cn, lutcn );
@@ -71,7 +76,7 @@ typedef void (*LUTFunc)( const uchar* src, const uchar* lut, uchar* dst, int len
7176
static LUTFunc lutTab[CV_DEPTH_MAX] =
7277
{
7378
(LUTFunc)LUT8u_8u, (LUTFunc)LUT8u_8s, (LUTFunc)LUT8u_16u, (LUTFunc)LUT8u_16s,
74-
(LUTFunc)LUT8u_32s, (LUTFunc)LUT8u_32f, (LUTFunc)LUT8u_64f,0
79+
(LUTFunc)LUT8u_32s, (LUTFunc)LUT8u_32f, (LUTFunc)LUT8u_64f,(LUTFunc)LUT8u_16f
7580
};
7681

7782
#ifdef HAVE_OPENCL

‎modules/core/test/test_arithm.cpp‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
elseif (table.type() == CV_16U)
3237+
{
3238+
return referenceWithType<ushort, ch>(input, table);
3239+
}
3240+
elseif (table.type() == CV_16F)
3241+
{
3242+
return referenceWithType<ushort, ch>(input, table);
3243+
}
3244+
elseif (table.type() == CV_32S)
3245+
{
3246+
return referenceWithType<int, ch>(input, table);
3247+
}
3248+
elseif (table.type() == CV_32F)
3249+
{
3250+
return referenceWithType<float, ch>(input, table);
3251+
}
3252+
elseif (table.type() == CV_64F)
3253+
{
3254+
return referenceWithType<double, ch>(input, table);
3255+
}
3256+
3257+
returncv::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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp