From 71c0d3eebb5b5cf2b1cf0056de968a3909ef5465 Mon Sep 17 00:00:00 2001 From: Marc DeGraef Date: Thu, 23 Jan 2025 07:01:15 -0500 Subject: [PATCH] adds logarithmic high-pass filter to EMppEBSD pattern preprocessing --- NamelistTemplates/EMppEBSD.template | 5 ++ Source/EMsoftOOLib/mod_patterns.f90 | 17 +++++-- .../EMsoftOOLib/program_mods/mod_ppEBSD.f90 | 47 ++++++++++++++++++- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/NamelistTemplates/EMppEBSD.template b/NamelistTemplates/EMppEBSD.template index c4e8788..f2eb274 100644 --- a/NamelistTemplates/EMppEBSD.template +++ b/NamelistTemplates/EMppEBSD.template @@ -20,6 +20,11 @@ hipassw = 0.05, ! number of regions for adaptive histogram equalization nregions = 10, +! number of pattern shifts to be used for logarithmic high pass filter + logparam = 10, +! filter type to be used ('fft' for EMsoft standard preprocessing with the hipassw and nregions +! parameters or 'log' for a logarithmic high pass filter) + filtertype = 'fft', ! pattern dimensions (actual) numsx = 640, numsy = 480, diff --git a/Source/EMsoftOOLib/mod_patterns.f90 b/Source/EMsoftOOLib/mod_patterns.f90 index c8ddd1e..a678a8e 100644 --- a/Source/EMsoftOOLib/mod_patterns.f90 +++ b/Source/EMsoftOOLib/mod_patterns.f90 @@ -166,7 +166,7 @@ end function computeEBSDIQ !-------------------------------------------------------------------------- recursive subroutine PreProcessPatterns(EMsoft, HDF, inRAM, nml, binx, biny, masklin, correctsize, totnumexpt, & - epatterns, exptIQ, log) + epatterns, exptIQ, log, logparam) !DEC$ ATTRIBUTES DLLEXPORT :: PreProcessPatterns !! author: MDG !! version: 1.0 @@ -205,6 +205,7 @@ recursive subroutine PreProcessPatterns(EMsoft, HDF, inRAM, nml, binx, biny, mas !f2py intent(in,out) :: epatterns real(kind=sgl),INTENT(INOUT),OPTIONAL :: exptIQ(totnumexpt) logical,INTENT(IN),OPTIONAL :: log +integer(kind=irg),INTENT(IN),OPTIONAL :: logparam !f2py intent(in,out) :: exptIQ type(IO_T) :: Message @@ -213,7 +214,7 @@ recursive subroutine PreProcessPatterns(EMsoft, HDF, inRAM, nml, binx, biny, mas logical :: ROIselected, f_exists, dolog=.FALSE. character(fnlen) :: fname -integer(kind=irg) :: istat, L, recordsize, io_int(2), patsz, iii, & +integer(kind=irg) :: istat, L, recordsize, io_int(2), patsz, iii, lp, & iiistart, iiiend, jjend, TID, jj, kk, ierr, itype integer(HSIZE_T) :: dims3(3), offset3(3) integer(kind=irg),parameter :: iunitexpt = 41, itmpexpt = 42 @@ -232,9 +233,17 @@ recursive subroutine PreProcessPatterns(EMsoft, HDF, inRAM, nml, binx, biny, mas ! standard or log-hipass processing ? if (present(log)) then - if (log.eqv..TRUE.) dolog = .TRUE. + if (log.eqv..TRUE.) then + dolog = .TRUE. + if (present(logparam)) then + lp = logparam + else + lp = 10 + end if + end if end if + if (nml%DIModality.eq.'EBSD') then isEBSD = .TRUE. else if (nml%DIModality.eq.'TKD') then @@ -418,7 +427,7 @@ recursive subroutine PreProcessPatterns(EMsoft, HDF, inRAM, nml, binx, biny, mas pint = nint(((Pat - mi) / (ma-mi))*255.0) Pat = float(adhisteq(nml%nregions,binx,biny,pint)) else - Pat = loghipass(Pat, 10, binx, biny) + Pat = loghipass(Pat, lp, binx, biny) end if ! convert back to 1D vector diff --git a/Source/EMsoftOOLib/program_mods/mod_ppEBSD.f90 b/Source/EMsoftOOLib/program_mods/mod_ppEBSD.f90 index 0c43bda..48688ce 100644 --- a/Source/EMsoftOOLib/program_mods/mod_ppEBSD.f90 +++ b/Source/EMsoftOOLib/program_mods/mod_ppEBSD.f90 @@ -47,6 +47,7 @@ module mod_ppEBSD integer(kind=irg) :: numsy integer(kind=irg) :: nthreads integer(kind=irg) :: nregions + integer(kind=irg) :: logparam integer(kind=irg) :: ROI(4) real(kind=dbl) :: hipassw character(3) :: filtertype @@ -79,6 +80,7 @@ module mod_ppEBSD procedure, pass(self) :: get_numsy_ procedure, pass(self) :: get_nthreads_ procedure, pass(self) :: get_nregions_ + procedure, pass(self) :: get_logparam_ procedure, pass(self) :: get_ROI_ procedure, pass(self) :: get_hipassw_ procedure, pass(self) :: get_filtertype_ @@ -116,6 +118,7 @@ module mod_ppEBSD generic, public :: get_numsy => get_numsy_ generic, public :: get_nthreads => get_nthreads_ generic, public :: get_nregions => get_nregions_ + generic, public :: get_logparam => get_logparam_ generic, public :: get_ROI => get_ROI_ generic, public :: get_hipassw => get_hipassw_ generic, public :: get_filtertype => get_filtertype_ @@ -454,6 +457,42 @@ subroutine set_nregions_(self,inp) end subroutine set_nregions_ +!-------------------------------------------------------------------------- +function get_logparam_(self) result(out) +!DEC$ ATTRIBUTES DLLEXPORT :: get_logparam_ +!! author: MDG +!! version: 1.0 +!! date: 01/23/25 +!! +!! get logparam from the ppEBSD_T class + +IMPLICIT NONE + +class(ppEBSD_T), INTENT(INOUT) :: self +integer(kind=irg) :: out + +out = self%nml%logparam + +end function get_logparam_ + +!-------------------------------------------------------------------------- +subroutine set_logparam_(self,inp) +!DEC$ ATTRIBUTES DLLEXPORT :: set_logparam_ +!! author: MDG +!! version: 1.0 +!! date: 01/23/25 +!! +!! set logparam in the ppEBSD_T class + +IMPLICIT NONE + +class(ppEBSD_T), INTENT(INOUT) :: self +integer(kind=irg), INTENT(IN) :: inp + +self%nml%logparam = inp + +end subroutine set_logparam_ + !-------------------------------------------------------------------------- function get_ROI_(self) result(out) !DEC$ ATTRIBUTES DLLEXPORT :: get_ROI_ @@ -808,6 +847,7 @@ subroutine readNameList_(self, nmlfile, initonly) integer(kind=irg) :: nthreads integer(kind=irg) :: nregions integer(kind=irg) :: ROI(4) +integer(kind=irg) :: logparam real(kind=dbl) :: hipassw character(1) :: maskpattern character(3) :: filtertype @@ -819,7 +859,7 @@ subroutine readNameList_(self, nmlfile, initonly) ! define the IO namelist to facilitate passing variables to the program. namelist / ppEBSDdata / numsx, numsy, nregions, maskpattern, nthreads, ipf_ht, ipf_wd, exptfile, maskradius, inputtype, & - filtertype, tmpfile, maskfile, HDFstrings, hipassw, ROI + filtertype, tmpfile, maskfile, HDFstrings, hipassw, ROI, logparam ! set the input parameters to default values ipf_ht = 100 @@ -829,6 +869,7 @@ subroutine readNameList_(self, nmlfile, initonly) maskradius = 240 hipassw = 0.05 nregions = 10 + logparam = 10 numsx = 0 numsy = 0 ROI = (/ 0, 0, 0, 0 /) @@ -871,6 +912,7 @@ subroutine readNameList_(self, nmlfile, initonly) self%nml%numsy = numsy self%nml%nthreads = nthreads self%nml%nregions = nregions +self%nml%logparam = logparam self%nml%ROI = ROI self%nml%hipassw = hipassw self%nml%filtertype = filtertype @@ -1064,7 +1106,8 @@ subroutine ppEBSD_(self, EMsoft, progname) call PreProcessPatterns(EMsoft, HDF, .FALSE., dinl, binx, biny, masklin, correctsize, totnumexpt) else ! logarithmic high-pass filter only - call PreProcessPatterns(EMsoft, HDF, .FALSE., dinl, binx, biny, masklin, correctsize, totnumexpt, log=.TRUE.) + call PreProcessPatterns(EMsoft, HDF, .FALSE., dinl, binx, biny, masklin, correctsize, totnumexpt, & + log=.TRUE., logparam=ppnl%logparam) end if !=====================================================