bool AnnotationInstance::ExecuteOn( View& view ) { AutoViewLock lock( view ); ImageVariant image = view.Image(); StandardStatus status; image.SetStatusCallback( &status ); Console().EnableAbort(); if ( !image.IsComplexSample() ) if ( image.IsFloatSample() ) switch ( image.BitsPerSample() ) { case 32: AnnotationEngine::Apply( static_cast<pcl::Image&>( *image ), *this ); break; case 64: AnnotationEngine::Apply( static_cast<pcl::DImage&>( *image ), *this ); break; } else switch ( image.BitsPerSample() ) { case 8: AnnotationEngine::Apply( static_cast<pcl::UInt8Image&>( *image ), *this ); break; case 16: AnnotationEngine::Apply( static_cast<pcl::UInt16Image&>( *image ), *this ); break; case 32: AnnotationEngine::Apply( static_cast<pcl::UInt32Image&>( *image ), *this ); break; } return true; }
void NewImageInterface::__SetToActiveImage_Click( Button& /*sender*/, bool /*checked*/ ) { ImageWindow w = ImageWindow::ActiveWindow(); if ( !w.IsNull() ) { ImageVariant v = w.MainView().Image(); AbstractImage* img = v.AnyImage(); if ( img != 0 ) { if ( v.IsFloatSample() ) switch ( v.BitsPerSample() ) { case 32: instance.sampleFormat = NewImageSampleFormat::F32; break; case 64: instance.sampleFormat = NewImageSampleFormat::F64; break; } else switch ( v.BitsPerSample() ) { case 8: instance.sampleFormat = NewImageSampleFormat::I8; break; case 16: instance.sampleFormat = NewImageSampleFormat::I16; break; case 32: instance.sampleFormat = NewImageSampleFormat::I32; break; } instance.colorSpace = img->IsColor() ? NewImageColorSpace::RGB : NewImageColorSpace::Gray; instance.width = img->Width(); instance.height = img->Height(); instance.numberOfChannels = img->NumberOfChannels(); UpdateControls(); } } }
bool PhotometricSuperflatInstance::ExecuteOn( View& view ) { AutoViewLock lock( view ); ImageVariant image = view.Image(); if ( image.IsComplexSample() ) return false; StandardStatus status; image.SetStatusCallback( &status ); Console().EnableAbort(); if ( image.IsFloatSample() ) switch ( image.BitsPerSample() ) { case 32: PhotometricSuperflatEngine::Apply( static_cast<Image&>( *image ), *this ); break; case 64: PhotometricSuperflatEngine::Apply( static_cast<DImage&>( *image ), *this ); break; } else switch ( image.BitsPerSample() ) { case 8: PhotometricSuperflatEngine::Apply( static_cast<UInt8Image&>( *image ), *this ); break; case 16: PhotometricSuperflatEngine::Apply( static_cast<UInt16Image&>( *image ), *this ); break; case 32: PhotometricSuperflatEngine::Apply( static_cast<UInt32Image&>( *image ), *this ); break; } return true; }
static void CombineChannels( GenericImage<P>& img, int colorSpace, const String& baseId, const Rect& r, ImageVariant& src0, ImageVariant& src1, ImageVariant& src2 ) { if ( src0 ) { if ( src0.IsFloatSample() ) switch ( src0.BitsPerSample() ) { case 32: CombineChannels( img, colorSpace, baseId, r, static_cast<Image*>( src0.ImagePtr() ), src1, src2 ); break; case 64: CombineChannels( img, colorSpace, baseId, r, static_cast<DImage*>( src0.ImagePtr() ), src1, src2 ); break; } else switch ( src0.BitsPerSample() ) { case 8: CombineChannels( img, colorSpace, baseId, r, static_cast<UInt8Image*>( src0.ImagePtr() ), src1, src2 ); break; case 16: CombineChannels( img, colorSpace, baseId, r, static_cast<UInt16Image*>( src0.ImagePtr() ), src1, src2 ); break; case 32: CombineChannels( img, colorSpace, baseId, r, static_cast<UInt32Image*>( src0.ImagePtr() ), src1, src2 ); break; } } else CombineChannels( img, colorSpace, baseId, r, static_cast<UInt8Image*>( nullptr ), src1, src2 ); }
bool FluxCalibrationInstance::ExecuteOn( View& view ) { AutoViewLock lock( view ); ImageVariant image = view.Image(); if ( image.IsComplexSample() ) throw Error( "FluxCalibration cannot be executed on complex images." ); StandardStatus status; image->SetStatusCallback( &status ); image->Status().Initialize( "Flux calibration", image->NumberOfPixels() ); Console().EnableAbort(); if ( image.IsFloatSample() ) switch ( image.BitsPerSample() ) { case 32: FluxCalibrationEngine::Apply( static_cast<Image&>( *image ), view, *this ); break; case 64: FluxCalibrationEngine::Apply( static_cast<DImage&>( *image ), view, *this ); break; } else switch ( image.BitsPerSample() ) { case 8: case 16: { ImageVariant tmp; tmp.CreateFloatImage( 32 ); tmp.CopyImage( image ); FluxCalibrationEngine::Apply( static_cast<Image&>( *tmp ), view, *this ); image.CopyImage( tmp ); } break; case 32: { ImageVariant tmp; tmp.CreateFloatImage( 64 ); tmp.CopyImage( image ); FluxCalibrationEngine::Apply( static_cast<DImage&>( *tmp ), view, *this ); image.CopyImage( tmp ); } break; } return true; }
static void Apply( ImageVariant& image, const CurvesTransformationInstance& instance, bool useLUT = false ) { if ( image.IsFloatSample() ) switch ( image.BitsPerSample() ) { case 32 : Apply( static_cast<Image&>( *image ), instance, useLUT ); break; case 64 : Apply( static_cast<DImage&>( *image ), instance, useLUT ); break; } else switch ( image.BitsPerSample() ) { case 8 : Apply( static_cast<UInt8Image&>( *image ), instance, useLUT ); break; case 16 : Apply( static_cast<UInt16Image&>( *image ), instance, useLUT ); break; case 32 : Apply( static_cast<UInt32Image&>( *image ), instance, useLUT ); break; } }
StarDetector::StarDetector( const ImageVariant& image, int channel, const DPoint& pos, int radius, float threshold, bool autoAperture ) { star.status = NotDetected; star.channel = channel; star.rect = pos; star.pos = pos; if ( image ) { image->SelectChannel( channel ); if ( image.IsFloatSample() ) switch ( image.BitsPerSample() ) { case 32: star.status = Detect( star.pos, radius, threshold, static_cast<const Image&>( *image ) ); break; case 64: star.status = Detect( star.pos, radius, threshold, static_cast<const DImage&>( *image ) ); break; } else switch ( image.BitsPerSample() ) { case 8: star.status = Detect( star.pos, radius, threshold, static_cast<const UInt8Image&>( *image ) ); break; case 16: star.status = Detect( star.pos, radius, threshold, static_cast<const UInt16Image&>( *image ) ); break; case 32: star.status = Detect( star.pos, radius, threshold, static_cast<const UInt32Image&>( *image ) ); break; } star.rect = DRect( star.pos - double( radius ), star.pos + double( radius ) ); if ( autoAperture && star ) { Rect r = star.rect.RoundedToInt(); for ( double m0 = 1; ; ) { image->SelectRectangle( r ); double m = Matrix::FromImage( image ).Median(); if ( m0 < m || (m0 - m)/m0 < 0.01 ) break; m0 = m; r.InflateBy( 1, 1 ); } star.rect = r; } } }
static void Convolve( const ImageVariant& v1, ImageVariant& v2, pcl_enum interpolation, float radiusD, float angleD, DPoint center, int c ) { if ( v1.IsFloatSample() ) switch ( v1.BitsPerSample() ) { case 32 : Convolve_1( static_cast<const Image&>( *v1 ), v2, interpolation, radiusD, angleD, center, c ); break; case 64 : Convolve_1( static_cast<const DImage&>( *v1 ), v2, interpolation, radiusD, angleD, center, c ); break; } else switch ( v1.BitsPerSample() ) { case 8 : Convolve_1( static_cast<const UInt8Image&>( *v1 ), v2, interpolation, radiusD, angleD, center, c ); break; case 16 : Convolve_1( static_cast<const UInt16Image&>( *v1 ), v2, interpolation, radiusD, angleD, center, c ); break; case 32 : Convolve_1( static_cast<const UInt32Image&>( *v1 ), v2, interpolation, radiusD, angleD, center, c ); break; } }
static void ApplyFilter( ImageVariant& v1, const ImageVariant& v2, float amount, float threshold, float deringing, float rangeLow, float rangeHigh, pcl_bool disableExtension, int c, pcl_bool highPass ) { if ( v1.IsFloatSample() ) switch ( v1.BitsPerSample() ) { case 32 : ApplyFilter_1( static_cast<Image&>( *v1 ), v2, amount, threshold, deringing, rangeLow, rangeHigh, disableExtension, c, highPass ); break; case 64 : ApplyFilter_1( static_cast<DImage&>( *v1 ), v2, amount, threshold, deringing, rangeLow, rangeHigh, disableExtension, c, highPass ); break; } else switch ( v1.BitsPerSample() ) { case 8 : ApplyFilter_1( static_cast<UInt8Image&>( *v1 ), v2, amount, threshold, deringing, rangeLow, rangeHigh, false, c, highPass ); break; case 16 : ApplyFilter_1( static_cast<UInt16Image&>( *v1 ), v2, amount, threshold, deringing, rangeLow, rangeHigh, false, c, highPass ); break; case 32 : ApplyFilter_1( static_cast<UInt32Image&>( *v1 ), v2, amount, threshold, deringing, rangeLow, rangeHigh, false, c, highPass ); break; } }
bool ChannelCombinationInstance::ExecuteGlobal() { ImageWindow sourceWindow[ 3 ]; ImageVariant sourceImage[ 3 ]; int numberOfSources = 0; int width = 0, height = 0; bool floatSample = false; int bitsPerSample = 0; for ( int i = 0; i < 3; ++i ) if ( channelEnabled[i] && !channelId[i].IsEmpty() ) { sourceWindow[i] = ImageWindow::WindowById( channelId[i] ); if ( sourceWindow[i].IsNull() ) throw Error( "ChannelCombination: Source image not found: " + channelId[i] ); sourceImage[i] = sourceWindow[i].MainView().Image(); if ( !sourceImage[i] ) throw Error( "ChannelCombination: Invalid source image: " + channelId[i] ); if ( sourceImage[i]->IsColor() ) throw Error( "ChannelCombination: Invalid source color space: " + channelId[i] ); if ( sourceImage[i].IsFloatSample() ) floatSample = true; if ( sourceImage[i].BitsPerSample() > bitsPerSample ) bitsPerSample = sourceImage[i].BitsPerSample(); if ( width == 0 ) { width = sourceImage[i]->Width(); height = sourceImage[i]->Height(); } else { if ( sourceImage[i]->Width() != width || sourceImage[i]->Height() != height ) throw Error( "ChannelCombination: Incompatible source image dimensions: " + channelId[i] ); } ++numberOfSources; } if ( numberOfSources == 0 ) throw Error( "ChannelCombination: No source image(s)." ); ImageWindow w( width, height, 3, bitsPerSample, floatSample, true, true ); if ( w.IsNull() ) throw Error( "ChannelCombination: Unable to create target image." ); View mainView = w.MainView(); AutoViewLock lock( mainView ); try { ImageVariant image = mainView.Image(); Console().EnableAbort(); StandardStatus status; image->SetStatusCallback( &status ); const char* what = ""; switch ( colorSpace ) { case ColorSpaceId::RGB: what = "RGB channels"; break; case ColorSpaceId::CIEXYZ: what = "normalized CIE XYZ components"; break; case ColorSpaceId::CIELab: what = "normalized CIE L*a*b* components"; break; case ColorSpaceId::CIELch: what = "normalized CIE L*c*h* components"; break; case ColorSpaceId::HSV: what = "normalized HSV components"; break; case ColorSpaceId::HSI: what = "normalized HSI components"; break; } image->Status().Initialize( String( "Combining " ) + what, image->NumberOfPixels() ); String baseId = mainView.Id(); Rect r = image->Bounds(); if ( image.IsFloatSample() ) switch ( image.BitsPerSample() ) { case 32: CombineChannels( static_cast<Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 64: CombineChannels( static_cast<DImage&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; } else switch ( image.BitsPerSample() ) { case 8: CombineChannels( static_cast<UInt8Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 16: CombineChannels( static_cast<UInt16Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 32: CombineChannels( static_cast<UInt32Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; } w.Show(); return true; } catch ( ... ) { w.Close(); throw; } }
bool ChannelCombinationInstance::ExecuteOn( View& view ) { ImageWindow sourceWindow[ 3 ]; ImageVariant sourceImage[ 3 ]; AutoViewLock lock( view ); ImageVariant image = view.Image(); if ( image.IsComplexSample() ) throw Error( "ChannelCombination cannot be executed on complex images." ); if ( image->ColorSpace() != ColorSpace::RGB ) throw Error( "ChannelCombination requires a RGB color image." ); Console().EnableAbort(); StandardStatus status; image->SetStatusCallback( &status ); String baseId; Rect r; int w0, h0; if ( view.IsPreview() ) { ImageWindow w = view.Window(); View mainView = w.MainView(); baseId = mainView.Id(); r = w.PreviewRect( view.Id() ); mainView.GetSize( w0, h0 ); } else { baseId = view.Id(); r = image->Bounds(); w0 = r.Width(); h0 = r.Height(); } int numberOfSources = 0; for ( int i = 0; i < 3; ++i ) if ( channelEnabled[i] ) { String id = channelId[i]; if ( id.IsEmpty() ) id = baseId + '_' + ColorSpaceId::ChannelId( colorSpace, i ); sourceWindow[i] = ImageWindow::WindowById( id ); if ( sourceWindow[i].IsNull() ) throw Error( "ChannelCombination: Source image not found: " + id ); sourceImage[i] = sourceWindow[i].MainView().Image(); if ( !sourceImage[i] ) throw Error( "ChannelCombination: Invalid source image: " + id ); if ( sourceImage[i]->IsColor() ) throw Error( "ChannelCombination: Invalid source color space: " + id ); if ( sourceImage[i]->Width() != w0 || sourceImage[i]->Height() != h0 ) throw Error( "ChannelCombination: Incompatible source image dimensions: " + id ); ++numberOfSources; } if ( numberOfSources == 0 ) return false; const char* what = ""; switch ( colorSpace ) { case ColorSpaceId::RGB: what = "RGB channels"; break; case ColorSpaceId::CIEXYZ: what = "normalized CIE XYZ components"; break; case ColorSpaceId::CIELab: what = "normalized CIE L*a*b* components"; break; case ColorSpaceId::CIELch: what = "normalized CIE L*c*h* components"; break; case ColorSpaceId::HSV: what = "normalized HSV components"; break; case ColorSpaceId::HSI: what = "normalized HSI components"; break; } image->Status().Initialize( String( "Combining " ) + what, image->NumberOfPixels() ); if ( image.IsFloatSample() ) switch ( image.BitsPerSample() ) { case 32: CombineChannels( static_cast<Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 64: CombineChannels( static_cast<DImage&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; } else switch ( image.BitsPerSample() ) { case 8: CombineChannels( static_cast<UInt8Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 16: CombineChannels( static_cast<UInt16Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 32: CombineChannels( static_cast<UInt32Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; } return true; }