# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# filename: REMARKS                                                       #
#                                                                         #
# UTILITY text: Medical Image Conversion Utility                          #
#                                                                         #
# purpose     : most important remarks on the code                        #
#                                                                         #
# project     : (X)MedCon by Erik Nolf                                    #
#                                                                         #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# $Id: REMARKS,v 1.11 2007/09/16 20:44:24 enlf Exp $

GENERAL:
=======

- Hey, wake up! As we would say, "to convert IS to delete"

           !! ALWAYS PRESERVE YOUR ORIGINAL DATA !!

- "Floating exception (core dumped)" with use of (X)MedCon library

   This can occur on DEC Alpha systems ...

       1) You can simply prevent this by adding the following functions
          to your main code: (see also './source/medcon.c')
  ...
MdcIgnoreSIGFPE()   /* ignore signal Floating exception */
  ...
MdcAcceptSIGFPE()   /* accept signal Floating exception */
  ...

       2) Possible reasons:

          On a DEC Alpha, floating exceptions are not handled by default,
          which is just great ... but unwanted in the following cases:

           1) Perhaps you read a raw image with type float,
              but didn't swap the bytes (= wrong endian choice).
 
           2) The headers/images contain bad float values.


- pixel types:  Int8,  Int16,  Int32,  Int64
               Uint8, Uint16, Uint32, Uint64, 
               float, double

    Most pixel types will be read, internally we want the types:

       1) 1-BIT  converted to 'Uint8'
       2) ASCII  converted to 'double'
       3) VAX    converted to   IEEE

    Quantifications/Calibrations only use the 'float' type! 
    Therefore, 'double' values must be downscalable to 'float', 
    otherwise the integrity of the data can not be guaranteed!

- patient/slice orientations: 

   a) Only orthogonal values are supported.
   b) (X)MedCon allows a simple form of reslicing along columns or rows.
   
- automatic filename creation:

   The filenames are created automatically with the following sequence:

    m000-...m999-,mA00-...mAZZ-,mB00-...mZZZ-

   So a directory listing "ls" will alphabetically show the files in sequence
   as created. After the sequence, filenames could overlap. (X)MedCon however
   will *not* overwrite any existing file.

- NEGATIVE = ZERO: potential danger reading (RAW) images with negative pixels

     By "default", (X)MedCon works in its most simplest setting, without support
     for contrast remapping, quantitation nor negatives. In this mode any 
     "negative" values are put to "zero". An image that seems to have lost a
     lot of pixel information, can mostly be brought back to the elimination
     of negative pixel values!

     1) supported images
        ----------------

       The program can not see whether negative pixel values are important.
       This is for the user to figure out. To preserve negative pixels, please
       use the following settings.

           command-line: use the '-n' option

              graphical: select in Options|MedCon => positives & negatives

     You are free to change the default behaviour of the program
     from the source code ...  (see the file: m-global.c)

     2) interactive reading (RAW images)
        -------------------

       When reading unsupported image matrices, the program will change its 
       default behaviour by:

         - disabling any quantitation (since there is none to be done)

         - enabling  negative pixel values

       Ofcourse, the user will be notified of this change in settings.
       Would this be OK? Or should I still persist on the user to implicitly
       select and allow negative pixel values ... hmmm. A dilemma!
       Now the user won't be confused by missing pixel info but we lost
       a certain degree of freedom ...

- QUANTITATION

   Some formats support quantified values, either stored in floats or through
   integer pixels combined with a float global rescale factor or a float
   slope & intercept pair; also referred to as linear (a*x) or affine (a*x+b)
   transformation. For various (un)reasonable motivations, quantitation is not
   supported by default. It must be selected by the user. From version 0.7.0
   quantitation can be combined with negative pixel values.
   To enable quantitation:

	command line: use the option '-qs' or '-qc'
        graphical   : see Options||MedCon||Pixels||Values

   1. affine transformation (generic = a*x+b)
      ---------------------

        /* general code for "affine" rescale to new pixeltype */
        {
          scale = max_new_pixeltype / (max_image_value - min_image_value);
          new_image_value = scale * (original_image_value - min_image_value);
        }
        /* 'max_image_value' and/or 'min_image_value' could be negative! */

   In case of negative minimal values however, the above requires a format that
   supports the slope and intercept concept in order to preserve the quantified
   float values where:

        (a) slope = 1/scale;    (b) intercept = min_image_value;

   Until now, only DICOM supports this affine transformation, therefore we
   give preference to the linear version.

   2. linear transformation (specific = a*x)
      ---------------------

   The linear transformation is possible whenever the minimal negative value
   can be transformed within the negative pixel range, using the same scale
   factor as for the positive pixel range.  In other words, the condition
   for linear transformation support is:

        scale * min_image_value  >=   min_new_pixeltype

   That way, the linear transform can be as simple as:

        /* general code for "linear" rescale to new pixeltype */
        {
          scale = max_new_pixeltype / max_image_value;
          new_image_value = scale * original_image_value;
        }

                            *************

FORMATS:
=======

ECAT6: We check the format on the value of 'mh.system_type==ECAT_SYST_TYPE'. 

      Change the value of ECAT_SYST_TYPE to your approriate system type in
      the source code (see the file: m-ecat64.h).

      For (X)MedCon however, if DICOM is unsupported, we automatically try 
      to read as ECAT when the format was not found or you can use the
      option '-fb-ecat' to select ECAT as the fallback read format.

      The patient/slice orientation (see Acr/Nema) is always considered as
      MDC_SUPINE_HEADFIRST_TRANSAXIAL ...

                            *************

DICOM: We check the format on the presence of the signature "DICM"

      (X)MedCon will automatically try to read as DICOM in case the format
      was not found. So DICOM files without MetaHeader can be read as such.

      Writing is only supported for reconstructed NM modality and Int16 pixels.

      For display with contrast remap (window center/width and rescale
      slope/intercept) you should select the '-contrast' option. (CT,MR)

      For quantitation (with rescale slope/intercept) you should select
      the quantification or calibration option '-qs' or '-qc'. (NM,PT)

                            *************
      
GIF:  We found one image that didn't compress well with the original code.
      See "eNlf: BUG??" notes in the code.
      Our workaround of (byte_offset >= 253) could perhaps fail on other
      images!

                            *************

Acr/Nema: 
      We do attempt to preserve some extra (DICOM) tags in our Acr/Nema files 
      concerning the patient/slice orientation and position.

                            *************

InterFile: 
      We try to preserve the patient/slice orientation and position.
      But the format misses some specifications for slice thickness
        - Tomographic   : all voxel dimensions defineable
        - Static/Dynamic: loses slice thickness (no format specification)

                            *************

Analyze: 
      We would like to preserve the patient/slice orientation and position, 
      however, the SPM software doesn't seem to interpret the value of 
      'orient' (patient orientation)! For our main format ECAT this was 
      no problem, except that we had to change the direction of all axis with
      the use of options '-fv -fh -rs'.

      Another problem are the "flipped" versions of 'orient': we don't know
      what the meaning of "flipped" is (feet first instead of head first, or
      prone instead of supine, or vice versa ...) so we ignore this and 
      always consider the patient orientation as MDC_SUPINE_HEADFIRST_ ...

      Filenames are no longer truncated to 18 chars for filling up the 
      db_name[18] entry in the header. If you need this, uncomment the 
      line with ANLZ_SHORT_FILENAME (see the file: m-anlz.h)

      With quantitation support, the default pixel value will be floats. The
      SPM-like version can be enabled with the '-spm' option. In this case,
      quantitation will be supported by the global scale factor in combination
      with integer pixel values. If however quantitation failed because an
      affine transform with slope/intercept was required, just leave out the
      option so (X)MedCon will write with normal float values.

                            *************

NIfTI: (NIFTI)
     The package now contains an integrated version of the C library, as 
     found on the following site:

         <http://niftilib.sourceforge.net>

     For using your own library version, you must compile/install it first.
     Afterwards, you can compile (X)MedCon with NIfTI support enabled by
     performing a proper configure, before the actual make process:

         $> ./configure --enable-nifti --with-nifti-prefix=/usr/local

     Quantitation should be preserved; patient orientation is currently lost
     as we only write Analyze like .nii files.

                            *************

ECAT7: writing
     First you must compile the libraries "libtpcmisc" and "libtpcimgio" from
     the Turku PET Centre (TPC):

	<http://www.turkupetcentre.net>

     Afterwards, you can compile (X)MedCon with ECAT7 writing enabled, by
     simply issuing the related configure options:

	$> ./configure --enable-tpc --with-tpc-prefix=/dir/with/tpc

     Make sure the prefix directory contains two subdirs, "include" and "lib"
     with copied header files (.h) and static libraries (.a)  respectively.

                           *************
 
