Fixed optical density calculation to handle out-of-bounds points and appropriate blackness values