A method of transforming an N-bit raw wide dynamic range (WDR) Bayer image to a K-bit raw red-green-blue (RGB) image wherein N>K is provided that includes converting the N-bit raw WDR Bayer image to an N-bit raw RGB image, computing a luminance image from the N-bit raw RGB image, computing a pixel gain value for each luminance pixel in the luminance image to generate a gain map, applying a hierarchical noise filter to the gain map to generate a filtered gain map, applying the filtered gain map to the N-bit raw RGB image to generated a gain mapped N-bit RGB image, and downshifting the gain mapped N-bit RGB image by (N−K) to generate the K-bit RGB image.