Skip to content

Commit c97b165

Browse files
Lee NewbergLeengit
authored andcommitted
BUG: Fix subtle error for dark pixels
Consistently increment pixel intensity prior to computing its logarithm. Clarify comments describing the increment and later decrement. The code takes logarithms of pixel intensity values, with the intent of first incrementing each intensity value to avoid log(0). However, the code failed to do the increment in one place, which gave small intensity errors in the output.
1 parent 452311c commit c97b165

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

include/itkStructurePreservingColorNormalizationFilter.hxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ StructurePreservingColorNormalizationFilter<TImage>::ImageToMatrix(RegionConstIt
274274

275275
SizeValueType numberOfRows = std::min(numberOfPixels, maxNumberOfRows);
276276

277-
// To avoid zeros, every color intensity is incremented.
278277
CalcMatrixType matrixV{ numberOfRows, m_NumberOfColors };
279278
for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter)
280279
{
@@ -284,6 +283,7 @@ StructurePreservingColorNormalizationFilter<TImage>::ImageToMatrix(RegionConstIt
284283
PixelType pixelValue = iter.Get();
285284
for (Eigen::Index color = 0; color < m_NumberOfColors; ++color)
286285
{
286+
// To avoid std::log(0), every color intensity is incremented.
287287
matrixV(numberOfRows, color) = pixelValue[color] + One;
288288
}
289289
}
@@ -575,7 +575,7 @@ StructurePreservingColorNormalizationFilter<TImage>::DistinguishersToColors(Calc
575575
// m_ColorIndexSuppressedByHematoxylin, and the index of the color
576576
// suppressed by eosin is indicated by
577577
// m_ColorIndexSuppressedByEosin.
578-
std::vector<int> suppressedIndex;
578+
std::vector<int> suppressedIndex;
579579
std::vector<CalcRowVectorType> suppressedPixel;
580580
for (int fromRow = 0; fromRow < distinguishers.rows(); ++fromRow)
581581
{
@@ -765,7 +765,8 @@ StructurePreservingColorNormalizationFilter<TImage>::NMFsToImage(const CalcMatri
765765
PixelType pixelValue = inIt.Get();
766766
for (Eigen::Index color = 0; color < m_NumberOfColors; ++color)
767767
{
768-
matrixV(pixelIndex, color) = static_cast<CalcElementType>(pixelValue[color]);
768+
// To avoid std::log(0), every color intensity is incremented.
769+
matrixV(pixelIndex, color) = static_cast<CalcElementType>(pixelValue[color]) + One;
769770
}
770771
}
771772

@@ -800,6 +801,7 @@ StructurePreservingColorNormalizationFilter<TImage>::NMFsToImage(const CalcMatri
800801
}
801802
for (Eigen::Index color = 0; color < m_NumberOfColors; ++color)
802803
{
804+
// Every color intensity is decremented to cancel the increment that was applied prior to std::log.
803805
pixelValue[color] = std::max(std::min(matrixV(pixelIndex, color) - One, upperbound), lowerbound);
804806
}
805807
const PixelType inputPixel = inIt.Get();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e9381960df175c97efc56743dd8d9e81eb71bb079186a3788e746ad11f6b95fbc24f5335a8b76573767358961ab16dcd66b614895abf783d967ec82024f368b7
1+
2a720ed0c8fbe0ee530c88d01de638671fa2380520ec59ccfb2ad126b3c17e5acc5521ce3001604a5c623fcfa14a81e3dad960a5f51be76269d398911e3f8740

0 commit comments

Comments
 (0)