Optimize the function that change the images colors to black and white -refs BT#7410