The steps are:
1. Decide which image to align the others to. I chose the central "full frontal" image, IMG_20181008_175313652.jpg
2. Decide which points on that image will not move. These should be vertically above each other in all images, ie within the main subject plane. I chose (586,324) and (586,869).
3. Decide on the window size for searches. It needs to be big enough to be distinctive, but not so large that it includes detail that isn't in the same plane. I chose 15x15.
4. Decide how large an area to search in each image. I chose the window size, multiplied by 9.
5. Write a list of the input images, from the central image forwards, listfwd.txt:
Code: Select all
IMG_20181008_175313652.jpg
IMG_20181008_175317636.jpg
IMG_20181008_175323231.jpg
IMG_20181008_175332486.jpg
IMG_20181008_175338634.jpg
IMG_20181008_175350987.jpg
IMG_20181008_175357155.jpg
IMG_20181008_175404592.jpg
IMG_20181008_175413653.jpg
6. Write a list of the input images, from the central image backwards, listbkwd.txt:
Code: Select all
IMG_20181008_175313652.jpg
IMG_20181008_175308782.jpg
IMG_20181008_175302042.jpg
IMG_20181008_175254984.jpg
IMG_20181008_175246234.jpg
IMG_20181008_175240880.jpg
IMG_20181008_175226628.jpg
The rest is automated, in the Windows BAT script doAlign.bat:
Code: Select all
call srchList listfwd.txt 586 324 coordsFwdTop.txt
call srchList listbkwd.txt 586 324 coordsBckTop.txt
call srchList listfwd.txt 586 869 coordsFwdBot.txt
call srchList listbkwd.txt 586 869 coordsBckBot.txt
if not exist distorted md distorted
del /s /q distorted\*
rem -----------------------------
rem Do the central image, undistorted.
call readArray listfwd.txt Files
%IMG7%magick ^
!Files[0]! ^
-gravity Center -crop 1000x1000+0+0 +repage ^
-resize 600x600 ^
distorted\!Files[0]!
rem -----------------------------
rem Distort the forwards list.
call readArray listfwd.txt Files
call readArray coordsFwdTop.txt CdsTop
call readArray coordsFwdBot.txt CdsBot
set firstCdsTop=%CdsTop[0]%
set firstCdsBot=%CdsBot[0]%
for /L %%I in (1,1,%Files_CNTm1%) do (
echo !Files[%%I]! !CdsTop[%%I]!,!CdsBot[%%I]!
%IMG7%magick ^
!Files[%%I]! ^
-distort Affine !CdsTop[%%I]!,%firstCdsTop%,!CdsBot[%%I]!,%firstCdsBot% ^
-gravity Center -crop 1000x1000+0+0 +repage ^
-resize 600x600 ^
distorted\!Files[%%I]!
)
rem -----------------------------
rem Distort the backwards list.
call readArray listbkwd.txt Files
call readArray coordsBckTop.txt CdsTop
call readArray coordsBckBot.txt CdsBot
set firstCdsTop=%CdsTop[0]%
set firstCdsBot=%CdsBot[0]%
for /L %%I in (1,1,%Files_CNTm1%) do (
echo !Files[%%I]! !CdsTop[%%I]!,!CdsBot[%%I]!
%IMG7%magick ^
!Files[%%I]! ^
-distort Affine !CdsTop[%%I]!,%firstCdsTop%,!CdsBot[%%I]!,%firstCdsBot% ^
-gravity Center -crop 1000x1000+0+0 +repage ^
-resize 600x600 ^
distorted\!Files[%%I]!
)
rem -----------------------------
rem Make the GIF.
%IMG7%magick ^
distorted\*.jpg ^
amst_aligned.gif
doAlign.bat calls srchList for the forwards and backwards lists, to find the corresponding points in the other images. srchList.bat is:
Code: Select all
rem %1 is a list of images
rem %2,%3 are coordinates in first image
rem %4 is output text file.
set slX=%2
set slY=%3
echo !slX!,!slY!>%4
set HasFirst=0
set PrevFile=
set NUM=0
for /F "tokens=*" %%F in (%1) do (
echo %%F
if !HasFirst!==0 (
set PrevFile=%%F
set HasFirst=1
) else (
call srchLink !PrevFile! %%F !slX! !slY!
if ERRORLEVEL 1 exit /B 1
copy /y sub_si_dbg.png sl_dbg_!NUM!.png
set /A NUM+=1
echo !slX!,!slY!>>%4
set PrevFile=%%F
)
)
In turn, this calls searchLink, to do one link in the search chain:
Code: Select all
rem Search one link in a search chain.
rem %1 is an image from which a rectangle will be cropped,
rem %2 is an image to be searched.
rem %3,%4 coords of a point in %1
rem Returns slX and slY, corresponding point in %2.
echo %0: %1 %2 %3 %4
set WindWH=15
set /A WindR=(%WindWH%-1)/2
set IMG1=%1
set IMG2=%2
set GuessX=%3
set GuessY=%4
%IMG7%magick ^
%IMG1% ^
-crop %WindWH%x%WindWH%+%%[fx:%GuessX%-%WindR%]+%%[fx:%GuessY%-%WindR%] +repage ^
s1.png
set WindFact=9
set /A WindSide=(%WindFact%-1)/2
set /A SX=%GuessX%-%WindR%-%WindWH%*%WindSide%
set /A SY=%GuessY%-%WindR%-%WindWH%*%WindSide%
if %SX% LSS 0 (
echo SX=%SX%
exit /B 1
)
if %SY% LSS 0 (
echo SY=%SY%
exit /B 1
)
%IMG7%magick ^
%IMG2% ^
-crop %%[fx:%WindWH%*%WindFact%]x%%[fx:%WindWH%*%WindFact%]+%SX%+%SY% +repage ^
sub.png
set siDEBUG=1
call %PICTBAT%srchImg sub.png s1.png
set /A slX=%SX%+%siCOMP_XW%+%WindR%
set /A slY=%Sy%+%siCOMP_YW%+%WindR%
echo slX=%slX% slY=%slY%
In turn, this calls srchImg.bat. See
Searching an image . This takes most of the time. If you have my process modules, "-process srchimg" would take less time.
Okay, so now we know the coordinates of the two points in each image that correspond to the two points in our central image. doAlign.bat copies the central image, then does the affine transformation for the images in the forwards list, then for those in the backwards list. For each of these, we take a central crop to remove the added virtual pixels at edges. We also resize to 600x600 for the web.
Finally, doAlign.bat takes all these distorted images and makes them into a GIF.