Skip to content

Commit b7ab26a

Browse files
committed
BUG: Avoid appearance of NaN values
This can be cause by 0 confidence values, probably due to large homogeneous (all black) regions. Closes #219.
1 parent 2789c34 commit b7ab26a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

include/itkTileMontage.hxx

+17-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <algorithm>
3232
#include <cassert>
33+
#include <cmath>
3334
#include <iomanip>
3435

3536
namespace itk
@@ -280,11 +281,24 @@ TileMontage<TImageType, TCoordinate>::RegisterPair(TileIndexType fixed, TileInde
280281

281282
m_CandidateConfidences[regLinearIndex] = m_PCM->GetConfidences();
282283
m_TransformCandidates[regLinearIndex].resize(offsets.size());
283-
PointType p0;
284-
p0.Fill(0.0);
285284
for (unsigned i = 0; i < offsets.size(); i++)
286285
{
287-
m_TransformCandidates[regLinearIndex][i] = offsets[i] - p0;
286+
if (m_CandidateConfidences[regLinearIndex][i] == 0)
287+
{
288+
m_CandidateConfidences[regLinearIndex][i] = std::numeric_limits<TCoordinate>::epsilon();
289+
}
290+
291+
for (unsigned d = 0; d < ImageDimension; d++)
292+
{
293+
if (std::isfinite(offsets[i][d]))
294+
{
295+
m_TransformCandidates[regLinearIndex][i][d] = offsets[i][d];
296+
}
297+
else
298+
{
299+
m_TransformCandidates[regLinearIndex][i][d] = 0;
300+
}
301+
}
288302
}
289303
}
290304

0 commit comments

Comments
 (0)