def intensity_to_index(px): indices = {0x00: 3, 0x55: 2, 0xaa: 1, 0xff: 0} assert px in indices, px return indices[px]