Hi Georg,
In PCL 1.x, Generic2DImage does not support implicit data sharing. ImageVariant implements a special data sharing mechanism, but it does not support shared images (i.e. images living in the PI Core application). This means that you cannot return an ImageVariant object by value if it transports a shared image. With a local image it should work, though. These limitations don't exist in PCL 2.0.
For now, try this code:
template <class ImageType>
static void extractLuminance( ImageVariant& L, const ImageType& image, bool linear )
{
if ( !L.IsImage() )
L.CreateSharedFloatImage( (image.BitsPerSample() < 32) ? 32 : (image.IsFloatSample() ? image.BitsPerSample() : 64) );
switch ( L.BitsPerSample() )
{
case 32:
std::cout << "image extract lum 32 bits" << std::endl;
image.ExtractLuminance( *static_cast<FImage*>( L.AnyImage() ), linear );
std::cout << "image extract lum 32 bits done" << std::endl;
break;
case 64:
std::cout << "image extract lum 64 bits" << std::endl;
image.ExtractLuminance( *static_cast<DImage*>( L.AnyImage() ), linear );
std::cout << "image extract lum 64 bits done" << std::endl;
break;
default:
throw Error( "Handling of this bitlength not implemented for extractLuminance" );
break;
}
}
By the way, in PCL 2.0 this task is already implemented in GenericImage and ImageVariant. The above code is equivalent to this in PCL 2.0:
ImageVariant L;
if ( linear )
image.GetLuminance( L );
else
image.GetLightness( L );
Note that the ExtractLuminance() member function does not exist in PCL 2.0 (it was a design error). Let me know if this helps.