Skip to content

Commit

Permalink
adds logarithmic high-pass filter to EMppEBSD pattern preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcdegraef committed Jan 23, 2025
1 parent a2b3b7f commit 71c0d3e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
5 changes: 5 additions & 0 deletions NamelistTemplates/EMppEBSD.template
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions Source/EMsoftOOLib/mod_patterns.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
47 changes: 45 additions & 2 deletions Source/EMsoftOOLib/program_mods/mod_ppEBSD.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_
Expand Down Expand Up @@ -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_
Expand Down Expand Up @@ -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_
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 /)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

!=====================================================
Expand Down

0 comments on commit 71c0d3e

Please sign in to comment.