pro lbisol,movin1,movout

; Procedure to isolate LB grains in a 3-D sunspot movie.
;
;Version 2.1 of UDISOL.PRO - general mask is set individually
;for each frame, trying to outline the actual UC boundary.
;
; Method: Differentiation based on unsharp masking,
;         like in SBV, ApJ 415 (1993), 832
; MOVIN - input movie
; MOVOUT- output movie with isolated UDs
; 27 March 1997, Michal

on_error,1

;*************** PARAMETERS **********************************
; SMO   - unsharp masking smoothing parameter (in pixels)
; THR   - threshold (minimum) value in the differential image
; PETHR - intensity above which the bright BFs are removed
; GMSMO - smoothing parameter to define general mask
; GMTHR - threshold to define general mask
 smo=7 		; 0.625" x 0.625"
 thr=200	; determine visually to remove noisy pixels
 gmsmo=19 	; 0.875" x 0.875" to smooth umbra
 gmthr=8100	; min. intensity in smoothed frame
;*************************************************************

movin=fix(movin1)
smov=size(movin)
if smov(0) ne 3 then message,'Input must be a 3-D array!'
movout=movin*0
area=lonarr(smov(3))

for i=0,smov(3)-1 do begin

   oima=movin(*,*,i)	; original image
   ima=SMOOTH(oima,smo)	; smoothed image (for unsharp masking)
   ima=oima-ima		; differential image (unsharp masking)
   ima=ima gt thr	; thresholding - mask for small BFs
   ima=ima*oima		; masked original image

   msk=SMOOTH(oima,gmsmo) gt gmthr	;Inverse general mask
   ima=ima*msk		; resulting masked image
   movout(0,0,i)=ima	; compose resulting movie

endfor
end