2021-10-24 16:46 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000005OTB-libGeneralpublic2015-05-20 09:39
Reporterjulien 
Assigned Togpasero 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
Summary0000005: can not read unsigned char three channels data into otb::Image<unsigned char,2> properly
DescriptionWhen reading an unsigned char three channels data into otb::Image<unsigned char,2> , the output make no sense at all..
Additional InformationThis is not hapenning with otb::Image<double,2>, so there might be a problem with the use of ITK buffer conversion tools, maybe with the precision used to compute the luminance value from the 3 input channels.
TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0000282

aurelien (developer)

The issue is due to itk::ConvertPixelBuffer::ConvertRGBAToGray that converts an otbVectorImage<unsigned char, 2> to an otbImage<unsigned char, 2> using the formula:

((2125.0 * static_cast<double>Chanel_R +
  7154.0 * static_cast<double>Chanel_G +
  0721.0 * static_cast<double>Chanel_B) / 1000.0)
* static_cast<double>Chanel_A

According to the fact that default value for a A chanel pixel is 255 , the resulting value is not reasonably castable into an unsigned char.

This bug will be transmitted to ITK dev team asap.

~0000370

aurelien (developer)

This bug has been fixed by ITK:

http://public.kitware.com/Bug/view.php?id=10917

~0000380

christop (administrator)

We should cherry-pick the fix to include it in OTB, no?

~0000382

aurelien (developer)

OTB does not use ITK IO to read/write png anymore.

~0000383

christop (administrator)

http://itk.org/gitweb?p=ITK.git;a=commit;h=54e364b981f351a3acbbbcaa0eec332a5218b119

the issue look like it is in the itk::ConvertPixelBuffer.

There might be other places where we do the convertion. We might be using it for the GDAL IO as well. Do we have a test for this bug?

~0000474

aurelien (developer)

I was wrong, the bug is still present because the incriminated method is still used to convert pixel buffers.

The bug is indeed located in IO/itkConvertPixelBuffer.txx in the method ConvertRGBAToGray. It is fixed in ITK-4-A2:

template< typename InputPixelType,
          typename OutputPixelType,
          class OutputConvertTraits
          >
void
ConvertPixelBuffer< InputPixelType, OutputPixelType, OutputConvertTraits >
::ConvertRGBAToGray(InputPixelType *inputData,
                    OutputPixelType *outputData, size_t size)
{
  // Weights convert from linear RGB to CIE luminance assuming a
  // modern monitor. See Charles Pontyon's Colour FAQ
  // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html
  // NOTE: The scale factors are converted to whole numbers for
  // precision
  InputPixelType *endInput = inputData + size * 4;
  double maxAlpha(Self::MaxAlpha(*inputData));
  //
  // To be backwards campatible, if the output pixel type
  // isn't a short or char type, don't fix the problem.
  if(sizeof(*outputData) > 2)
    {
    maxAlpha = 1.0;
    }
  while ( inputData != endInput )
    {
    // this is an ugly implementation of the simple equation
    // greval = (.2125 * red + .7154 * green + .0721 * blue) / alpha
    //
    double tempval =
      ((2125.0 * static_cast< double >( * inputData)
        + 7154.0 * static_cast< double >( *( inputData + 1 ))
        + 0721.0 * static_cast< double >( *( inputData + 2 ))) / 10000.0)
      * static_cast< double >(*( inputData + 3))
      / maxAlpha;
    inputData += 4;
    OutputComponentType val = static_cast< OutputComponentType >( tempval );
    OutputConvertTraits::SetNthComponent(0, *outputData++, val);
    }
}

We do not have a test for this bug and it will no longer exist after the switch
to ITK v4.

~0000620

julien (administrator)

We should add a proper test to ensure it is really closed once moving to ITK v4.

~0001161

julien (administrator)

To check when moving to ITK4

~0002830

mickael (administrator)

still there with ITKv4

~0002903

gpasero (administrator)

The problem was actually fixed in itk::ConvertPixelBuffer, but an OTB fork was used instead (otb::ConvertPixelBuffer). I refactored this fork so that it uses ITK class by default, except for ConvertGrayToComplex which is patched.
http://hg.orfeo-toolbox.org/OTB/rev/a6519cea5972
+Notes

-Issue History
Date Modified Username Field Change
2008-09-11 10:41 julien New Issue
2008-09-11 10:41 julien File Added: PngReadWriteBug.tar.gz
2008-09-11 10:43 inglada Assigned To => user3
2008-09-11 10:43 inglada Status new => assigned
2008-09-11 10:55 inglada Description Updated
2008-09-11 10:57 inglada Assigned To user3 => julien
2010-06-11 11:29 aurelien Assigned To julien => aurelien
2010-06-18 17:03 aurelien Note Added: 0000282
2010-12-02 13:17 aurelien Note Added: 0000370
2010-12-02 13:17 aurelien Status assigned => resolved
2010-12-02 13:17 aurelien Resolution open => fixed
2010-12-04 17:48 christop Note Added: 0000380
2010-12-04 17:48 christop Status resolved => feedback
2010-12-04 17:48 christop Resolution fixed => reopened
2010-12-06 09:01 aurelien Note Added: 0000382
2010-12-06 18:00 christop Note Added: 0000383
2011-02-22 11:01 aurelien Note Added: 0000474
2011-04-29 10:43 julien Note Added: 0000620
2011-04-29 10:43 julien Status feedback => assigned
2011-12-16 13:24 julien Note Added: 0001161
2011-12-16 13:24 julien Status assigned => feedback
2015-04-17 14:56 grizonnetm Status feedback => confirmed
2015-04-23 10:44 mickael Note Added: 0002830
2015-05-20 09:13 gpasero Assigned To aurelien => gpasero
2015-05-20 09:13 gpasero Status confirmed => assigned
2015-05-20 09:17 gpasero Note Added: 0002903
2015-05-20 09:17 gpasero Status assigned => resolved
2015-05-20 09:17 gpasero Resolution reopened => fixed
2015-05-20 09:39 julien Status resolved => closed
+Issue History