UFO_bad_pixel_mask_processor.py

This code processes ...M.bmp mask (M) files generated by UFO Capture.
Scintillating pixels present in all M files in a given directory are
    identified. Those pixels are most probably bad pixels.
A mask file named 'bad_pixel_mask.bmp' is created from these pixels and will be
    saved in the given directory.
If requested, an ...N.bmp (N) file is created from each M file in
    the given directory using 'bad_pixel_mask.bmp' file in the given directory.
    N files are used by UFO Analyzer. With bad pixels masked out, fitting of
    the star map to detected scintillating objects is easier.
All actions will be logged in the given directory in a file named
    'logfile_UFO_bad_pixel_mask_processor.txt'.

Usage: the code is interactive. Just run this module in your favourite python
       interpreter and answer the questions.
       If python is integrated in your system, you can run this module from a
       consol/command window simply by typing 'UFO_bad_pixel_mask_processor.py'

       The program will ask for the full path of a directory it will use.
       If a 'bad_pixel_mask.bmp' file is to be created, the directory must
       contain at least 2 M files.

Note: This code has been written and tested under python 2.7.6
      This code was built using the datetime and pillow (2.4.0) packages

Runtime environment:

This program was written using WinPython-32bit-2.7.6.4. This distribution
runs under Windows XP and above. The latest Windows distribution it was tested
on was Windows 7. WinPython-32bit-2.7.6.4 contains all necessary components to
run this code. If you want to integrate python from this distribution in your
system, run 'WinPython Control Panel.exe' after installation, and select the
menu item 'Advanced'=> 'Register distribution...'

Concept:

Stars are registered as scintillating objects in ...M.bmp mask files saved by
UFO Capture for each record. The position of stars changes over time. If a
pixel is registered as scintillating in all records taken at different time, it
is most probably a pixel does not mark a star. The presence of such pixels is
annoying when the direction of the camera is to be determined by star map
matching in the UFO analyzer programme.
bad_pixel_mask.bmp: a black and white image with unwanted (bad) pixels in
    white. If a pixel was identified as 'bad', its surrounding pixels are also
    marked as 'bad'. The size of the image matches the size of the M files
    it was deduced from.

Information in M files:

In M files, the information is coded in the color channels.
Note that the 2 pixel wide frame of the image is treated differently.
If red value is nonzero, the pixel is one of the record-triggering pixels
If blue value is 0, it is a general background pixel (opt-mask).
If blue value is 2 (or 1 in the frame), the pixel is masked (area-mask).
If blue value is 250 (or 249 in the frame), the pixel is scintillating
    but it is also masked (area-mask + scl-mask).
If blue value is 248, the pixel is scintillating, not masked (scl-mask).

Creation of N file from an M file:

- around red pixels (+-10 pixel range in both x and y directions):
    - if blue value < 128 => not changed
    - if blue value > 128 => 8 is subtracted from blue value to add area-mask
- outside the square region of red pixels:
    - if blue value < 128 => 4 is added to blue value
    - if blue value > 128 => 4 is subtracted from blue value to add area-mask
- +1 is added to the blue value in the frame

Tested on UFO Capture versions 2.22, 2.24

Send feedback to the developer: Karolina Szabn Andr (Szabone.Andre.Karolina@csfk.mta.hu)
