I am done with this Script as my (superficial) testing seemed to reveal no problems with 8bit images.
The operation works on the composite Channel so the individual RGB Channels may provide different results.
If you want to improve the Script go ahead.
Regards,
Pfaffenbichler