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

Added LUT for FP16 and accuracy test#25787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
asmorkalov merged 1 commit intoopencv:4.xfromasmorkalov:as/lut_fp16
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletionmodules/core/src/lut.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,11 @@ static void LUT8u_32s( const uchar* src, const int* lut, int* dst, int len, int
LUT8u_( src, lut, dst, len, cn, lutcn );
}

static void LUT8u_16f( const uchar* src, const hfloat* lut, hfloat* dst, int len, int cn, int lutcn )
{
LUT8u_( src, lut, dst, len, cn, lutcn );
}

static void LUT8u_32f( const uchar* src, const float* lut, float* dst, int len, int cn, int lutcn )
{
LUT8u_( src, lut, dst, len, cn, lutcn );
Expand All@@ -71,7 +76,7 @@ typedef void (*LUTFunc)( const uchar* src, const uchar* lut, uchar* dst, int len
static LUTFunc lutTab[CV_DEPTH_MAX] =
{
(LUTFunc)LUT8u_8u, (LUTFunc)LUT8u_8s, (LUTFunc)LUT8u_16u, (LUTFunc)LUT8u_16s,
(LUTFunc)LUT8u_32s, (LUTFunc)LUT8u_32f, (LUTFunc)LUT8u_64f,0
(LUTFunc)LUT8u_32s, (LUTFunc)LUT8u_32f, (LUTFunc)LUT8u_64f,(LUTFunc)LUT8u_16f
};

#ifdef HAVE_OPENCL
Expand Down
98 changes: 98 additions & 0 deletionsmodules/core/test/test_arithm.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3196,5 +3196,103 @@ INSTANTIATE_TEST_CASE_P(Core_CartPolar, Core_PolarToCart_inplace,
)
);

CV_ENUM(LutMatType, CV_8U, CV_16U, CV_16F, CV_32S, CV_32F, CV_64F)

struct Core_LUT: public testing::TestWithParam<LutMatType>
{
template<typename T, int ch>
cv::Mat referenceWithType(cv::Mat input, cv::Mat table)
{
cv::Mat ref(input.size(), CV_MAKE_TYPE(table.type(), ch));
for (int i = 0; i < input.rows; i++)
{
for (int j = 0; j < input.cols; j++)
{
if(ch == 1)
{
ref.at<T>(i, j) = table.at<T>(input.at<uchar>(i, j));
}
else
{
Vec<T, ch> val;
for (int k = 0; k < ch; k++)
{
val[k] = table.at<T>(input.at<Vec<uchar, ch>>(i, j)[k]);
}
ref.at<Vec<T, ch>>(i, j) = val;
}
}
}
return ref;
}

template<int ch = 1>
cv::Mat reference(cv::Mat input, cv::Mat table)
{
if (table.type() == CV_8U)
{
return referenceWithType<uchar, ch>(input, table);
}
else if (table.type() == CV_16U)
{
return referenceWithType<ushort, ch>(input, table);
}
else if (table.type() == CV_16F)
{
return referenceWithType<ushort, ch>(input, table);
}
else if (table.type() == CV_32S)
{
return referenceWithType<int, ch>(input, table);
}
else if (table.type() == CV_32F)
{
return referenceWithType<float, ch>(input, table);
}
else if (table.type() == CV_64F)
{
return referenceWithType<double, ch>(input, table);
}

return cv::Mat();
}
};

TEST_P(Core_LUT, accuracy)
{
int type = GetParam();
cv::Mat input(117, 113, CV_8UC1);
randu(input, 0, 256);

cv::Mat table(1, 256, CV_MAKE_TYPE(type, 1));
randu(table, 0, 127);

cv::Mat output;
cv::LUT(input, table, output);

cv::Mat gt = reference(input, table);

ASSERT_EQ(0, cv::norm(output, gt, cv::NORM_INF));
}

TEST_P(Core_LUT, accuracy_multi)
{
int type = (int)GetParam();
cv::Mat input(117, 113, CV_8UC3);
randu(input, 0, 256);

cv::Mat table(1, 256, CV_MAKE_TYPE(type, 1));
randu(table, 0, 127);

cv::Mat output;
cv::LUT(input, table, output);

cv::Mat gt = reference<3>(input, table);

ASSERT_EQ(0, cv::norm(output, gt, cv::NORM_INF));
}


INSTANTIATE_TEST_CASE_P(/**/, Core_LUT, LutMatType::all());

}} // namespace

[8]ページ先頭

©2009-2025 Movatter.jp