#!/bin/csh

## Script for running descreening.
##================================  
## For 300dpi scans: 
## -----------------
##	1) Use the filters in filters/den_1X to 
##	   denoise '$in_imge' using RS. The O/P
##	   of this stage is 'temp1'
##	2) The denoised image 'temp1' from RS is 
##	   used by the susan filtering algorithm
##         to produce the O/P '$out_img'

## For 600dpi scans:
## -----------------
##	1) Decimate '$in_image' to 'temp0'
##      2) Use the filters in filters/den_2X to 
##	   denoise 'temp0' using RS. The O/P of 
##	   this stage is 'temp1'
##      3) The denoised image 'temp1' from RS is
##         used by the susan filtering algorithm
##         to produce the O/P '$out_img'


##  usage: ./rs_denoise    raw_scanned_image 	\
##         	           denoised_rs_output   \
##               	   filter_file		\
##                     	   delta_factor		\
##                   	   scanner_resolution	\
##                     	   preprocss_flag	\

##  usage: ./susan_smooth  denoised_img \
##                         raw_scan_img \
##                         output_img   \
##                         bt           \ (between 20 and 40)
##                         form_option  \ (2 or 6)
##                         mask_size    \ (mask_size = 3 => filter is 7x7)
##                         sigma        \ (std. deviation for gaussian filter h(m,n))
##                         tone_correction_option (either 0 or 1)
##                                0 => filter in gamma corrected domain
##				  2 => filter in linear domain 
##                                1 => filter in linear domain followed
##				       by tone correction

#  set input and output filenames
set img_dir	= imgs/
set in_img	= $img_dir/low/scan_img
set out_img     = $img_dir/high/descr_img
set scan_res    = 600

# tifftopnm ${in_img}.tif >! ${in_img}
# Processing of 300 dpi scans
if($scan_res == 300) then
        ./source_code/rs_denoise $in_img temp1 filters/den_1X 2.2 300 0 
        ./source_code/susan_smooth temp1 $in_img $out_img  21 2 3 1.6 2
	/bin/rm temp*
# Processing of 600 dpi scans
else if($scan_res == 600) then  
	./source_code/decimate  $in_img temp0 2 1 bilinear 0
	./source_code/rs_denoise temp0 temp1 filters/den_2X 2.2 600 0 
	./source_code/susan_smooth temp1 $in_img $out_img  21 2 3 2.5 2
	/bin/rm temp*
endif
# pnmtotiff ${out_img} >! ${out_img}.tif
# /bin/rm ${in_img} ${out_img}


