Skip to content

Commit c42beb4

Browse files
committed
Merge pull request #1144 from olivierpascal:olivierpascal-structured-edge-detection
2 parents da29f71 + ab48ffd commit c42beb4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

modules/ximgproc/src/structured_edge_detection.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ static void gradientHist(const cv::Mat &src, cv::Mat &magnitude, cv::Mat &histog
235235
magnitude /= imsmooth( magnitude, gnrmRad )
236236
+ 0.01*cv::Mat::ones( magnitude.size(), magnitude.type() );
237237

238-
int pHistSize = histogram.cols*histogram.channels() - 1;
239238
for (int i = 0; i < phase.rows; ++i)
240239
{
241240
const float *pPhase = phase.ptr<float>(i);
@@ -245,8 +244,12 @@ static void gradientHist(const cv::Mat &src, cv::Mat &magnitude, cv::Mat &histog
245244

246245
for (int j = 0; j < phase.cols; ++j)
247246
{
248-
int index = cvRound((j/pSize + pPhase[j])*nBins);
249-
index = std::max(0, std::min(index, pHistSize));
247+
int angle = cvRound(pPhase[j]*nBins);
248+
if(angle >= nBins)
249+
{
250+
angle = 0;
251+
}
252+
const int index = (j/pSize)*nBins + angle;
250253
pHist[index] += pMagn[j] / CV_SQR(pSize);
251254
}
252255
}

0 commit comments

Comments
 (0)