[Insight-developers] ImageAdaptors and RGB images

Richard Beare richard.beare at gmail.com
Mon Feb 21 19:10:12 EST 2011


Sorry - badly posted question:

Here is a more complete version of the code and the errors (I've only
included errors from the first adaptor):

template <int dim, class pixtype>
void extractProfile(const CmdLineType & CmdLineObj)
{
  typedef typename itk::Image<pixtype, dim> RawImType;
  typedef typename itk::Image<unsigned char, dim> MaskImType;
  typedef typename itk::Image<short, dim> SignedImType;
  typedef itk::RGBPixel<pixtype>   RGBPixelType;
  typedef itk::Image<RGBPixelType, dim>    RGBImageType;

  typename RGBImageType::Pointer raw = readIm<RGBImageType>(CmdLineObj.InputIm);

  // break into red, green and blue components so that we can get rid
  // of the overlays
  typedef typename itk::RedPixelAccessor<RGBPixelType> RedAccessorType;
  typedef typename itk::GreenPixelAccessor<RGBPixelType> GreenAccessorType;
  typedef typename itk::BluePixelAccessor<RGBPixelType> BlueAccessorType;

  typedef typename itk::ImageAdaptor<RGBImageType, RedAccessorType>
RedAdaptorType;
  typedef typename itk::ImageAdaptor<RGBImageType, GreenAccessorType>
GreenAdaptorType;
  typedef typename itk::ImageAdaptor<RGBImageType, BlueAccessorType>
BlueAdaptorType;

  typename RedAdaptorType::Pointer RedAdaptor = RedAdaptorType::New();
  typename GreenAdaptorType::Pointer GreenAdaptor = GreenAdaptorType::New();
  typename BlueAdaptorType::Pointer BlueAdaptor = BlueAdaptorType::New();


  RedAdaptor->SetImage(raw);
  GreenAdaptor->SetImage(raw);
  BlueAdaptor->SetImage(raw);

  // blue - red selects cyan
  // red - blue selects yellow

  itk::Instance< itk::SubtractImageFilter< BlueAdaptorType,
RedAdaptorType, SignedImType> > Difference;
  Difference->SetInput(BlueAdaptor);
  Difference->SetInput2(RedAdaptor);
}

int main(int argc, char * argv[])
{

  const int dim = 2;
  CmdLineType CmdLineObj;
  ParseCmdLine(argc, argv, CmdLineObj);


  extractProfile<dim, unsigned char>(CmdLineObj);

}



[ 50%] Building CXX object CMakeFiles/procDiameter.dir/procDiameter.o
In file included from
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/Common/itkMath.h:29,
                 from
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/Common/itkIndex.h:25,
                 from
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/Common/itkImageRegion.h:26,
                 from
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/IO/itkImageIORegion.h:24,
                 from
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/IO/itkImageIOBase.h:24,
                 from
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/IO/itkImageFileWriter.h:22,
                 from
/home/richardb/Projects/MCRI/cardiacflow/trunk/Ultrasound/ioutils.h:5,
                 from
/home/richardb/Projects/MCRI/cardiacflow/trunk/Ultrasound/procDiameter.cxx:3:
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/Common/itkConceptChecking.h:
In member function ‘void itk::Concept::AdditiveOperators<T1, T2,
T3>::Constraints::constraints() [with T1 = itk::RGBPixel<unsigned
char>, T2 = itk::RGBPixel<unsigned char>, T3 = short int]’:
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/Common/itkConceptChecking.h:317:
  instantiated from
‘itk::Concept::AdditiveOperators<itk::RGBPixel<unsigned char>,
itk::RGBPixel<unsigned char>, short int>’
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/BasicFilters/itkSubtractImageFilter.h:87:
  instantiated from
‘itk::SubtractImageFilter<itk::ImageAdaptor<itk::Image<itk::RGBPixel<unsigned
char>, 2u>, itk::BluePixelAccessor<itk::RGBPixel<unsigned char> > >,
itk::ImageAdaptor<itk::Image<itk::RGBPixel<unsigned char>, 2u>,
itk::RedPixelAccessor<itk::RGBPixel<unsigned char> > >,
itk::Image<short int, 2u> >’
/home/richardb/Projects/MCRI/cardiacflow/trunk/Ultrasound/procDiameter.cxx:30:
  instantiated from
‘itk::Instance<itk::SubtractImageFilter<itk::ImageAdaptor<itk::Image<itk::RGBPixel<unsigned
char>, 2u>, itk::BluePixelAccessor<itk::RGBPixel<unsigned char> > >,
itk::ImageAdaptor<itk::Image<itk::RGBPixel<unsigned char>, 2u>,
itk::RedPixelAccessor<itk::RGBPixel<unsigned char> > >,
itk::Image<short int, 2u> > >’
/home/richardb/Projects/MCRI/cardiacflow/trunk/Ultrasound/procDiameter.cxx:112:
  instantiated from ‘void extractProfile(const CmdLineType&) [with int
dim = 2, pixtype = unsigned char]’
/home/richardb/Projects/MCRI/cardiacflow/trunk/Ultrasound/procDiameter.cxx:125:
  instantiated from here
/usr/local/ITK/ITK-3.20_staticB/include/InsightToolkit/Common/itkConceptChecking.h:299:
error: invalid static_cast from type ‘itk::RGBPixel<unsigned char>’ to
type ‘short int’
On Tue, Feb 22, 2011 at 11:02 AM, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> Hi Richard,
>
> 1) How is the type "pixtype" defined ?
>
> 2) What exactly are the error messages that you get from the concept check ?
>     please post them to the list.
>
>
>  Thanks
>
>
>       Luis
>
>
> -------------------------------
> On Mon, Feb 21, 2011 at 6:08 PM, Richard Beare <richard.beare at gmail.com> wrote:
>> Hi,
>> I'm trying to take a difference between channels of an RGB image. The
>> color accessor functors seem the appropriate way of doing it, but I'm
>> running into problems with concept checks in the subtract filter.
>>
>> Am I making a stupid error with this code? Should I be using an
>> alternative approach?
>>
>> Thanks
>>
>>  typedef typename itk::Image<pixtype, dim> RawImType;
>>  typedef typename itk::Image<unsigned char, dim> MaskImType;
>>  typedef typename itk::Image<short, dim> SignedImType;
>>  typedef itk::RGBPixel<pixtype>   RGBPixelType;
>>  typedef itk::Image<RGBPixelType, dim>    RGBImageType;
>>
>>  typename RGBImageType::Pointer raw = readIm<RGBImageType>(CmdLineObj.InputIm);
>>
>>
>>  typedef typename itk::RedPixelAccessor<RGBPixelType> RedAccessorType;
>>  typedef typename itk::GreenPixelAccessor<RGBPixelType> GreenAccessorType;
>>  typedef typename itk::BluePixelAccessor<RGBPixelType> BlueAccessorType;
>>
>>  typedef typename itk::ImageAdaptor<RGBImageType, RedAccessorType>
>> RedAdaptorType;
>>  typedef typename itk::ImageAdaptor<RGBImageType, GreenAccessorType>
>> GreenAdaptorType;
>>  typedef typename itk::ImageAdaptor<RGBImageType, BlueAccessorType>
>> BlueAdaptorType;
>>
>>  typename RedAdaptorType::Pointer RedAdaptor = RedAdaptorType::New();
>>  typename GreenAdaptorType::Pointer GreenAdaptor = GreenAdaptorType::New();
>>  typename BlueAdaptorType::Pointer BlueAdaptor = BlueAdaptorType::New();
>>
>>
>>  RedAdaptor->SetImage(raw);
>>  GreenAdaptor->SetImage(raw);
>>  BlueAdaptor->SetImage(raw);
>>
>>  // blue - red selects cyan
>>  // red - blue selects yellow
>>
>>  itk::Instance< itk::SubtractImageFilter< BlueAdaptorType,
>> RedAdaptorType, SignedImType> > Difference;
>>  Difference->SetInput(BlueAdaptor);
>>  Difference->SetInput2(RedAdaptor);
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-developers
>>
>


More information about the Insight-developers mailing list