Loading AA images into other software
Posted: 08 Dec 2018, 16:10
As I discovered, there are some AA images which will not load correctly into other image processing software. The problem is due to the BZERO FITS keyword and how the pixel values in the image represent the raw pixels recorded by the camera.
When AA saves an image to disk, it first scans the pixels to see if any are greater than 32767. If so then it will subtract 32768 from all of the pixels and add the FITS keyword BZERO with a value of 32768 to the FITS header. This is because the FITS standard does not support unsigned 16 bit integers (0 - 65535), but instead uses signed 16 bit integers (-32768 to + 32767). For example, a raw pixel value of 40,000 would be saved in the fits file as 7,232. When reading this image the pixel value has BZERO added to it to get back to the raw pixel value: 7,232 + BZERO (32768) = 40,000. Raw pixel values less than 32768 are saved in the image file as negative numbers.
BZERO = 32768.0
Raw Pixel Image Pixel
0 -32768
1000 -31768
32768 0
60000 27,232
Raw pixel = image pixel + BZERO (32768)
BUT, if there are no pixels greater than 32767 in the image then AA does not add the BZERO keyword to the header AND does not rescale the pixel values. In other words, the pixel value in the image file is the same as the raw pixel value from the camera. Technically BZERO = 0 in this case and there is no need to change the pixel values in the image:
BZERO = 0
Raw Pixel Image Pixel
0 0
1000 1000
30000 30000
Raw pixel = image pixel + BZERO (0)
Unfortunately, some other image processing programs assume a 16 bit FITS image have the pixels offset by 32768 which means those programs ALWAYS add 32768 to the image pixel value. The AA image which has not been offset now looks like this in the other program:
BZERO (none in the header)
Image Pixel --> Raw Pixel
0 32768
1000 33768
30000 62768
This will cause all kinds of problems in the other software.
But there is an easy fix in AA:
1. Check the AA image for the keyword BZERO (Edit|FITS Header).
2. If you find the keyword BZERO then the image will load correctly into all other image processing programs.
3. If you do not find BZERO then zoom into the image maximum size and move to the lower left corner of the image.
4. Position the cursor to the far lower left of the image and right click mouse and select Edit pixels.
5. You will now see in dark gray the value of each of the pixels with a black border around pixel 0,0.
6. Using the edit box, change the pixel value to 35000 and click OK.
7. Save the image. AA will now see a value greater than 32767 and will rescale all the pixel values and add the BZERO keyword.
You can now load the image into all other image processing programs.
NOTE: you can also write a script to do this automatically.
It would be better if AA would always add the BZERO keyword and rescale the pixel values, but the above method will solve the problem of using any AA image in all other image processing programs.
When AA saves an image to disk, it first scans the pixels to see if any are greater than 32767. If so then it will subtract 32768 from all of the pixels and add the FITS keyword BZERO with a value of 32768 to the FITS header. This is because the FITS standard does not support unsigned 16 bit integers (0 - 65535), but instead uses signed 16 bit integers (-32768 to + 32767). For example, a raw pixel value of 40,000 would be saved in the fits file as 7,232. When reading this image the pixel value has BZERO added to it to get back to the raw pixel value: 7,232 + BZERO (32768) = 40,000. Raw pixel values less than 32768 are saved in the image file as negative numbers.
BZERO = 32768.0
Raw Pixel Image Pixel
0 -32768
1000 -31768
32768 0
60000 27,232
Raw pixel = image pixel + BZERO (32768)
BUT, if there are no pixels greater than 32767 in the image then AA does not add the BZERO keyword to the header AND does not rescale the pixel values. In other words, the pixel value in the image file is the same as the raw pixel value from the camera. Technically BZERO = 0 in this case and there is no need to change the pixel values in the image:
BZERO = 0
Raw Pixel Image Pixel
0 0
1000 1000
30000 30000
Raw pixel = image pixel + BZERO (0)
Unfortunately, some other image processing programs assume a 16 bit FITS image have the pixels offset by 32768 which means those programs ALWAYS add 32768 to the image pixel value. The AA image which has not been offset now looks like this in the other program:
BZERO (none in the header)
Image Pixel --> Raw Pixel
0 32768
1000 33768
30000 62768
This will cause all kinds of problems in the other software.
But there is an easy fix in AA:
1. Check the AA image for the keyword BZERO (Edit|FITS Header).
2. If you find the keyword BZERO then the image will load correctly into all other image processing programs.
3. If you do not find BZERO then zoom into the image maximum size and move to the lower left corner of the image.
4. Position the cursor to the far lower left of the image and right click mouse and select Edit pixels.
5. You will now see in dark gray the value of each of the pixels with a black border around pixel 0,0.
6. Using the edit box, change the pixel value to 35000 and click OK.
7. Save the image. AA will now see a value greater than 32767 and will rescale all the pixel values and add the BZERO keyword.
You can now load the image into all other image processing programs.
NOTE: you can also write a script to do this automatically.
It would be better if AA would always add the BZERO keyword and rescale the pixel values, but the above method will solve the problem of using any AA image in all other image processing programs.