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

Loading…
Cancel
Save