Skip to content

Commit 43a4786

Browse files
authored
Merge pull request #3916 from CodeLinaro:normalizeLocalBox_extension_Fastcv
Adding FastCV extension for normalizeLocalBox u8 and f32 #3916 Fastcv extension for normalizeLocalBox u8 and f32 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
1 parent 1fffe35 commit 43a4786

File tree

4 files changed

+87
-4
lines changed

4 files changed

+87
-4
lines changed

modules/fastcv/include/opencv2/fastcv/blur.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
2+
* Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -58,6 +58,22 @@ CV_EXPORTS_W void filter2D(InputArray _src, OutputArray _dst, int ddepth, InputA
5858
CV_EXPORTS_W void sepFilter2D(InputArray _src, OutputArray _dst, int ddepth, InputArray _kernelX, InputArray _kernelY);
5959
//! @}
6060

61+
//! @addtogroup fastcv
62+
//! @{
63+
64+
/**
65+
* @brief Calculates the local subtractive and contrastive normalization of the image.
66+
* Each pixel of the image is normalized by the mean and standard deviation of the patch centred at the pixel.
67+
* It is optimized for Qualcomm's processors.
68+
* @param _src Input image, should have one channel CV_8U or CV_32F
69+
* @param _dst Output array, should be one channel, CV_8S if src of type CV_8U, or CV_32F if src of CV_32F
70+
* @param pSize Patch size for mean and std dev calculation
71+
* @param useStdDev If 1, bot mean and std dev will be used for normalization, if 0, only mean used
72+
*/
73+
CV_EXPORTS_W void normalizeLocalBox(InputArray _src, OutputArray _dst, Size pSize, bool useStdDev);
74+
75+
//! @}
76+
6177
} // fastcv::
6278
} // cv::
6379

modules/fastcv/perf/perf_blur.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
2+
* Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -120,4 +120,29 @@ PERF_TEST_P(SepFilter2DPerfTest, run,
120120
SANITY_CHECK_NOTHING();
121121
}
122122

123+
typedef perf::TestBaseWithParam<tuple<Size, int, Size, int>> NormalizeLocalBoxPerfTest;
124+
125+
PERF_TEST_P(NormalizeLocalBoxPerfTest, run,
126+
::testing::Combine(::testing::Values(perf::szVGA, perf::sz720p, perf::sz1080p), // image size
127+
::testing::Values(CV_8U,CV_32F), // src image depth
128+
::testing::Values(Size(3,3),Size(5,5)), // patch size
129+
::testing::Values(0,1) // use std dev or not
130+
)
131+
)
132+
{
133+
cv::Size srcSize = get<0>(GetParam());
134+
int depth = get<1>(GetParam());
135+
Size sz = get<2>(GetParam());
136+
bool useStdDev = get<3>(GetParam());
137+
138+
cv::Mat src(srcSize, depth);
139+
cv::Mat dst;
140+
RNG& rng = cv::theRNG();
141+
cvtest::randUni(rng, src, Scalar::all(0), Scalar::all(255));
142+
143+
TEST_CYCLE() cv::fastcv::normalizeLocalBox(src, dst, sz, useStdDev);
144+
145+
SANITY_CHECK_NOTHING();
146+
}
147+
123148
} // namespace

modules/fastcv/src/blur.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
2+
* Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -361,5 +361,26 @@ void sepFilter2D(InputArray _src, OutputArray _dst, int ddepth, InputArray _kern
361361
}
362362
}
363363

364+
void normalizeLocalBox(InputArray _src, OutputArray _dst, Size pSize, bool useStdDev)
365+
{
366+
CV_Assert(!_src.empty());
367+
int type = _src.type();
368+
CV_Assert(type == CV_8UC1 || type == CV_32FC1);
369+
370+
Size size = _src.size();
371+
int dst_type = type == CV_8UC1 ? CV_8SC1 : CV_32FC1;
372+
_dst.create(size, dst_type);
373+
374+
Mat src = _src.getMat();
375+
Mat dst = _dst.getMat();
376+
377+
if(type == CV_8UC1)
378+
fcvNormalizeLocalBoxu8(src.data, src.cols, src.rows, src.step[0],
379+
pSize.width, pSize.height, useStdDev, (int8_t*)dst.data, dst.step[0]);
380+
else if(type == CV_32FC1)
381+
fcvNormalizeLocalBoxf32((float*)src.data, src.cols, src.rows, src.step[0],
382+
pSize.width, pSize.height, useStdDev, (float*)dst.data, dst.step[0]);
383+
}
384+
364385
} // fastcv::
365386
} // cv::

modules/fastcv/test/test_blur.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
2+
* Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -108,6 +108,24 @@ TEST_P(SepFilter2DTest, accuracy)
108108
EXPECT_LT(num_diff_pixels, (src.rows+src.cols)*ksize);
109109
}
110110

111+
typedef testing::TestWithParam<tuple<int>> NormalizeLocalBoxTest;
112+
113+
TEST_P(NormalizeLocalBoxTest, accuracy)
114+
{
115+
bool use_stddev = get<0>(GetParam());
116+
cv::Mat src, dst;
117+
src = imread(cvtest::findDataFile("cv/shared/baboon.png"), cv::IMREAD_GRAYSCALE);
118+
119+
cv::fastcv::normalizeLocalBox(src, dst, Size(5,5), use_stddev);
120+
Scalar s = cv::mean(dst);
121+
122+
if(use_stddev)
123+
EXPECT_LT(s[0],1);
124+
else
125+
EXPECT_LT(s[0],50);
126+
}
127+
128+
111129
INSTANTIATE_TEST_CASE_P(FastCV_Extension, GaussianBlurTest, Combine(
112130
/*image size*/ ::testing::Values(perf::szVGA, perf::sz720p, perf::sz1080p),
113131
/*image depth*/ ::testing::Values(CV_8U,CV_16S,CV_32S),
@@ -126,4 +144,7 @@ INSTANTIATE_TEST_CASE_P(FastCV_Extension, SepFilter2DTest, Combine(
126144
/*kernel size*/ Values(3, 5, 7, 9, 11)
127145
));
128146

147+
INSTANTIATE_TEST_CASE_P(FastCV_Extension, NormalizeLocalBoxTest, Values(0,1));
148+
149+
129150
}} // namespaces opencv_test, ::

0 commit comments

Comments
 (0)