Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simd optimization #145

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
48bade0
Add dummy test
mabean Feb 1, 2016
c5f5148
Add size test for BGR2GRAY + GuoHall
mabean Feb 1, 2016
387743a
Add size test for ImageResize
mabean Feb 1, 2016
cf92dbd
Add color test for ImageResize
mabean Feb 1, 2016
cc8e6e0
Add color test for bgr2gray
mabean Feb 1, 2016
2f5cf2d
Add correct work test for guohall
mabean Feb 1, 2016
c612d90
Merge branch 'add-new-google-tests'
mabean Feb 2, 2016
80b0939
Add perf test
mabean Feb 3, 2016
521f04e
fix merge conflict
mabean Feb 3, 2016
1f0e199
Merge https://github.com/itseez-academy/itseez-ws-2016-practice
mabean Feb 3, 2016
57a834d
Merge branch 'profiling-and-benchmarking'
mabean Feb 3, 2016
e3946ee
first step of optimization
mabean Feb 3, 2016
d8b4bb4
Current version of step 2
mabean Feb 3, 2016
990041a
second version of second step optimization
mabean Feb 4, 2016
ea69950
minor fix for second version
mabean Feb 4, 2016
0c8a9e3
fix merge problem
mabean Feb 4, 2016
20fb505
Merge https://github.com/itseez-academy/itseez-ws-2016-practice
mabean Feb 4, 2016
f4c878b
2 steps of the optimization
mabean Feb 4, 2016
71973ac
floor optimization in resize func
mabean Feb 4, 2016
9f5a4d9
deleting STL using for Travis
mabean Feb 4, 2016
3b1760b
fixes for perf_tests and optimization improve
mabean Feb 4, 2016
7e1b4fb
fix merge conflict in resize.cpp
mabean Feb 4, 2016
ca5b171
fix > >
mabean Feb 4, 2016
ff3de85
2.7 boost version
mabean Feb 4, 2016
5444d98
Working version of optimizations of GuoHall and Resize
mabean Feb 4, 2016
35c93d6
fix merge conflict in perf_skeleton
mabean Feb 5, 2016
b8f76fe
fix another merge conflict
mabean Feb 6, 2016
081c87c
Try to fix perf_skeleton
mabean Feb 6, 2016
86e3107
Merge branch 'master' of https://github.com/itseez-academy/itseez-ws-…
mabean Feb 6, 2016
0d93736
SIMD optimized version
mabean Feb 6, 2016
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
Prev Previous commit
Next Next commit
Working version of optimizations of GuoHall and Resize
mabean committed Feb 4, 2016
commit 5444d9839558fd71fb74fe394a98cd69269abb87
60 changes: 30 additions & 30 deletions perf/perf_skeleton.cpp
Original file line number Diff line number Diff line change
@@ -60,20 +60,20 @@ PERF_TEST_P(Size_Only, ImageResize, testing::Values(MAT_SIZES))
// Test(s) for the skeletonize function
//

//<<<<<<< HEAD
#define IMAGES testing::Values( std::string("./bin/testdata/sla.png"),\

/*#define IMAGES testing::Values( std::string("./bin/testdata/sla.png"),\
std::string("./bin/testdata/page.png"),\
std::string("./bin/testdata/schedule.png") )
typedef perf::TestBaseWithParam<std::string> ImageName;
typedef perf::TestBaseWithParam<std::string> ImageName;*/

//PERF_TEST_P(ImageName, skeletonize, IMAGES)
//{
// Mat input = cv::imread(GetParam());

// // Add code here
//}
//=======

// #define IMAGES testing::Values( std::string("./bin/testdata/sla.png"),\
// std::string("./bin/testdata/page.png"),\
// std::string("./bin/testdata/schedule.png") )
@@ -91,29 +91,29 @@ PERF_TEST_P(Size_Only, ImageResize, testing::Values(MAT_SIZES))
// Test(s) for the Thinning function
//

//PERF_TEST_P(Size_Only, Thinning, testing::Values(MAT_SIZES))
//{
// Size sz = GetParam();
//
// cv::Mat image(sz, CV_8UC1);
// declare.in(image, WARMUP_RNG).out(image);
// declare.time(60);
//
// cv::RNG rng(234231412);
// rng.fill(image, CV_8UC1, 0, 255);
// cv::threshold(image, image, 240, 255, cv::THRESH_BINARY_INV);
//
// cv::Mat gold; GuoHallThinning(image, gold);
//
// cv::Mat thinned_image;
// TEST_CYCLE()
// {
// GuoHallThinning_optimized(image, thinned_image);
// }
//
// cv::Mat diff; cv::absdiff(thinned_image, gold, diff);
// ASSERT_EQ(0, cv::countNonZero(diff));
//
// SANITY_CHECK(image);
//}
//>>>>>>> 957b2ec1d79263fb46b3320256314e063895b9a3
PERF_TEST_P(Size_Only, Thinning, testing::Values(MAT_SIZES))
{
Size sz = GetParam();

cv::Mat image(sz, CV_8UC1);
declare.in(image, WARMUP_RNG).out(image);
declare.time(130);

cv::RNG rng(234231412);
rng.fill(image, CV_8UC1, 0, 255);
cv::threshold(image, image, 240, 255, cv::THRESH_BINARY_INV);

cv::Mat gold; GuoHallThinning(image, gold);

cv::Mat thinned_image;
TEST_CYCLE()
{
GuoHallThinning_optimized(image, thinned_image);
}

cv::Mat diff; cv::absdiff(thinned_image, gold, diff);
ASSERT_EQ(0, cv::countNonZero(diff));

SANITY_CHECK(image);
}

70 changes: 28 additions & 42 deletions src/thinning.cpp
Original file line number Diff line number Diff line change
@@ -125,14 +125,14 @@ static void createTable(int iter)
uchar p8 = i & 64;
uchar p9 = i & 128;

p2 = (!p2 ? 1 : 0);
p3 = (!p3 ? 1 : 0);
p4 = (!p4 ? 1 : 0);
p5 = (!p5 ? 1 : 0);
p6 = (!p6 ? 1 : 0);
p7 = (!p7 ? 1 : 0);
p8 = (!p8 ? 1 : 0);
p9 = (!p9 ? 1 : 0);
p2 = (p2 != 0 ? 1 : 0);
p3 = (p3 != 0 ? 1 : 0);
p4 = (p4 != 0 ? 1 : 0);
p5 = (p5 != 0 ? 1 : 0);
p6 = (p6 != 0 ? 1 : 0);
p7 = (p7 != 0 ? 1 : 0);
p8 = (p8 != 0 ? 1 : 0);
p9 = (p9 != 0 ? 1 : 0);

int C = (!p2 & (p3 | p4)) + (!p4 & (p5 | p6)) +
(!p6 & (p7 | p8)) + (!p8 & (p9 | p2));
@@ -177,49 +177,35 @@ static void GuoHallIteration_optimized(cv::Mat& im, int iter)
{
if (im.at<uchar>(i, j))
{
std::vector<uchar> p(8);
/*std::vector<uchar> p(8);
p[0] = im.at<uchar>(i-1, j);
p[1] = im.at<uchar>(i-1, j+1);
p[2] = im.at<uchar>(i, j+1);
p[3] = im.at<uchar>(i+1, j+1);
p[4] = im.at<uchar>(i+1, j);
p[5] = im.at<uchar>(i+1, j-1);
p[6] = im.at<uchar>(i, j-1);
p[7] = im.at<uchar>(i-1, j-1);
p[7] = im.at<uchar>(i-1, j-1);*/
uchar p2 = im.at<uchar>(i-1, j);
uchar p3 = im.at<uchar>(i-1, j+1);
uchar p4 = im.at<uchar>(i, j+1);
uchar p5 = im.at<uchar>(i+1, j+1);
uchar p6 = im.at<uchar>(i+1, j);
uchar p7 = im.at<uchar>(i+1, j-1);
uchar p8 = im.at<uchar>(i, j-1);
uchar p9 = im.at<uchar>(i-1, j-1);

uchar hash = createByte(p);
/*uchar hash = createByte(p);*/
uchar hash = p2 * 1 +
p3 * 2 +
p4 * 4 +
p5 * 8 +
p6 * 16 +
p7 * 32 +
p8 * 64 +
p9 * 128;
marker.at<uchar>(i,j) = table[iter][hash];

//if (table[iter][hash] == 0)
//{
// /*int C = (!p2 & (p3 | p4)) + (!p4 & (p5 | p6)) +
// (!p6 & (p7 | p8)) + (!p8 & (p9 | p2));
//int N1 = (p9 | p2) + (p3 | p4) + (p5 | p6) + (p7 | p8);
//int N2 = (p2 | p3) + (p4 | p5) + (p6 | p7) + (p8 | p9);
//int N = N1 < N2 ? N1 : N2;
//int m = iter == 0 ? ((p6 | p7 | !p9) & p8) : ((p2 | p3 | !p5) & p4);*/

// int C = (!p[0] & (p[1] | p[2])) + (!p[2] & (p[3] | p[4])) +
// (!p[4] & (p[5] | p[6])) + (!p[6] & (p[7] | p[0]));
// int N1 = (p[7] | p[0]) + (p[1] | p[2]) + (p[3] | p[4]) + (p[5] | p[6]);
// int N2 = (p[0] | p[1]) + (p[2] | p[3]) + (p[4] | p[5]) + (p[6] | p[7]);
// int N = N1 < N2 ? N1 : N2;
// int m = iter == 0 ? ((p[4] | p[5] | !p[7]) & p[6]) : ((p[0] | p[1] | !p[3]) & p[2]);

// if (C == 1 && (N >= 2 && N <= 3) & (m == 0))
// {
// marker.at<uchar>(i,j) = 1;
// table[iter][hash] = 2;
// }
// else
// {
// table[iter][hash] = 1;
// }

//}
//else
//if (table[iter][hash] == 2) marker.at<uchar>(i,j) = 1;


}

}