pull/3847/merge
Dugnom 2 months ago committed by GitHub
commit 6d08e945e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 36
      modules/ximgproc/src/radon_transform.cpp

@ -23,7 +23,7 @@ namespace cv {namespace ximgproc {
_col_num = cvRound((end_angle - start_angle) / theta); _col_num = cvRound((end_angle - start_angle) / theta);
transpose(_srcMat, _srcMat); transpose(_srcMat, _srcMat);
Mat _masked_src; Mat _masked_src;
cv::Point _center; Point2f _center;
if (_srcMat.type() == CV_32FC1 || _srcMat.type() == CV_64FC1) { if (_srcMat.type() == CV_32FC1 || _srcMat.type() == CV_64FC1) {
_out_mat_type = CV_64FC1; _out_mat_type = CV_64FC1;
@ -35,26 +35,26 @@ namespace cv {namespace ximgproc {
if (crop) { if (crop) {
// crop the source into square // crop the source into square
_row_num = min(_srcMat.rows, _srcMat.cols); _row_num = min(_srcMat.rows, _srcMat.cols);
cv::Rect _crop_ROI( Point2f _srcCenter = Point2f(_srcMat.cols / 2.f - 0.5f, _srcMat.rows / 2.f - 0.5f);
_srcMat.cols / 2 - _row_num / 2, Mat _squared_src = Mat(Size(_row_num, _row_num), _srcMat.type(), Scalar(0));
_srcMat.rows / 2 - _row_num / 2, _center = Point2f(_squared_src.cols / 2.f - 0.5f, _squared_src.rows / 2.f - 0.5f);
_row_num, _row_num); Point2f _offset = _center - _srcCenter;
_srcMat = _srcMat(_crop_ROI); Mat _t_matrix = (Mat1f(2, 3) << 1, 0, _offset.x, 0, 1, _offset.y);
warpAffine(_srcMat, _squared_src, _t_matrix, _squared_src.size());
// crop the source into circle // crop the source into circle
Mat _mask(_srcMat.size(), CV_8UC1, Scalar(0)); Mat _mask(_squared_src.size(), CV_8UC1, Scalar(0));
_center = Point(_srcMat.cols / 2, _srcMat.rows / 2); circle(_mask, _center * 2, _srcMat.cols, Scalar(255), FILLED, LINE_8, 1);
circle(_mask, _center, _srcMat.cols / 2, Scalar(255), FILLED); _squared_src.copyTo(_masked_src, _mask);
_srcMat.copyTo(_masked_src, _mask);
} }
else { else {
// avoid cropping corner when rotating // avoid cropping corner when rotating
_row_num = cvCeil(sqrt(_srcMat.rows * _srcMat.rows + _srcMat.cols * _srcMat.cols)); _row_num = cvCeil(sqrt(_srcMat.rows * _srcMat.rows + _srcMat.cols * _srcMat.cols));
_masked_src = Mat(Size(_row_num, _row_num), _srcMat.type(), Scalar(0)); _masked_src = Mat(Size(_row_num, _row_num), _srcMat.type(), Scalar(0));
_center = Point(_masked_src.cols / 2, _masked_src.rows / 2); _center = Point2f(_masked_src.cols / 2.f - 0.5f, _masked_src.rows / 2.f - 0.5f);
_srcMat.copyTo(_masked_src(Rect( Point2f _srcCenter = Point2f(_srcMat.cols / 2.f - 0.5f, _srcMat.rows / 2.f - 0.5f);
(_row_num - _srcMat.cols) / 2, Point2f _offset = _center - _srcCenter;
(_row_num - _srcMat.rows) / 2, Mat _t_matrix = (Mat1f(2, 3) << 1, 0, _offset.x, 0, 1, _offset.y);
_srcMat.cols, _srcMat.rows))); warpAffine(_srcMat, _masked_src, _t_matrix, _masked_src.size());
} }
double _t; double _t;
@ -64,11 +64,11 @@ namespace cv {namespace ximgproc {
for (int _col = 0; _col < _col_num; _col++) { for (int _col = 0; _col < _col_num; _col++) {
// rotate the source by _t // rotate the source by _t
_t = (start_angle + _col * theta); _t = (start_angle + _col * theta);
cv::Mat _r_matrix = cv::getRotationMatrix2D(_center, _t, 1); Mat _r_matrix = getRotationMatrix2D(_center, _t, 1);
cv::warpAffine(_masked_src, _rotated_src, _r_matrix, _masked_src.size()); warpAffine(_masked_src, _rotated_src, _r_matrix, _masked_src.size());
Mat _col_mat = _radon.col(_col); Mat _col_mat = _radon.col(_col);
// make projection // make projection
cv::reduce(_rotated_src, _col_mat, 1, REDUCE_SUM, _out_mat_type); reduce(_rotated_src, _col_mat, 1, REDUCE_SUM, _out_mat_type);
} }
if (norm) { if (norm) {

Loading…
Cancel
Save