Start of histographic equalisation code