Working histogram comparison code