0

I was correcting distortion in an image. I overlaid the corrected section of the image onto the original image and discovered the overlaid section is darker than the source image.

I need a solution which does not change the quality of the image being overlaid.

The script being used was:

Set "G=%~n1%~x1"    ::This is the file name with extension
Set "X=1945" :: X position of overlay
Set "Y=0" :: Y position of overlay


REM Crop image 7776x3888 to smaller size 3888:3888 at X,Y of 1945:0
ffmpeg -i %G% -vf  "crop=3888:3888:1945:0" -c:a copy -y %FF%Center.jpg

REM Create Xmap file for Center Section 3888x3888
ffmpeg -f lavfi -i nullsrc=size=3888x3888 -vf format=pix_fmts=gray16le,geq=X -frames 1 -y %FF%XmapCenter.pgm


REM Create Ymap file for Center Section 3888x3888
ffmpeg -f lavfi -i nullsrc=size=3888x3888 -vf format=pix_fmts=gray16le,geq='if(gt(Y,1880),Y-19*(Y/1939)*(3887-X)/3887,if(gt(Y,1720),Y-14*(Y/1866)*(3887-X)/3887,if(gt(Y,1493),Y-11*(Y/1720)*(3887-X)/3887,Y-2*(Y/1493)*(3887-X)/3887)))'  -frames 1 -y %FF%YmapCenter.pgm


REM Create Remapped/Corrected Center Section 3888x3888
ffmpeg -i %FF%Center.jpg -i %FF%XmapCenter.pgm -i %FF%YmapCenter.pgm -lavfi "format=pix_fmts=rgb24, remap" -q:v 1 -y %FF%Center.jpg

REM Overlay Corrected Center onto Original
ffmpeg -i %G% -i %FF%Center.jpg -lavfi "overlay=x=%X%:y=%Y%" -y Corr_%G%

I attached the original, corrected section and the result of overlaid image.

original image1 corrected section2 overlaid image3

3
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Mar 13, 2023 at 15:33
  • Tested solution with success. The solution is found at: Previous solution
    – CANJMP
    Mar 13, 2023 at 16:11
  • Using 'overlay' command with the attribute ':format=auto' works well with still images such as jpg, etc. Not part of the original question but very similar is for overlay onto video. This solution is not able to color match the overlay and original video.
    – CANJMP
    Apr 7, 2023 at 19:35

0

You must log in to answer this question.

Browse other questions tagged .