Пример #1
1
bool ConvertToGrayscaleInstance::ExecuteOn( View& view )
{
   AutoViewLock lock( view );

   ImageVariant image = view.Image();

   StandardStatus status;
   image.SetStatusCallback( &status );

   Console().EnableAbort();

   image.SetColorSpace( ColorSpace::Gray );

   return true;
}
Пример #2
1
bool ConvertToRGBColorInstance::ExecuteOn( View& view )
{
   ImageWindow window = view.Window();
   Array<ImageWindow> windows = ImageWindow::AllWindows();
   for ( size_type i = 0; i < windows.Length(); ++i )
      if ( windows[i].Mask() == window && !windows[i].MainView().IsColor() )
         windows[i].RemoveMask();

   AutoViewLock lock( view );

   ImageVariant image = view.Image();

   StandardStatus status;
   image.SetStatusCallback( &status );

   Console().EnableAbort();

   image.SetColorSpace( ColorSpace::RGB );

   return true;
}
Пример #3
0
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();
      }
   }
}
Пример #4
0
static void CombineChannels( GenericImage<P>& img, int colorSpace, const String& baseId,
                             const Rect& r,
                             const GenericImage<P0>* src0, ImageVariant& src1, ImageVariant& src2 )
{
   if ( src1 )
   {
      if ( src1.IsFloatSample() )
         switch ( src1.BitsPerSample() )
         {
         case 32:
            CombineChannels( img, colorSpace, baseId, r, src0, static_cast<Image*>( src1.ImagePtr() ), src2 );
            break;
         case 64:
            CombineChannels( img, colorSpace, baseId, r, src0, static_cast<DImage*>( src1.ImagePtr() ), src2 );
            break;
         }
      else
         switch ( src1.BitsPerSample() )
         {
         case  8:
            CombineChannels( img, colorSpace, baseId, r, src0, static_cast<UInt8Image*>( src1.ImagePtr() ), src2 );
            break;
         case 16:
            CombineChannels( img, colorSpace, baseId, r, src0, static_cast<UInt16Image*>( src1.ImagePtr() ), src2 );
            break;
         case 32:
            CombineChannels( img, colorSpace, baseId, r, src0, static_cast<UInt32Image*>( src1.ImagePtr() ), src2 );
            break;
         }
   }
   else
      CombineChannels( img, colorSpace, baseId, r, src0, static_cast<UInt8Image*>( nullptr ), src2 );
}
Пример #5
0
 static void Apply( ImageVariant& image, const BinarizeInstance& instance )
 {
    for ( int c = 0; c < image.NumberOfNominalChannels(); ++c )
    {
       image.SelectChannel( c );
       if ( instance.isGlobal )
          image.Binarize( instance.level[0] );
       else
          image.Binarize( instance.level[c] );
    }
 }
Пример #6
0
   static api_bool api_func ValidateProcessImageExecution( const_image_handle hImage, const_process_handle hp, char16_type* whyNot, uint32 maxLen )
   {
      try
      {
         uint32 bitsPerSample;
         api_bool isFloat;
         if ( !(*API->SharedImage->GetImageFormat)( hImage, &bitsPerSample, &isFloat ) )
            throw 0;

         ImageVariant image;
         void* h = const_cast<image_handle>( hImage );
         if ( isFloat )
            switch ( bitsPerSample )
            {
            case 32 :
               image = ImageVariant( new pcl::Image( h ) );
               break;
            case 64 :
               image = ImageVariant( new pcl::DImage( h ) );
               break;
            default :
               return api_false; // ?!
            }
         else
            switch ( bitsPerSample )
            {
            case  8 :
               image = ImageVariant( new UInt8Image( h ) );
               break;
            case 16 :
               image = ImageVariant( new UInt16Image( h ) );
               break;
            case 32 :
               image = ImageVariant( new UInt32Image( h ) );
               break;
            default :
               return api_false; // ?!
            }

         image.SetOwnership( true );

         String whyNotStr;
         bool ok = constInstance->CanExecuteOn( image, whyNotStr );

         if ( !ok && !whyNotStr.IsEmpty() && whyNot != 0 && maxLen > 0 )
               whyNotStr.c_copy( whyNot, maxLen );

         return api_bool( ok );
      }
      ERROR_HANDLER
      return api_false;
   }
Пример #7
0
static void ApplyInverseRealFourierTransform( GenericImage<P>& image, const ImageVariant& dft, bool parallel, int maxProcessors )
{
   if ( !dft || dft->IsEmpty() )
   {
      image.FreeData();
      return;
   }

   switch ( dft.BitsPerSample() )
   {
   case 32: ApplyInverseRealFourierTransform_1( image, static_cast<const FComplexImage&>( *dft ), parallel, maxProcessors ); break;
   case 64: ApplyInverseRealFourierTransform_1( image, static_cast<const DComplexImage&>( *dft ), parallel, maxProcessors ); break;
   }
}
 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;
       }
 }
Пример #9
0
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;
      }
   }
}
Пример #10
0
bool BinarizeInstance::ExecuteOn( View& view )
{
   AutoViewLock lock( view );

   ImageVariant image = view.Image();

   if ( image.IsComplexSample() )
      return false;

   Console().EnableAbort();

   StandardStatus status;
   image.SetStatusCallback( &status );

   BinarizeEngine::Apply( image, *this );

   return true;
}
Пример #11
0
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;
      }
}
Пример #12
0
template <class P> static
void Convolve_1( const GenericImage<P>& image, ImageVariant& v2,
                 pcl_enum interpolation, float radiusD, float angleD, DPoint center, int c )
{
   switch ( v2.BitsPerSample() )
   {
   case 32 : Convolve_2( image, static_cast<Image&>( *v2 ), interpolation, radiusD, angleD, center, c ); break;
   case 64 : Convolve_2( image, static_cast<DImage&>( *v2 ), interpolation, radiusD, angleD, center, c ); break;
   }
}
Пример #13
0
bool ProcessInstance::ExecuteOn( ImageVariant& image, const IsoString& hints )
{
   if ( !image.IsSharedImage() || !image.IsCompletelySelected() )
   {
      ImageVariant tmp;
      tmp.CreateSharedImageAs( image ).AssignImage( image );
      if ( !ExecuteOn( tmp ) )
         return false;
      if ( image.IsCompletelySelected() )
         image.AssignImage( tmp );
      else
         image.Apply( tmp, ImageOp::Mov, image.SelectedRectangle().LeftTop() );
      return true;
   }

   return (*API->Process->ExecuteOnImage)( handle, image.SharedImageHandle(), hints.c_str(), 0/*flags*/ ) != api_false;
}
 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;
 }
Пример #15
0
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;
}
Пример #16
0
template <class P> static
void ApplyFilter_1( GenericImage<P>& image, const ImageVariant& v2,
                    float amount, float threshold, float deringing,
                    float rangeLow, float rangeHigh, pcl_bool disableExtension, int c, pcl_bool highPass )
{
   switch ( v2.BitsPerSample() )
   {
   case 32 : ApplyFilter_2( image, static_cast<const Image&>( *v2 ),
                            amount, threshold, deringing, rangeLow, rangeHigh, disableExtension, c, highPass ); break;
   case 64 : ApplyFilter_2( image, static_cast<const DImage&>( *v2 ),
                            amount, threshold, deringing, rangeLow, rangeHigh, disableExtension, c, highPass ); break;
   }
}
Пример #17
0
bool CropInstance::ExecuteOn( View& view )
{
   if ( !view.IsMainView() )
      return false;  // should not happen!

   if ( p_margins == 0.0 )
   {
      Console().WriteLn( "<end><cbr>&lt;* Identity *&gt;" );
      return true;
   }

   AutoViewLock lock( view );

   ImageWindow window = view.Window();
   ImageVariant image = view.Image();

   Crop C( p_margins );
   C.SetMode( static_cast<Crop::crop_mode>( p_mode ) );
   C.SetResolution( p_resolution.x, p_resolution.y );
   C.SetMetricResolution( p_metric );
   C.SetFillValues( p_fillColor );

   // Dimensions of target image
   int w0 = image.Width();
   int h0 = image.Height();

   // Dimensions of transformed image
   int width = w0, height = h0;
   C.GetNewSizes( width, height );

   if ( width < 1 || height < 1 )
      throw Error( "Crop: Invalid operation: Null target image dimensions" );

   // On 32-bit systems, make sure the resulting image requires less than 4 GB.
   if ( sizeof( void* ) == sizeof( uint32 ) )
   {
      uint64 sz = uint64( width )*uint64( height )*image.NumberOfChannels()*image.BytesPerSample();
      if ( sz > uint64( uint32_max-256 ) )
         throw Error( "Crop: Invalid operation: Target image dimensions would exceed four gigabytes" );
   }

   DeleteAstrometryMetadataAndPreviewsAndMask( window );

   Console().EnableAbort();

   StandardStatus status;
   image.SetStatusCallback( &status );

   C >> image;

   if ( p_forceResolution )
   {
      Console().WriteLn( String().Format( "Setting resolution: h:%.3lf, v:%.3lf, u:px/%s",
                                          p_resolution.x, p_resolution.y, p_metric ? "cm" : "inch" ) );
      window.SetResolution( p_resolution.x, p_resolution.y, p_metric );
   }

   return true;
}
Пример #18
0
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;
      }
}
Пример #19
0
bool RescaleInstance::ExecuteOn( View& view )
{
   AutoViewLock lock( view );

   ImageVariant image = view.Image();

   if ( image.IsComplexSample() )
      return false;

   Console().EnableAbort();

   StandardStatus status;
   image.SetStatusCallback( &status );

   switch ( mode )
   {
   default:
   case RescalingMode::RGBK:
      image->SelectNominalChannels();
      image.Rescale();
      break;
   case RescalingMode::RGBK_Individual:
      for ( int c = 0; c < image->NumberOfNominalChannels(); ++c )
      {
         image->SelectChannel( c );
         image.Rescale();
      }
      break;
   case RescalingMode::CIEL:
      {
         ImageVariant L;
         image.GetLightness( L );
         L.Rescale();
         image.SetLightness( L );
      }
      break;
   case RescalingMode::CIEY:
      {
         ImageVariant Y;
         image.GetLuminance( Y );
         Y.Rescale();
         image.SetLuminance( Y );
      }
      break;
   }

   return true;
}
Пример #20
0
bool ProcessInstance::CanExecuteOn( const ImageVariant& image, String& whyNot ) const
{
   if ( !image.IsSharedImage() || !image.IsCompletelySelected() )
   {
      ImageVariant tmp;
      tmp.CreateSharedImageAs( image ).AssignImage( image );
      return CanExecuteOn( tmp, whyNot );
   }

   image.PushSelections();
   image.ResetSelections();

   ImageInfo info1( *image );

   image.PopSelections();

   whyNot.Clear();
   whyNot.Reserve( WHYNOT_MAXLENGTH );

   bool ok = (*API->Process->ValidateImageExecution)( handle, image.SharedImageHandle(), whyNot.c_str(), WHYNOT_MAXLENGTH ) != api_false;

   image.PushSelections();
   image.ResetSelections();

   ImageInfo info2( *image );

   image.PopSelections();

   if ( info1 != info2 )
      APIHackingAttempt( "ValidateImageExecution" );

   return ok;
}
Пример #21
0
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;
}
Пример #22
0
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;
   }
}
Пример #23
0
bool RotationInstance::ExecuteOn( View& view )
{
   if ( !view.IsMainView() )
      return false;  // should never reach this point!

   AutoViewLock lock( view );

   ImageVariant image = view.Image();

   if ( image.IsComplexSample() )
      return false;

   double degrees = Round( Deg( p_angle ), 4 );
   if ( degrees == 0 )
   {
      Console().WriteLn( "<end><cbr>&lt;* Identity *&gt;" );
      return true;
   }

   ImageWindow window = view.Window();

   window.RemoveMaskReferences();
   window.RemoveMask();
   window.DeletePreviews();

   Console().EnableAbort();

   StandardStatus status;
   image.SetStatusCallback( &status );

   if ( p_optimizeFast )
      switch ( TruncI( degrees ) )
      {
      case 90:
         Rotate90CCW() >> image;
         return true;
      case -90:
         Rotate90CW() >> image;
         return true;
      case 180:
      case -180:
         Rotate180() >> image;
         return true;
      default:
         break;
      }

   AutoPointer<PixelInterpolation> interpolation( NewInterpolation(
         p_interpolation, 1, 1, 1, 1, true, p_clampingThreshold, p_smoothness, image ) );

   Rotation T( *interpolation, p_angle );

   /*
    * On 32-bit systems, make sure the resulting image requires less than 4 GB.
    */
   if ( sizeof( void* ) == sizeof( uint32 ) )
   {
      int width = image.Width(), height = image.Height();
      T.GetNewSizes( width, height );
      uint64 sz = uint64( width )*uint64( height )*image.NumberOfChannels()*image.BytesPerSample();
      if ( sz > uint64( uint32_max-256 ) )
         throw Error( "Rotation: Invalid operation: Target image dimensions would exceed four gigabytes" );
   }

   T.SetFillValues( p_fillColor );
   T >> image;

   return true;
}
Пример #24
0
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;
}
Пример #25
0
   static api_bool api_func ExecuteProcessImage( image_handle hImage, process_handle hp, const char* hints, uint32/*flags*/ )
   {
      try
      {
         uint32 bitsPerSample;
         api_bool isFloat;
         if ( !(*API->SharedImage->GetImageFormat)( hImage, &bitsPerSample, &isFloat ) )
            throw 0;

         ImageVariant image;
         if ( isFloat )
            switch ( bitsPerSample )
            {
            case 32 :
               image = ImageVariant( new pcl::Image( hImage ) );
               break;
            case 64 :
               image = ImageVariant( new pcl::DImage( hImage ) );
               break;
            default :
               return api_false; // ?!
            }
         else
            switch ( bitsPerSample )
            {
            case  8 :
               image = ImageVariant( new UInt8Image( hImage ) );
               break;
            case 16 :
               image = ImageVariant( new UInt16Image( hImage ) );
               break;
            case 32 :
               image = ImageVariant( new UInt32Image( hImage ) );
               break;
            default :
               return api_false; // ?!
            }

         image.SetOwnership( true );

         bool wasConsoleOutput = Exception::IsConsoleOutputEnabled();
         bool wasGUIOutput = Exception::IsGUIOutputEnabled();

         try
         {
            Exception::EnableConsoleOutput();
            Exception::EnableGUIOutput();

            api_bool retVal = (api_bool)instance->ExecuteOn( image, hints );

            Exception::EnableConsoleOutput( wasConsoleOutput );
            Exception::EnableGUIOutput( wasGUIOutput );

            return retVal;
         }
         catch ( ... )
         {
            Exception::EnableConsoleOutput( wasConsoleOutput );
            Exception::EnableGUIOutput( wasGUIOutput );
            throw;
         }
      }
      ERROR_HANDLER
      return api_false;
   }
Пример #26
0
bool LarsonSekaninaInstance::ExecuteOn( View& view )
{
   AutoViewLock lock( view );

   ImageVariant image = view.Image();

   if ( image.IsComplexSample() )
      return false;

   StandardStatus status;
   image.SetStatusCallback( &status );

   Console().EnableAbort();

   ImageVariant sharpImg;
   sharpImg.CreateFloatImage( (image.BitsPerSample() > 32) ? image.BitsPerSample() : 32 );
   sharpImg.AllocateImage( image->Width(), image->Height(), 1, ColorSpace::Gray );

   if ( useLuminance && image->IsColor() )
   {
      ImageVariant L;
      image.GetLightness( L );
      Convolve( L, sharpImg, interpolation, radiusDiff, angleDiff, center, 0 );
      ApplyFilter( L, sharpImg, amount, threshold, deringing, rangeLow, rangeHigh, false, 0, highPass );
      image.SetLightness( L );
   }
   else
   {
      for ( int c = 0, n = image->NumberOfNominalChannels(); c < n; ++c )
      {
         image->SelectChannel( c );
         if ( n > 1 )
            Console().WriteLn( "<end><cbr>Processing channel #" + String( c ) );

         Convolve( image, sharpImg, interpolation, radiusDiff, angleDiff, center, c );
         ApplyFilter( image, sharpImg, amount, threshold, deringing, rangeLow, rangeHigh, disableExtension, c, highPass );
      }
   }

   return true;
}