Hi Sander,
target->Pixel( col, row, 2 ) = img.Pixel( s_col, s_row );
That only works if *target and img are instances of the same template instantiation (i.e., they share the same PixelTraits, or P template argument).
In your case, target is a pointer to pcl::Image, but img can be an instance of any image type (and anyway, it isn't likely to be pcl::Image), so P::FromSample is mandatory.
Right, so now the problem is that PI loads images differently than other software.
This is the default behavior. It can be changed via Format Explorer > FITS > Preferences > Miscellaneous Options > Coordinate Origin.
Juan will say PI does it correctly and others do it wrong
Of course not. No orientation is more correct than any other since the FITS standard says nothing (once more) about it. Since PI is being used in professional/academic contexts, and most professional telescopes generate FITS images using the lower-left coordinate origin, we decided to follow it by default. When necessary, it's easy to apply a vertical mirror to a set of images, and we provide a way to change the default FITS orientation, as I've explained above.
Now the actual problem is that your module has no way to know if FITS files are being loaded with a particular orientation. To be sincere, this is the first time I have to face this problem. And it is indeed a problem
As you probably know, I really don't like the FITS format. It is supposed to be a "flexible" format, but flexibility, as I understand it, doesn't consist of "absence of rules". The FITS format is something that we have inherited from the magnetic tape times. The problem is that FITS is *still* a good format for magnetic tapes. We definitely need something more contemporary. To make things worse, many CCD makers have decided to use FITS to store their raw data in proprietary formats, (ab)using nonstandard keywords and extensions to store hardware-dependent data into an abstract image transport system. The result is a big mess.
Well, enough digression for this morning, so let's return to the real problem. We need a way to let a module learn the default orientation of FITS images. Right now this is impossible. The solution that I've figured out is to add the following static member functions (see pcl/GlobalSettings.h):
bool PixInsightSettings::DefineGlobalVariable( const IsoString& globalId, PixInsightSettings::variable_type type, bool permanent = false );
bool PixInsightSettings::UndefineGlobalVariable( const IsoString& globalId )
{
return DefineGlobalVariable( globalId, GlobalVariableType::Undefined );
}
In this way a module will be able to create and delete global variables. Right now a module can only read global variables, but can't generate and manage new ones. Note that this functionality requires changes to the low-level C API used for communication between the core application and modules, and significant changes also to internal core routines. Of course, only the module that created a global variable can redefine (or undefine) it.
With this new functionality, the FITS module will define a permanent global variable, namely:
/FileFormats/FITS/CoordinateOrigin
whose type will be GlobalVariableType::String, with possible values "bottom-left" and "top-left". A module will then be able to use PixInsightSettings to retrieve the current value of this global variable. All this will be possible in version 1.5. Right now, you have to hope that the user has set the top-left orientation manually via preferences.
What do you think? I'm open to hear other ideas or potential pitfalls associated to these new functions.