; Apply low pass filter to set of particle image stacks
 ;
 ; PURPOSE: Apply low pass filter to set of particle image stacks.
 ;
 ; SOURCE:  spider/docs/techs/recon1/Procs/denoise-imgs.spi    
  ;
 ; USAGE:   clean ; spider spi/dat @denoise-imgs
 ;
 ;  ------------ Parameters ----------------------------------------

 [filter-type] = 7       ; Filter type: Butterworth low-pass
                         ; Reasonable ranges for Butterworth parameters:
                         ;   (0.05,0.3) for high defocus;  (0.02,0.15) for low defocus
 [par1] = 0.05           ; Filter parameter 1 = passband for Butterworth, 
                         ;    filter radius for all others)
 [par2] = 0.3            ; Filter parameter 2 = stopband for Butterworth, 
                         ;    temperature for Fermi, ignored for all others)

 ; ----------- Input files --------------

 [sel_micrograph] = '../sel_micrograph'         ; Micrograph selection file        (one)

 [ser]            = 'win/data_bymic_****'       ; Unfiltered particle image stacks (one/micrograph)

 ; ----------- Output files --------------

 [filtdir]        = 'filt'                      ; Directory for filtered output images

 [out]            = '[filtdir]/data_bymic_****' ; Filtered particle image stacks   (one/micrograph)

 ; -------------- END BATCH HEADER -------------

 MD                                ; Use all available processors
   SET MP
   0 
 MD                                ; Skip unnecessary output 
   VB OFF

 SYS                               ; Make directory for output
   mkdir -p [filtdir]

 SYS
   echo '  'Applying Low pass filter to images from micrograph stacks ; echo  

 DO                                ; Loop over all micrographs ----------------

   UD NEXT [key],[mic]             ; Get the micrograph number
     [sel_micrograph]              ; Micrograph selection file (input)
   IF ( [key] <= 0 ) EXIT

   FI H [maxim]                    ; Get number of particles in micrograph
     [ser]@[mic]                   ; Raw images stack               (input)
     MAXIM                         ; Header location for # of images in file 

   DO [part] = 1,[maxim]           ; Loop over all particle numbers -----------

      IF ( [filter-type] >= 5 ) THEN
         FQ
           [ser]@******[mic][part] ; Raw images file              (input)
           [out]@******[mic][part] ; Filtered images file         (output)
           [filter-type]           ; Filter type = Butterworth, Fermi
           [par1],[par2]           ; Passband, stopband

      ELSE 
         FQ
           [ser]@******[mic][part] ; Raw images file              (input)
           [out]@******[mic][part] ; Filtered images file         (output)
           [filter-type]           ; Filter type = top hat, Gaussian
           [par1]                  ; Filter radius
      ENDIF
   ENDDO                           ; End Loop over all particle numbers --------

   SYS
     echo '  'Filtered: {%I6%[maxim]} images from micrograph: {%I4%[mic]} 

 ENDDO                             ; End loop over all micrographs -------------

 UD NEXT END                       ; End doc file use
   [sel_micrograph]

 SYS
   echo  

 EN

 ;