1. A non-transitory machine readable medium storing a program which when executed by at least one processing unit performs a color matching operation, the program comprising sets of instructions for: based on analysis of luma component values of pixels of a first image and a second image, identifying a first initial set of ranges of luma component values in the first image and a second initial set of ranges of luma component values in the second image; splitting a range in the first initial set of ranges into two ranges in a first updated set of ranges; splitting a corresponding range in the second initial set of ranges into two ranges in a second updated set of ranges; for each range in the first updated set of ranges: determining a set of transforms to modify pixel values of the pixels in the first image with luma component values in the range so that the pixel values of pixels with luma component values in the range in the first image are similar to pixel values of pixels with luma component values in a corresponding range in the second image; and applying the set of transforms to the pixels in the first image with luma component values in the range such that the pixel values of the pixels with luma component values in the range in first image are similar to the pixel values of the pixels with luma component values in a corresponding range in the second image.