Eugene - 2015-10-26

Some very basic ideas

add option "-forcegray"
add option "-graytreshold <value>", define default value 5-10.

If "forcegray" defined in command line then check image:

if (BrokenGrayscale) ConvertToGrayscale;

function BrokenGrayscale {
// here we will check if it's "broken" grayscale image or normal RGB image.
// check difference in R/G/B channels
for every pixel {
if (MAX(ABS(R-G),ABS(R-B),ABS(G-B)) > graytreshold) return false; // nope, difference in channels too big => normal RGB image
}
return true; // yes, difference is just few points => broken grayscale image, requires conversion to "proper" grayscale
}

function ConvertToGrayscale {
for every pixel {
// with usual very small difference in R/G/B channels there's no reason to use BT.709 or BT.601 methods, simple average is good enough
Gray = (R+G+B)/3
R = Gray
G = Gray
B = Gray
}
}

Optimize(); // usual optimization

 

Last edit: Eugene 2015-10-26