Author Topic: Read 32bit fits files from CCDStack  (Read 4632 times)

Offline gottsch

  • Newcomer
  • Posts: 13
Read 32bit fits files from CCDStack
« on: 2012 June 26 22:10:50 »
Hello All,

This issue was shortly discussed here:
http://pixinsight.com/forum/index.php?topic=1194.msg5826#msg5826

+++++++++++++++++++++++++++++++++++
Quote

    I tried using a 32 integer output from CCDStack but they all appear a flat gray with no real image data.
    I have never tried 32 integer from Stack before,  so this may a known issue with it's output.


Yes, this is certainly a known issue. The data are there, and you can use them in PixInsight without problems. Open the Process Explorer window, expand the IntensityTransformations category, then open the Rescale process. Apply Rescale with default parameters to one of these images, then use STF as usual, and voilĂ , everything's there.

The problem is actually quite simple. These are 32-bit integer FITS images. As you know, one of these images can store 232 discrete values (4,294,967,296 different values). However, these files store less than 216=65,536 discrete values (at least this happens in all CCDStack 32-bit integer images that I've seen so far).

But the problem isn't in this fact, actually. The real problem is that the 65536 values have been stored into a contiguous region of the available dynamic range, centered around 232/2 (the middle point of the histogram). Consequently, we have an extremely sharp peak (virtually a Dirac delta) that concentrates less than 65536 values in the middle of a hugely vast numerical range of 4294967296 values. In more understandable figures, this means that only a fraction of 0.000015 of the available dynamic range is being used by these images. Note that 16-bit histograms (which are being used internally by PixInsight) are unable to manage that infinitesimal ratio of dynamic range usage (we would need at least a 24-bit histogram to provide reasonable resolution for these images, but of course we don't want to waste 32 MB of RAM to represent the histogram of a 16-bit image).
+++++++++++++++++++++++++++++++++++

I am not sure this is correct.

I open a 32bit (int) fits from CCDStack in AA4 and stats as well as histogram show data population from 0 to 548880. (makes sense as this is a stack of 10 exposures (16bit) which might have close to saturated pixels. ( 548880 ~ 10 x 64k)

I open the same in PI 1.7 (temp license) and the picture is all gray.  I apply the rescale and surprisingly a 16bit scaled image pops out. (Not what I expected) I think the file import + rescale has done something wrong.

When I check statistics right after opening the image the statistics are limited to 16bit, which doesn't make sense.

Screen shots are here.

http://www.trivalleystargazers.org/gert/download/AA4_opens_32bit_int_from_ccdstack.jpg
http://www.trivalleystargazers.org/gert/download/PI1.7_opens_32bit_int_from_ccdstack.jpg
http://www.trivalleystargazers.org/gert/download/PI1.7_opens_32bit_int_from_ccdstack_no_rescale.jpg

I am trying to come to a decision to pay for PI full license.

Clear Skies,
Gert

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Read 32bit fits files from CCDStack
« Reply #1 on: 2012 June 27 02:44:54 »
Hi Gert,

That forum thread is pretty old (2009?). We now have more flexible options implemented in the FITS format support module.

I guess this is a 32-bit signed integer image storing physical pixel data. In other words, the negative half of the available numeric range, from -1 to -231, is not being used (the negative value at {0,0} looks like a spurious value or a border artifact). Please do the following to open these images correctly in PixInsight (see attached image):

- Open the Format Explorer window.

- Double click the FITS item on the left column.

- On the FITS Format Preferences dialog, enable the "Signed integer images store physical pixel data" option (Miscellaneous Options section).

- You may also want to set "Coordinate origin = Upper left corner" in order to load these FITS images with the correct orientation.

- Click OK.

Now these images will be loaded with the correct range in PixInsight. This means that the data will be loaded and kept with their original values in memory, as a 32-bit unsigned integer image (signed integer images don't exist as objects available to the user in the PixInsight platform).

However, we now have a completely different, much harder problem: we don't know how to interpret these images. In particular, we have no way to know where the white point is located inside the vast space of 2,147,483,648 discrete values (from 0 to 231-1 ; since we know that the original file stored signed integers, we know for sure that the upper half of the unsigned numeric range is not being used). You may think that this can be solved by simply rescaling all existing pixel values to the [0,232-1] range, which is what the Rescale tool does. However, this is just a cosmetic solution to let you see the image, but not a valid general solution to the data interpretation problem. By rescaling the data we are assuming that the minimum and maximum pixel values stored in the original file (and now stored in RAM as an image in PixInsight) are intended to represent the black and white points in the dynamic range of the image. In general, this is not necessarily true, unless the image has some black and saturated valid pixels. So by rescaling the image we take the risk to lose the physical meaning of the original data. This is bad because, among other effects, two or more images loaded under the same conditions are not guaranteed to be mutually comparable. Unfortunately, the FITS format does not provide any standard way to define the bounds of the numerical range to which an image is referred. Only the developers of each application are responsible to publicly define the range of the data they generate in a consistent way.

As for PixInsight, we always follow these rules for every image we generate:

- Pixel samples stored in floating point images (32-bit and 64-bit IEEE 754 formats) are always referred to the [0,1] range, where 0 is black (no signal) and 1 is white (full signal).

- Pixel samples stored in unsigned integer images (8-bit, 16-bit and 32-bit unsigned integer images) are always referred to [0,2n-1], where n is the number of bits used to represent each pixel sample.

- Pixel samples stored in signed integer images (16-bit and 32-bit signed integer images) are always referred to [-2n-1,+2n-1-1], where n is the number of bits used to represent each pixel sample.

For integer images, the bounds of the nominal range always represent, respectively, the black and white points of the image.

Quote
I apply the rescale and surprisingly a 16bit scaled image pops out.

Not at all; the data is stored and managed in RAM as a 32-bit unsigned integer image (unless you convert it to a different format, for example with the SampleFormatConversion tool).

Quote
When I check statistics right after opening the image the statistics are limited to 16bit, which doesn't make sense.

In PixInsight, pixel readouts are virtual. This means that you can read pixel values in any real or integer range of your choice (including arbitrary integer ranges), irrespective of the actual data type used to store and manipulate the image. For example, you can load a 32-bit integer image and read its pixels as 16-bit integers if you want, or load a floating point image and read it in the [0,1000] range, if this is useful for you. The ReadoutOptions tool allows you to manage these settings.

The default readout range is [0,1]. We call it normalized real range, and it is very important and widely used throughout the whole PixInsight platform. It allows us to express and manipulate images in a purely abstract numerical space that is independent on the actual data type of each image. It also has the advantage that we can remap it to any arbitrary range by a simple multiplication with a constant.

The Statistics tool also allows you to acquire statistical data in virtual ranges. It doesn't offer the 32-bit integer range, mainly because we think that working with 32-bit integer numbers is quite confusing (what is the difference between 1,000,300,768 and 1,700,500,123 in terms of brightness?). If you need precision with the Statistics tool, select the normalized real range.

You can also read statistical values very quickly from the console. Select your image and enter this command from the console:

j $min

$min is a predefined macro that shows you the minimum value of the current image in the [0,1] range. If you want to read it as a 32-bit integer number, use this command:

j $min*(Math.pow2(32)-1)

In a similar way, you can use the $max, $mean, $median, $stddev and $avgdev predefined macros.

Hope this helps.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/