Skip to content

Commit ad88adf

Browse files
committed
cpp updates
1 parent ddef52b commit ad88adf

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

src/equalizeImageHist.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Rcpp::NumericMatrix equalizeImageHist(Rcpp::NumericMatrix mat) {
1111
int nrow = mat.nrow();
1212
int ncol = mat.ncol();
1313
int min_cdf = 1;
14-
std::pointer_to_unary_function <double,double> roundObject (round) ;
1514

16-
// MULTIPLY BY 255 AND ROUND TO CREATE BINS
17-
std::transform(mat.begin(), mat.end(), mat.begin(), std::bind1st(std::multiplies<double>(), 255));
18-
std::transform(mat.begin(), mat.end(), mat.begin(), roundObject);
15+
// Multiply by 255 and round to create bins
16+
for (i = 0; i < ncol; i++) {
17+
for (j = 0; j < nrow; j++) {
18+
mat(j,i) = std::round(mat(j,i) * 255);
19+
}
20+
}
1921

2022
// COUNT INSTANCES OF EACH PIXEL VALUE (FREQUENCY HISTOGRAM)
2123
for (i = 0; i < ncol; i++) {
@@ -50,7 +52,11 @@ Rcpp::NumericMatrix equalizeImageHist(Rcpp::NumericMatrix mat) {
5052
}
5153

5254
// DIVIDE BY 255 TO RESTORE ORIGINAL 0->1 VALUES
53-
std::transform(mat.begin(), mat.end(), mat.begin(), std::bind1st(std::multiplies<double>(), 0.00392156862));
55+
for (i = 0; i < ncol; i++) {
56+
for (j = 0; j < nrow; j++) {
57+
mat(j,i) = mat(j,i) * 0.00392156862;
58+
}
59+
}
5460

5561
//Rcpp::Rcout << "Print text" << std::endl;
5662

src/findCornerSubPix.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,22 @@ Rcpp::NumericMatrix findCornerSubPix(Rcpp::NumericMatrix image, Rcpp::IntegerMat
5959

6060
// CREATE WINDOW INDICES FOR ITERATING THROUGH SUBMATRIX
6161
for(i = 0; i < win; i++) for(j = 0; j < win; j++) *(wvec.begin()+i+j*win) = i+j*nrow_img;
62-
std::transform(wvec.begin(), wvec.end(), wvec.begin(), std::bind1st(std::plus<int>(), -*(wvec.begin()+((win_win)/2))));
62+
//for(i = 0; i < wvec.size(); i++) Rcpp::Rcout << wvec[i] << std::endl;
63+
64+
// Subtract constant
65+
int sub_cons = *(wvec.begin()+((win_win)/2));
66+
for(i = 0; i < win_win; i++) wvec[i] = wvec[i] - sub_cons;
67+
68+
//for(i = 0; i < wvec.size(); i++) Rcpp::Rcout << wvec[i] << ',';
69+
//Rcpp::Rcout << win_win << std::endl;
70+
//Rcpp::Rcout << wvec.size() << std::endl;
6371

6472
// CREATE KERNEL INDICES FOR ITERATING THROUGH WINDOW
6573
for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) *(kvec.begin()+i+j*3) = i+j*nrow_img;
66-
std::transform(kvec.begin(), kvec.end(), kvec.begin(), std::bind1st(std::plus<int>(), -*(kvec.begin()+4)));
74+
75+
// Subtract constant
76+
sub_cons = *(kvec.begin()+4);
77+
for(i = 0; i < 9; i++) kvec[i] = kvec[i] - sub_cons;
6778

6879
// CREATE X AND Y KERNEL MULTIPLIER VECTORS
6980
for(i=0; i < 3; i++) for(j = 0, k=-1; j < 3; j++, k++) *(kmlt_x.begin()+i+j*3) = k;

src/thresholdImageMatrix.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Rcpp::IntegerMatrix thresholdImageMatrix(Rcpp::NumericMatrix mat, Rcpp::NumericM
1616
std::map<int, int> tab;
1717
int nrow = mat.nrow();
1818
int ncol = mat.ncol();
19-
std::pointer_to_unary_function <double,double> roundObject (round) ;
19+
//std::pointer_to_unary_function <double,double> roundObject (round) ;
2020

2121
// CREATE EMPTY INTEGER MATRIX
2222
Rcpp::IntegerMatrix mat_int(nrow, ncol);
@@ -25,12 +25,19 @@ Rcpp::IntegerMatrix thresholdImageMatrix(Rcpp::NumericMatrix mat, Rcpp::NumericM
2525
// COPY MATRIX
2626
std::copy(mat.begin(), mat.end(), mat_num.begin());
2727

28-
// MULTIPLY BY 255 AND ROUND TO CREATE BINS
29-
std::transform(mat_num.begin(), mat_num.end(), mat_num.begin(), std::bind1st(std::multiplies<double>(), 255));
30-
std::transform(mat_num.begin(), mat_num.end(), mat_num.begin(), roundObject);
28+
// Multiply by 255 and round to create bins
29+
for (i = 0; i < ncol; i++) {
30+
for (j = 0; j < nrow; j++) {
31+
mat_num(j,i) = std::round(mat_num(j,i) * 255);
32+
}
33+
}
3134

32-
std::transform(thresh_mat.begin(), thresh_mat.end(), thresh_mat.begin(), std::bind1st(std::multiplies<double>(), 255));
33-
std::transform(thresh_mat.begin(), thresh_mat.end(), thresh_mat.begin(), roundObject);
35+
// Multiply by 255 and round to create bins
36+
for (i = 0; i < thresh_mat.ncol(); i++) {
37+
for (j = 0; j < thresh_mat.nrow(); j++) {
38+
thresh_mat(j,i) = std::round(thresh_mat(j,i) * 255);
39+
}
40+
}
3441

3542
int idelta = type == 1 ? ceil(delta) : floor(delta);
3643
// Rcpp::Rcout << "idelta: " << idelta << std::endl;

0 commit comments

Comments
 (0)