test_smooth Program

Uses

  • program~~test_smooth~~UsesGraph program~test_smooth test_smooth data_arch data_arch program~test_smooth->data_arch fftw3 fftw3 program~test_smooth->fftw3 miscellaneous miscellaneous program~test_smooth->miscellaneous module~filter filter program~test_smooth->module~filter surfile surfile program~test_smooth->surfile module~filter->data_arch module~filter->fftw3 module~filter->surfile module~stat_mom stat_mom module~filter->module~stat_mom sort_arrays sort_arrays module~filter->sort_arrays module~stat_mom->data_arch module~stat_mom->sort_arrays

Calls

program~~test_smooth~~CallsGraph program~test_smooth test_smooth end_fftw3 end_fftw3 program~test_smooth->end_fftw3 extend extend program~test_smooth->extend fftw_plan_with_nthreads fftw_plan_with_nthreads program~test_smooth->fftw_plan_with_nthreads init_fftw3 init_fftw3 program~test_smooth->init_fftw3 omp_get_max_threads omp_get_max_threads program~test_smooth->omp_get_max_threads proc~fft_filter fft_filter program~test_smooth->proc~fft_filter proc~median_filter median_filter program~test_smooth->proc~median_filter proc~median_smooth median_smooth program~test_smooth->proc~median_smooth proc~morpho_filter morpho_filter program~test_smooth->proc~morpho_filter proc~soften soften program~test_smooth->proc~soften read_surf read_surf program~test_smooth->read_surf unit2IUf unit2IUf program~test_smooth->unit2IUf write_surf write_surf program~test_smooth->write_surf proc~fft_filter->extend calc_fftw3_real_bwd calc_fftw3_real_bwd proc~fft_filter->calc_fftw3_real_bwd calc_fftw3_real_fwd calc_fftw3_real_fwd proc~fft_filter->calc_fftw3_real_fwd proc~gaussian_filter gaussian_filter proc~fft_filter->proc~gaussian_filter tab_calc_fftw3_real_bwd tab_calc_fftw3_real_bwd proc~fft_filter->tab_calc_fftw3_real_bwd tab_calc_fftw3_real_fwd tab_calc_fftw3_real_fwd proc~fft_filter->tab_calc_fftw3_real_fwd proc~median_filter->proc~median_smooth proc~calc_median calc_median proc~median_filter->proc~calc_median proc~calc_moments calc_moments proc~median_filter->proc~calc_moments omp_get_num_procs omp_get_num_procs proc~median_smooth->omp_get_num_procs proc~median_smooth->proc~calc_median sort_array2 sort_array2 proc~median_smooth->sort_array2 proc~roll_smooth roll_smooth proc~morpho_filter->proc~roll_smooth proc~calc_median->sort_array2 proc~calc_moments_1d calc_moments_1D proc~calc_moments->proc~calc_moments_1d proc~roll_smooth->omp_get_num_procs

Variables

Type Attributes Name Initial
real(kind=R8) :: dx
real(kind=R8) :: dy
real(kind=R8) :: dz
real(kind=R8), allocatable, dimension(:,:) :: ext_heights
real(kind=R8) :: fft_cutoff
real(kind=R8), allocatable, dimension(:,:) :: heights
real(kind=R8), allocatable, dimension(:,:) :: heights_copy
real(kind=R8), allocatable, dimension(:,:) :: heights_out
real(kind=R8), allocatable, dimension(:,:) :: mask
integer(kind=I4) :: n_th
integer(kind=I4) :: nx
integer(kind=I4) :: nx2
integer(kind=I4) :: ny
integer(kind=I4) :: ny2
real(kind=R8) :: pad
type(SCALE_SURF) :: scal_mask
type(SCALE_SURF) :: scal_surf

Source Code

program test_smooth
use data_arch,     only : I4, R8
use miscellaneous, only : get_unit
use surfile,       only : read_surf, write_surf, init_scal, SCALE_SURF, unit2IUf
use filter,        only : median_smooth, median_filter, soften, morpho_filter, fft_filter, PAD_FFT_FILTER
use fftw3,         only : fftw_plan_with_nthreads, init_fftw3, end_fftw3, extend
!$ use omp_lib

implicit none

real(kind=R8), allocatable, dimension(:,:) :: heights, heights_out, heights_copy, mask, ext_heights

real(kind=R8) :: dx, dy, dz, fft_cutoff, pad

integer(kind=I4) :: nx, ny, nx2, ny2, n_th

type(SCALE_SURF) :: scal_surf, scal_mask

!========================================================================= padding / windowing

call read_surf( nom_fic = "sur/AB-Zinv-ART-8-21-200x200.sur", &  ! IN
                  tab_s = heights,                            &  ! OUT
                   scal = scal_surf )                            ! OUT

nx = scal_surf%xres
ny = scal_surf%yres

pad = 1.5!PAD_FFT_FILTER

nx2 = 2 * ( nint(pad * nx)/2 )
ny2 = 2 * ( nint(pad * ny)/2 )

allocate( ext_heights(1:nx2, 1:ny2) )

call extend(   tab_in = heights(1:nx, 1:ny),          &  !
              tab_out = ext_heights(1:nx2, 1:ny2),    &  !
                   nx = nx,                           &  !
                   ny = ny,                           &  !
                  nx2 = nx2,                          &  !
                  ny2 = ny2,                          &  !
                  ext = 'constant',                   &  !
             type_apo = 'hann__')                        !

scal_surf%xres = nx2
scal_surf%yres = ny2

call write_surf( nom_fic = "out/test_extend.sur",        &  !
                 tab_s   = ext_heights(1:nx2, 1:ny2),    &  !
                 scal    = scal_surf )                      !

deallocate( ext_heights )

!========================================================================= fft_filter 5 µm

call read_surf( nom_fic = "sur/AB-Zinv-ART-8-21-200x200.sur", &  ! IN
                  tab_s = heights,                            &  ! OUT
                   scal = scal_surf )                            ! OUT

nx = scal_surf%xres
ny = scal_surf%yres

dx = scal_surf%dx * unit2IUf(scal_surf%dx_unit)
dy = scal_surf%dy * unit2IUf(scal_surf%dy_unit)
dz = 0

write(*,*) 'nx, ny = ', nx, ny
write(*,*) 'dx, dy = ', dx, dy

allocate( heights_out(1:nx, 1:ny) )


n_th = omp_get_max_threads()
call fftw_plan_with_nthreads(nthreads = n_th)

nx2 = 2 * ( nint(PAD_FFT_FILTER * nx)/2 )
ny2 = 2 * ( nint(PAD_FFT_FILTER * ny)/2 )

fft_cutoff = dx / 5.e-6

call init_fftw3(long = nx2,  & !
                larg = ny2 )   !

call fft_filter(tab       = heights(1:nx, 1:ny),      & !
                long      = nx,                       & !
                larg      = ny,                       & !
                cutoff    = fft_cutoff,               & !
                bf_tab    = heights_out(1:nx, 1:ny),  & !
                multi_fft = .FALSE.)                    !

call write_surf( nom_fic = "out/test_fft_filter_005µm.sur",    &  !
                 tab_s   = heights_out(1:nx, 1:ny),            &  !
                 scal    = scal_surf )                            !

write(*,*) 'gaussian filter cutoff = 5 µm'

!========================================================================= fft_filter 80 µm

fft_cutoff = dx / 80.e-6

call fft_filter(tab       = heights(1:nx, 1:ny),      & !
                long      = nx,                       & !
                larg      = ny,                       & !
                cutoff    = fft_cutoff,               & !
                bf_tab    = heights_out(1:nx, 1:ny),  & !
                multi_fft = .FALSE.)                    !

call write_surf( nom_fic = "out/test_fft_filter_080µm.sur",    &  !
                 tab_s   = heights_out(1:nx, 1:ny),            &  !
                 scal    = scal_surf )                            !

write(*,*) 'gaussian filter cutoff = 80 µm'

!========================================================================= fft_filter 150 µm

fft_cutoff = dx / 150.e-6

call fft_filter(tab       = heights(1:nx, 1:ny),      & !
                long      = nx,                       & !
                larg      = ny,                       & !
                cutoff    = fft_cutoff,               & !
                bf_tab    = heights_out(1:nx, 1:ny),  & !
                multi_fft = .FALSE.)                    !

call write_surf( nom_fic = "out/test_fft_filter_150µm.sur",    &  !
                 tab_s   = heights_out(1:nx, 1:ny),            &  !
                 scal    = scal_surf )                            !

write(*,*) 'gaussian filter cutoff = 150 µm'

call end_fftw3()

!========================================================================= ROLL +, RAY = 10 µm

call morpho_filter( mtype       = "dilation",                 &  ! IN
                    tabin       = heights(1:nx, 1:ny),        &  ! IN
                    tabou       = heights_out(1:nx, 1:ny),    &  ! OUT
                    long        = nx,                         &  ! IN
                    larg        = ny,                         &  ! IN
                    scale_xyz   = [dx, dy, dz],               &  ! IN
                    ray         = 10.e-6_R8,                  &  ! IN
                    omp         = .true.,                     &  ! IN
                    nb_div      = 50 )                           ! IN

call write_surf( nom_fic = "out/test_roll_smooth_dilation_10µm.sur",   &  !
                 tab_s   = heights_out(1:nx, 1:ny),                    &  !
                 scal    = scal_surf )                                    !

write(*,*) 'morpho filter: dilation disk 10 µm'

!------------------------------------------------------------------------- ROLL -, RAY = 10 µm

call morpho_filter( mtype       = "erosion",                  &  ! IN
                    tabin       = heights(1:nx, 1:ny),        &  ! IN
                    tabou       = heights_out(1:nx, 1:ny),    &  ! OUT
                    long        = nx,                         &  ! IN
                    larg        = ny,                         &  ! IN
                    scale_xyz   = [dx, dy, dz],               &  ! IN
                    ray         = 10.e-6_R8,                  &  ! IN
                    omp         = .true.,                     &  ! IN
                    nb_div      = 50 )                           ! IN

call write_surf( nom_fic = "out/test_roll_smooth_erosion_10µm.sur",   &  !
                 tab_s   = heights_out(1:nx, 1:ny),                   &  !
                 scal    = scal_surf )                                   !

write(*,*) 'morpho filter: erosion disk 10 µm'

!------------------------------------------------------------------------- CLOSING, RAY = 10 µm

call morpho_filter( mtype       = "closing",                  &  ! IN
                    tabin       = heights(1:nx, 1:ny),        &  ! IN
                    tabou       = heights_out(1:nx, 1:ny),    &  ! OUT
                    long        = nx,                         &  ! IN
                    larg        = ny,                         &  ! IN
                    scale_xyz   = [dx, dy, dz],               &  ! IN
                    ray         = 10.e-6_R8,                  &  ! IN
                    omp         = .true.,                     &  ! IN
                    nb_div      = 50 )                           ! IN

call write_surf( nom_fic = "out/test_roll_smooth_closing_10µm.sur",   &  !
                 tab_s   = heights_out(1:nx, 1:ny),                   &  !
                 scal    = scal_surf )                                   !

write(*,*) 'morpho filter: closing disk 10 µm'

!------------------------------------------------------------------------- OPENING, RAY = 10 µm

call morpho_filter( mtype       = "opening",                  &  ! IN
                    tabin       = heights(1:nx, 1:ny),        &  ! IN
                    tabou       = heights_out(1:nx, 1:ny),    &  ! OUT
                    long        = nx,                         &  ! IN
                    larg        = ny,                         &  ! IN
                    scale_xyz   = [dx, dy, dz],               &  ! IN
                    ray         = 10.e-6_R8,                  &  ! IN
                    omp         = .true.,                     &  ! IN
                    nb_div      = 50 )                           ! IN

call write_surf( nom_fic = "out/test_roll_smooth_opening_10µm.sur",   &  !
                 tab_s   = heights_out(1:nx, 1:ny),                   &  !
                 scal    = scal_surf )                                   !

write(*,*) 'morpho filter: opening disk 10 µm'

!========================================================================= KERNEL SIZE = 3

allocate( heights_copy(1:nx, 1:ny) )

heights_copy(1:nx, 1:ny) = heights(1:nx, 1:ny)

call median_smooth( tab    = heights(1:nx, 1:ny),        &  ! INOUT
                    long   = nx,                         &  ! IN
                    larg   = ny,                         &  ! IN
                    kernel = 3,                          &  ! IN
                    omp    = .true. )                       ! IN

call write_surf( nom_fic = "out/test_med_smooth_3.sur",  &  !
                 tab_s   = heights(1:nx, 1:ny),          &  !
                 scal    = scal_surf )                      !

write(*,*) 'median filter kernel: 3'

!========================================================================= KERNEL SIZE = 5

heights(1:nx, 1:ny) = heights_copy(1:nx, 1:ny)

call median_smooth( tab    = heights(1:nx, 1:ny),        &  ! INOUT
                    long   = nx,                         &  ! IN
                    larg   = ny,                         &  ! IN
                    kernel = 5,                          &  ! IN
                    omp    = .true. )                       ! IN

call write_surf( nom_fic = "out/test_med_smooth_5.sur",  &  !
                 tab_s   = heights(1:nx, 1:ny),          &  !
                 scal    = scal_surf )                      !

write(*,*) 'median filter kernel: 5'

!========================================================================= KERNEL SIZE = 9

heights(1:nx, 1:ny) = heights_copy(1:nx, 1:ny)

call median_smooth( tab    = heights(1:nx, 1:ny),        &  ! INOUT
                    long   = nx,                         &  ! IN
                    larg   = ny,                         &  ! IN
                    kernel = 9,                          &  ! IN
                    omp    = .true. )                       ! IN

call write_surf( nom_fic = "out/test_med_smooth_9.sur",  &  !
                 tab_s   = heights(1:nx, 1:ny),          &  !
                 scal    = scal_surf )                      !

write(*,*) 'median filter kernel: 9'

!========================================================================= SOFTEN NO MASK

heights(1:nx, 1:ny) = heights_copy(1:nx, 1:ny)

call soften( tabin  = heights(1:nx, 1:ny),         &  ! IN
             tabout = heights_out(1:nx, 1:ny),     &  ! OUT
             long   = nx,                          &  ! IN
             larg   = ny )                            ! IN

call write_surf( nom_fic = "out/test_soften_no_mask.sur",   &  !
                 tab_s   = heights_out(1:nx, 1:ny),         &  !
                 scal    = scal_surf )                         !

write(*,*) 'simple smooth with no mask'

!========================================================================= SOFTEN WITH MASK

call read_surf( nom_fic = "sur/test_mask.sur",  &  ! IN
                  tab_s = mask,                 &  ! OUT
                   scal = scal_mask )              ! OUT

call soften( tabin  = heights(1:nx, 1:ny),         &  ! IN
             tabout = heights_out(1:nx, 1:ny),     &  ! OUT
             mask   = nint(mask(1:nx, 1:ny)),      &  ! IN
             long   = nx,                          &  ! IN
             larg   = ny )                            ! IN

call write_surf( nom_fic = "out/test_soften_with_mask.sur",   &  !
                 tab_s   = heights_out(1:nx, 1:ny),           &  !
                 scal    = scal_surf )                           !

write(*,*) 'simple smooth in upper mask'

!========================================================================= MEDIAN FILTER SNB = 10, KERN = 15

call median_filter( tab    = heights(1:nx, 1:ny),        &  ! INOUT
                    long   = nx,                         &  ! IN
                    larg   = ny,                         &  ! IN
                    kernel = 15,                         &  ! IN
                    snb    = 10,                         &  ! IN
                    sig    = 3._R8,                      &  ! IN
                    omp    = .true. )                       ! IN

call write_surf( nom_fic = "out/test_med_filt_k15_s10.sur", &  !
                 tab_s   = heights(1:nx, 1:ny),             &  !
                 scal    = scal_surf )                         !

deallocate( heights, heights_copy, heights_out, mask )

stop
endprogram test_smooth