Skip to content

Commit

Permalink
PERF: Only compute log(fixedImageMarginalPDFValue once outside loop
Browse files Browse the repository at this point in the history
A dummy value is used in the case where the log computation is not used
and would otherwise be invalid so that the log() can be precomputed
outside the looping structure.
  • Loading branch information
hjmjohnson committed Apr 13, 2020
1 parent 982cfae commit e7ef06e
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,24 @@ MattesMutualInformationImageToImageMetricv4<TFixedImage,
{
const PDFValueType fixedImageMarginalPDFValue = l_FixedImageMarginalPDF[fixedIndex];

// const bool isNotNearZerofixedImageMarginalPDFValue = (fixedImageMarginalPDFValue > closeToZero);
// if (isNotNearZerofixedImageMarginalPDFValue)
const bool isNotNearZerofixedImageMarginalPDFValue = (fixedImageMarginalPDFValue > closeToZero);
// NOTE: if isNotNearZerofixedImageMarginalPDFValue is false, logfixedImageMarginalPDFValue is never used
// The common case is that it is used, so only perform std::log(fixedImageMarginalPDFValue one time
const PDFValueType logfixedImageMarginalPDFValue = (isNotNearZerofixedImageMarginalPDFValue)
? std::log(fixedImageMarginalPDFValue)
: std::numeric_limits<PDFValueType>::max();
{
for (unsigned int movingIndex = 0; movingIndex < temp_num_histogram_bins;
++movingIndex, ++jointPDFPtr /* GOTO NEXT BIN */)
{
const PDFValueType movingImageMarginalPDF = this->m_MovingImageMarginalPDF[movingIndex];
const PDFValueType jointPDFValue = *(jointPDFPtr);
// check for non-zero bin contribution
if (jointPDFValue > closeToZero && movingImageMarginalPDF > closeToZero)
const PDFValueType & movingImageMarginalPDF = this->m_MovingImageMarginalPDF[movingIndex];
const PDFValueType & jointPDFValue = *(jointPDFPtr);
// check for non-zero bin contribution, if movingImageMarginalPDF <= closeToZero, then so is joinPDFValue
if (movingImageMarginalPDF > closeToZero && jointPDFValue > closeToZero)
{
const PDFValueType pRatio = std::log(jointPDFValue / movingImageMarginalPDF);
if (fixedImageMarginalPDFValue > closeToZero)
if (isNotNearZerofixedImageMarginalPDFValue)
{
const PDFValueType logfixedImageMarginalPDFValue = std::log(fixedImageMarginalPDFValue);
sum += jointPDFValue * (pRatio - logfixedImageMarginalPDFValue);
}

Expand Down

0 comments on commit e7ef06e

Please sign in to comment.