Author Topic: PCL: how do I get the ID of an image?  (Read 5347 times)

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
PCL: how do I get the ID of an image?
« on: 2009 April 27 17:57:31 »
It's a little embarrassing to have to ask this but I can't figure out how to get the ID (name) of an image. I don't think any of the samples provided actually get the name and use it to create a new name. At least I can't find the channel extraction module and related ones. The statistics module uses the ImageList control to get all the images pre-listed.

So if I have:

Generic2DImage<P>& img

how do I get the ID? I looked at the object in the debugger and it's not telling me a whole lot. None of the intellisense methods seem to match either but I'm probably not seeing it anymore.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PCL: how do I get the ID of an image?
« Reply #1 on: 2009 May 08 12:12:10 »
Juan, could you please help me out here? I think it's rather glaring problem with my module that I use a fixed name for the new images.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PCL: how do I get the ID of an image?
« Reply #2 on: 2009 May 08 12:41:22 »
Of course. This snippet is from the ImageRegistration module:

Code: [Select]
ImageWindow StarAlignmentInstance::CreateImageWindow( const View& view, const IsoString& postFix, int bitsPerSample, bool floatSample )
{
   IsoString id = ValidFullId( view.FullId() ) + postFix;
   ImageWindow window( 1, 1, 1, bitsPerSample, floatSample, false, true, id );
   if ( window.IsNull() )
      throw Error( "Unable to create image window: " + id );
   return window;
}

and the ValidFullId routine, which is useful when you want to use previews, is something like:

Code: [Select]
static IsoString ValidFullId( const IsoString& id )
{
   IsoString validId( id );
   validId.ReplaceString( "->", "_" );
   return validId;
}

The following functions:

Code: [Select]
IsoString View::Id() const
IsoString View::FullId() const

provide the identifier and full identifier, respectively, of any view. For a preview, the full identifier is composed of the main view's identifier and the preview's identifier, separated with the "->" sequence. For a main view, FullId() and Id() give the same string. The ValidFullId() routine above transforms a preview full id into a valid view identifier.

The CreateImageWindow() function allows you to create a new image window with the specified bit depth and data type, taking a view's full identifier as the basis to build the id of the newly created window, plus an optional postfix. I use routines like these quite frequently.

Finally, you'll probably wonder what's the trick behind:

Code: [Select]
ImageWindow window( 1, 1, 1, bitsPerSample, floatSample, false, true, id );
This is a special call to ImageWindow's constructor. When the core receives a request to create a 1x1x1 image, it knows that what is being created is actually a placeholder where an actual image will be built later. You can assign any image to window.MainView().Image(), and the core will keep track of the assignment automatically. This technique is useful when you don't know in advance the dimensions and color space of the final image.

Of course, change the above code as necessary. For example, to create a 1024x768 RGB color image:

Code: [Select]
ImageWindow window( 1024, 768, 3, bitsPerSample, floatSample, true, true, id );
Hope this helps
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PCL: how do I get the ID of an image?
« Reply #3 on: 2009 May 08 14:54:48 »
Well yes but I only have an Image, not a View, right?

Quote
So if I have:

Generic2DImage<P>& img

how do I get the ID?

I'll pass the View into the routine that creates the new image.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PCL: how do I get the ID of an image?
« Reply #4 on: 2009 May 08 15:02:36 »
Great, I got it to work. Not sure why I didn't just do this before. Probably because I now have to pass the new id up in several layers of function calls rather than pulling it out of the source image  >:D
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity