Fixes#3477
The LoadImage and LoadImageMask nodes opened image files but did not
close them after processing. This kept file handles open, preventing
other processes from accessing the files.
Added try/finally blocks to ensure img.close() is called after
processing completes.