Skip to content

Commit

Permalink
update to homography-shape function conversion
Browse files Browse the repository at this point in the history
this modification ensures that the homography coefficients are interpreted in the same way as in the Ernould papers (Fig. 4 of Chapter 2).
  • Loading branch information
marcdegraef committed Dec 20, 2024
1 parent b4ba7c1 commit 5a23178
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
29 changes: 19 additions & 10 deletions Source/EMsoftOOLib/mod_DIC.f90
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ module mod_DIC
real(wp) :: W(3,3) ! shape function
real(wp) :: h(8) ! homography
real(wp) :: CIC ! current value of function to be minimized
integer(ip) :: kx = 5 ! spline order
integer(ip) :: ky = 5 ! spline order
integer(ip) :: kx = 4 ! spline order
integer(ip) :: ky = 4 ! spline order
integer(kind=irg) :: nx ! pattern x-size
integer(kind=irg) :: ny ! pattern y-size
real(wp) :: rnxi ! pattern x scale factor
Expand Down Expand Up @@ -177,7 +177,7 @@ recursive type(DIC_T) function DIC_constructor( nx, ny ) result(DIC)
do i=0,nx-1
DIC%x(i) = real(i,wp)
end do
DIC%x = DIC%x * arx
DIC%x = DIC%x * arx
! DIC%x = DIC%x * DIC%rnxi
do j=0,ny-1
DIC%y(j) = real(j,wp)
Expand Down Expand Up @@ -576,6 +576,8 @@ recursive subroutine applyHomography_(self, h, PCx, PCy, dotarget)
! convert to shape function
W = self%getShapeFunction(h)

! W = matrixInvert_wp(W)

! determine the XiPrime coordinates so that we can apply the deformation by
! means of the evaluate method in the bspline class
if (.not.allocated(self%XiPrime)) allocate( self%XiPrime(0:1, 0:lnx*lny-1))
Expand Down Expand Up @@ -778,6 +780,9 @@ recursive function getShapeFunction_(self, h, store) result(W)
!!
!! convert input homography to a 3x3 shape function W and optionally store it
!! as a class variable
!!
!! note that the interpolation routines sample the original image to the deformed
!! image so we need to invert that behavior ...

IMPLICIT NONE

Expand All @@ -786,14 +791,14 @@ recursive function getShapeFunction_(self, h, store) result(W)
logical, INTENT(IN), OPTIONAL :: store
real(wp) :: W(3,3)

W(1,1) = 1.0_wp + h(1)
W(2,2) = 1.0_wp + h(5)
W(1,1) = 1.0_wp / (1.0_wp + h(1))
W(2,2) = 1.0_wp / (1.0_wp + h(5))
W(3,3) = 1.0_wp

W(1,2:3) = h(2:3)
W(2,1) = h(4)
W(2,3) = h(6)
W(3,1:2) = h(7:8)
W(1,2:3) = -h(2:3)
W(2,1) = -h(4)
W(2,3) = -h(6)
W(3,1:2) = -h(7:8)

if (present(store)) then
if (store.eqv..TRUE.) then
Expand All @@ -812,6 +817,10 @@ recursive function getHomography_(self, W, store) result(h)
!!
!! convert input 3x3 shape function to homography h and optionally store it
!! as a class variable
!!
!! note that the interpolation routines sample the original image to the deformed
!! image so we need to invert that behavior ...


IMPLICIT NONE

Expand All @@ -820,7 +829,7 @@ recursive function getHomography_(self, W, store) result(h)
logical, INTENT(IN), OPTIONAL :: store
real(wp) :: h(8)

h = (/ W(1,1)-1.0_wp, W(1,2), W(1,3), W(2,1), W(2,2)-1.0_wp, W(2,3), W(3,1), W(3,2) /)
h = (/ 1.0_wp/W(1,1)-1.0_wp, -W(1,2), -W(1,3), -W(2,1), 1.0_wp/W(2,2)-1.0_wp, -W(2,3), -W(3,1), W(3,2) /)

if (present(store)) then
if (store.eqv..TRUE.) then
Expand Down
28 changes: 21 additions & 7 deletions Source/TestPrograms/play.f90
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ program EMplay
! write (*,*) ' tmppat entries : ', tmppat(1:2,1:2)
! write (*,*) ' reference pattern : ', minval(tmppat), maxval(tmppat)

! refpat(20:40,20:22) = 1.0_wp
! refpat(20:22,20:40) = 1.0_wp

write (*,*) matmul( reshape( (/ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 /),(/3,3/) ), &
(/ 10.0, 20.0, 30.0 /) )

call DIC%setpattern('r', refpat)

Expand Down Expand Up @@ -185,32 +190,32 @@ program EMplay

write (20) real(refpat)

horiginal = (/ 0.5D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0 /)
horiginal = (/ 0.2D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0 /)
call DIC%applyHomography(horiginal, PCx, PCy)
defpat = DIC%getpattern('d', nx, ny)
write (20) real(defpat)
call DIC%cleanup()
horiginal = (/ 0.0D0, 0.3D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0 /)
horiginal = (/ 0.0D0, 0.5D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0 /)
call DIC%applyHomography(horiginal, PCx, PCy)
defpat = DIC%getpattern('d', nx, ny)
write (20) real(defpat)
call DIC%cleanup()
horiginal = (/ 0.D0, 0.D0, 25.0D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0 /)
horiginal = (/ 0.D0, 0.D0, 50.0D0, 0.D0, 0.D0, 0.D0, 0.D0, 0.D0 /)
call DIC%applyHomography(horiginal, PCx, PCy)
defpat = DIC%getpattern('d', nx, ny)
write (20) real(defpat)
call DIC%cleanup()
horiginal = (/ 0.D0, 0.D0, 0.0D0, 0.3D0, 0.D0, 0.D0, 0.D0, 0.D0 /)
horiginal = (/ 0.D0, 0.D0, 0.0D0, 0.5D0, 0.D0, 0.D0, 0.D0, 0.D0 /)
call DIC%applyHomography(horiginal, PCx, PCy)
defpat = DIC%getpattern('d', nx, ny)
write (20) real(defpat)
call DIC%cleanup()
horiginal = (/ 0.D0, 0.D0, 0.D0, 0.D0, 0.5D0, 0.D0, 0.D0, 0.D0 /)
horiginal = (/ 0.D0, 0.D0, 0.D0, 0.D0, 0.2D0, 0.D0, 0.D0, 0.D0 /)
call DIC%applyHomography(horiginal, PCx, PCy)
defpat = DIC%getpattern('d', nx, ny)
write (20) real(defpat)
call DIC%cleanup()
horiginal = (/ 0.D0, 0.D0, 0.0D0, 0.D0, 0.D0, 20.0D0, 0.D0, 0.D0 /)
horiginal = (/ 0.D0, 0.D0, 0.0D0, 0.D0, 0.D0, 50.0D0, 0.D0, 0.D0 /)
call DIC%applyHomography(horiginal, PCx, PCy)
defpat = DIC%getpattern('d', nx, ny)
write (20) real(defpat)
Expand All @@ -220,7 +225,7 @@ program EMplay
defpat = DIC%getpattern('d', nx, ny)
write (20) real(defpat)
call DIC%cleanup()
horiginal = (/ 0.D0, 0.D0, 0.0D0, 0.D0, 0.D0, 0.D0, 0.0D0, 0.002D0 /)
horiginal = (/ 0.D0, 0.D0, 0.0D0, 0.D0, 0.D0, 0.D0, 0.0D0, 0.001D0 /)
call DIC%applyHomography(horiginal, PCx, PCy)
defpat = DIC%getpattern('d', nx, ny)
write (20) real(defpat)
Expand All @@ -232,6 +237,15 @@ program EMplay

close(20,status='keep')

! check

horiginal = (/ 0.01D0, 0.1D0, 50.0D0, 0.1D0, 0.5D0,-50.D0, 0.002D0, 0.002D0 /)
write(*,*) horiginal
W = DIC%getShapeFunction(horiginal)
hg = DIC%getHomography(W)
write(*,*) hg


stop

do jj=1, 10 ! 2500
Expand Down

0 comments on commit 5a23178

Please sign in to comment.