Patent Publication Number: US-2023156343-A1

Title: Blind local reshaping in hdr imaging

Description:
CROSS-REFERENCE TO RELATED APPLICATIONS 
     This application claims priority to U.S. Provisional Application No. 63/004,609 and European Patent Application No. 20167908.1, both filed on Apr. 3, 2020, each of which is incorporated by reference in its entirety. 
    
    
     TECHNOLOGY 
     The present disclosure relates generally to images. More particularly, an embodiment of the present invention relates to improving coding efficiency and image quality of high-dynamic range (HDR) images reconstructed from standard-dynamic range (SDR) images using local reshaping functions. 
     BACKGROUND 
     As used herein, the term ‘dynamic range’ (DR) may relate to a capability of the human visual system (HVS) to perceive a range of intensity (e.g., luminance, luma) in an image, e.g., from darkest grays (blacks) to brightest whites (highlights). In this sense, DR relates to a ‘scene-referred’ intensity. DR may also relate to the ability of a display device to adequately or approximately render an intensity range of a particular breadth. In this sense, DR relates to a ‘display-referred’ intensity. Unless a particular sense is explicitly specified to have particular significance at any point in the description herein, it should be inferred that the term may be used in either sense, e.g. interchangeably. 
     As used herein, the term high dynamic range (HDR) relates to a DR breadth that spans the 14-15 orders of magnitude of the human visual system (HVS). In practice, the DR over which a human may simultaneously perceive an extensive breadth in intensity range may be somewhat truncated, in relation to HDR. As used herein, the terms visual dynamic range (VDR) or enhanced dynamic range (EDR) may individually or interchangeably relate to the DR that is perceivable within a scene or image by a human visual system (HVS) that includes eye movements, allowing for some light adaptation changes across the scene or image. As used herein, VDR may relate to a DR that spans 5 to 6 orders of magnitude. Thus, while perhaps somewhat narrower in relation to true scene referred HDR, VDR or EDR nonetheless represents a wide DR breadth and may also be referred to as HDR. 
     In practice, images comprise one or more color components (e.g., luma Y and chroma Cb and Cr) wherein each color component is represented by a precision of n-bits per pixel (e.g., n=8). For example, using gamma luminance coding, images where n≤8 (e.g., color 24-bit JPEG images) are considered images of standard dynamic range, while images where n≥10 may be considered images of enhanced dynamic range. HDR images may also be stored and distributed using high-precision (e.g., 16-bit) floating-point formats, such as the OpenEXR file format developed by Industrial Light and Magic. 
     Most consumer desktop displays currently support luminance of 200 to 300 cd/m 2  or nits. Most consumer HDTVs range from 300 to 500 nits with new models reaching 1000 nits (cd/m 2 ). Such conventional displays thus typify a lower dynamic range (LDR), also referred to as a standard dynamic range (SDR), in relation to HDR. As the availability of HDR content grows due to advances in both capture equipment (e.g., cameras) and HDR displays (e.g., the PRM-4200 professional reference monitor from Dolby Laboratories), HDR content may be color graded and displayed on HDR displays that support higher dynamic ranges (e.g., from 1,000 nits to 5,000 nits or more). 
     As used herein, the term “forward reshaping” denotes a process of sample-to-sample or codeword-to-codeword mapping of a digital image from its original bit depth and original codewords distribution or representation (e.g., gamma, PQ, HLG, and the like) to an image of the same or different bit depth and a different codewords distribution or representation. Reshaping allows for improved compressibility or improved image quality at a fixed bit rate. For example, without limitation, reshaping may be applied to 10-bit or 12-bit PQ-coded HDR video to improve coding efficiency in a 10-bit video coding architecture. In a receiver, after decompressing the received signal (which may or may not be reshaped), the receiver may apply an “inverse (or backward) reshaping function” to restore the signal to its original codeword distribution and/or to achieve a higher dynamic range. 
     In traditional reshaping techniques, a single, global, forward reshaping function may be applied to all pixels in an input HDR image to generate a reshaped SDR image to be compressed and transmitted to a decoder. Next, information related to the forward reshaping function (e.g., a parametric representation of the backward reshaping function) may be sent to a decoder as metadata together with the reshaped SDR image to assist a decoder to reconstruct the input HDR image. As appreciated by the inventors here, improved techniques for image reshaping to reduce coding artifacts in HDR coding and improve the quality of the corresponding reshaped SDR images are desired. 
     As used herein, the term “local reshaping” denotes that an encoder may use a family of reshaping functions and each pixel in an input image may be encoded using a different reshaping function, selected from the family of reshaping functions, according to local spatial information. 
     As used herein, the term “blind local reshaping” refers to a method where no information is sent to a decoder on how the individual forward reshaping functions were selected for each input HDR image pixel in the encoder, thus requiring the decoder to autonomously reconstruct that information from the encoded SDR data. 
     The approaches described in this section are approaches that could be pursued, but not necessarily approaches that have been previously conceived or pursued. Therefore, unless otherwise indicated, it should not be assumed that any of the approaches described in this section qualify as prior art merely by virtue of their inclusion in this section. Similarly, issues identified with respect to one or more approaches should not assume to have been recognized in any prior art on the basis of this section, unless otherwise indicated. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
       An embodiment of the present invention is illustrated by way of example, and not in way by limitation, in the figures of the accompanying drawings and in which like reference numerals refer to similar elements and in which: 
         FIG.  1 A  depicts an example single-layer encoder for HDR data using a global reshaping function according to prior art; 
         FIG.  1 B  depicts an example HDR decoder corresponding to the encoder of  FIG.  1 A , according to prior art; 
         FIG.  2 A  depicts an example single-layer encoder for HDR data using local forward reshaping according to an embodiment of this invention; 
         FIG.  2 B  depicts an example HDR decoder corresponding to the encoder of  FIG.  2 A , according to an embodiment of this invention; 
         FIG.  3 A  depicts an example iterative process for blind local backward reshaping according to a first embodiment of this invention; 
         FIG.  3 B  depicts an example iterative process for bling local backward reshaping according to a second embodiment of this invention; 
         FIG.  4 A  depicts an example plot of a global forward reshaping function; 
         FIG.  4 B  depicts an example plot of a template forward reshaping function corresponding to the global forward reshaping function of  FIG.  4 A ; 
         FIG.  4 C  depicts an example plot of a template backward reshaping function corresponding to the template forward reshaping function of  FIG.  4 B ; 
         FIG.  4 D  depicts example plots of a set of local forward reshaping functions corresponding to the template forward reshaping function of  FIG.  4 B ; 
         FIG.  4 E  depicts example plots of a set of local backward reshaping functions corresponding to the template backward reshaping function of  FIG.  4 C ; and 
         FIG.  5    depicts an example process to generate a family of local forward reshaping functions and a family of local backward reshaping functions based on a global forward reshaping function according to an embodiment of this invention. 
     
    
    
     DESCRIPTION OF EXAMPLE EMBODIMENTS 
     Methods for blind local reshaping for coding HDR images and video content are described herein. In the following description, for the purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the present invention. It will be apparent, however, that the present invention may be practiced without these specific details. In other instances, well-known structures and devices are not described in exhaustive detail, in order to avoid unnecessarily occluding, obscuring, or obfuscating the present invention. 
     SUMMARY 
     Example embodiments described herein relate to blind local reshaping for coding of HDR images. In an embodiment, in an encoder, given an input HDR image, the encoder uses a family of forward reshaping functions and an array of forward mapping indices (FMI), where the FMI array indicates which forward reshaping function is to be used for each input HDR pixel, to reshape the input HDR image and generate a reshaped SDR image. In a decoder, given the received reshaped SDR image and a family of backward reshaping functions, the decoder applies an iterative technique to generate an array of backward mapping indices (BMI), where the BMI array indicates which backward reshaping function is to be used for each SDR pixel to generate a reconstructed HDR image which best approximates the input HDR image. 
     In an embodiment, in an apparatus comprising one or more processors, a decoder receives an input reshaped image ( 156 ) in a first dynamic range, it initializes ( 305 ) an array of backward mapping indices (BMI), wherein each element of the BMI array indicates an index of a local backward reshaping function in a set of two or more local backward reshaping functions, wherein a local backward reshaping function maps pixel values from the first dynamic range to pixel values in the second dynamic range, and performs one or more iterations to generate an output reconstructed image in a second dynamic range, wherein an iteration comprises:
         generating ( 310 ) a first reconstructed image in the second dynamic range by applying the set of local backward reshaping functions to the input reshaped image according to the BMI array;   generating ( 315 ) a first array of forward mapping indices (FMI) based on the first reconstructed image and an FMI-generation function, wherein each element of the FMI array indicates an index of a local forward reshaping function in a set of two or more local forward reshaping functions, wherein a local forward reshaping function maps pixel values from the second dynamic range to pixel values in the first dynamic range;   measuring a difference between the BMI array and the first FMI array according to a first error metric to generate a mapping-indices error;   generating ( 325 ) an updated BMI array based on the mapping-indices error;   generating ( 330 ) a second reconstructed image in the second dynamic range by applying the set of local backward reshaping functions to the input reshaped image according to the updated BMI array;   generating ( 335 ) an updated FMI array based on the second reconstructed image and the FMI-generation function;   generating ( 340 ) an estimate reshaped image in the first dynamic range by applying the set of local forward reshaping functions to the second reconstructed image according to the updated FMI array;   measuring a difference between the estimate reshaped image and the input reshaped image according to a second error metric to generate a reshaped-images error; and   testing if a combination of the reshaped-images error and the mapping-indices error satisfies a convergence criterion:
           if the converge criterion is satisfied, terminating the iteration and outputting the second reconstructed image as the output reconstructed image;   else:
               replacing ( 360 ) elements of the BMI array based on elements of the updated BMI array and the reshaped-images error; and   performing another iteration.   
               
               

     In a second embodiment, in an apparatus comprising one or more processors, a processor accesses a global forward reshaping function; 
     generates property values for the global forward reshaping function, wherein the property values comprise one or more of: a non-flat region (x-range) of the function in the second dynamic range, a mid-point of the x-range, and flat regions for the for darks and highlights in the second dynamic range; 
     generates a template forward reshaping function based on the global forward reshaping function, the property values, and an x-range scaling factor; 
     generates a template backward reshaping function by computing an inverse function of the template forward reshaping function; and, for a local forward reshaping function related to a target luminance value in the second dynamic range, generates the local forward reshaping function by shifting the template forward reshaping function by an x-axis shift value, wherein the x-axis shift value is determined so that: for the target luminance value, corresponding mean reshaped output values using the local forward reshaping function and the template forward reshaping function are approximately equal. 
     Example HDR Coding System 
     As described in U.S. patent Ser. No. 10,032,262, “Block-based content-adaptive reshaping for high dynamic range images,” by A. Kheradmand et al., to be referred to as the &#39;262 Patent, which is incorporated herein by reference in its entirety,  FIG.  1 A  and  FIG.  1 B  illustrate an example single-layer backward-compatible codec framework using image reshaping. More specifically,  FIG.  1 A  illustrates an example encoder-side codec architecture, which may be implemented with one or more computing processors in an upstream video encoder.  FIG.  1 B  illustrates an example decoder-side codec architecture, which may also be implemented with one or more computing processors in one or more downstream video decoders. 
     Under this framework, given reference HDR content ( 120 ), corresponding SDR content ( 134 ) (also to be referred as base-layer (BL) or reshaped content) is encoded and transmitted in a single layer of a coded video signal ( 144 ) by an upstream encoding device that implements the encoder-side codec architecture. The SDR content is received and decoded, in the single layer of the video signal, by a downstream decoding device that implements the decoder-side codec architecture. Backward-reshaping metadata ( 152 ) is also encoded and transmitted in the video signal with the SDR content so that HDR display devices can reconstruct HDR content based on the SDR content and the backward reshaping metadata. Without loss of generality, in some embodiments, as in non-backward-compatible systems, SDR content may not be watchable on its own, but must be watched in combination with the backward reshaping function which will generate watchable SDR or HDR content. In other embodiments which support backward compatibility, legacy SDR decoders can still playback the received SDR content without employing the backward reshaping function. 
     As illustrated in  FIG.  1 A , given HDR image ( 120 ) and a target dynamic range, after generating, in step  130 , a forward reshaping function ( 132 ); given the forward reshaping function, a forward reshaping mapping step ( 132 ) is applied to the HDR images ( 120 ) to generate reshaped SDR base layer ( 134 ). A compression block ( 142 ) (e.g., an encoder implemented according to any known video coding algorithms, like AVC, HEVC, AV 1 , and the like) compresses/encodes the SDR images ( 134 ) in a single layer ( 144 ) of a video signal. In addition, a backward reshaping function generator ( 150 ) may generate a backward reshaping function which may be transmitted to a decoder as metadata ( 152 ). In some embodiments, metadata ( 152 ) may represent the forward reshaping function ( 130 ), thus, it would be up to the decoder to generate the backward reshaping function (not shown). 
     Examples of backward reshaping metadata representing/specifying the optimal backward reshaping functions may include, but are not necessarily limited to only, any of: inverse tone mapping function, inverse luma mapping functions, inverse chroma mapping functions, lookup tables (LUTs), polynomials, inverse display management coefficients/parameters, etc. In various embodiments, luma backward reshaping functions and chroma backward reshaping functions may be derived/optimized jointly or separately, may be derived using a variety of techniques, for example, and without limitation, as described in the &#39;262 Patent. 
     The backward reshaping metadata ( 152 ), as generated by the backward reshaping function generator ( 150 ) based on the SDR images ( 134 ) and the target HDR images ( 120 ), may be multiplexed as part of the video signal  144 , for example, as supplemental enhancement information (SEI) messaging. 
     In some embodiments, backward reshaping metadata ( 152 ) is carried in the video signal as a part of overall image metadata, which is separately carried in the video signal from the single layer in which the SDR images are encoded in the video signal. For example, the backward reshaping metadata ( 152 ) may be encoded in a component stream in the coded bitstream, which component stream may or may not be separate from the single layer (of the coded bitstream) in which the SDR images ( 134 ) are encoded. 
     Thus, the backward reshaping metadata ( 152 ) can be generated or pre-generated on the encoder side to take advantage of powerful computing resources and offline encoding flows (including but not limited to content adaptive multiple passes, look ahead operations, inverse luma mapping, inverse chroma mapping, CDF-based histogram approximation and/or transfer, etc.) available on the encoder side. 
     The encoder-side architecture of  FIG.  1 A  can be used to avoid directly encoding the target HDR images ( 120 ) into coded/compressed HDR images in the video signal; instead, the backward reshaping metadata ( 152 ) in the video signal can be used to enable downstream decoding devices to backward reshape the SDR images ( 134 ) (which are encoded in the video signal) into reconstructed images that are identical to or closely/optimally approximate the reference HDR images ( 120 ). 
     In some embodiments, as illustrated in  FIG.  1 B , the video signal encoded with the SDR images in the single layer ( 144 ) and the backward reshaping metadata ( 152 ) as a part of the overall image metadata are received as input on the decoder side of the codec framework. A decompression block ( 154 ) decompresses/decodes compressed video data in the single layer ( 144 ) of the video signal into the decoded SDR images ( 156 ). Decompression  154  typically corresponds to the inverse of compression  142 . The decoded SDR images ( 156 ) may be the same as the SDR images ( 134 ), subject to quantization errors in the compression block ( 142 ) and in the decompression block ( 154 ), which may have been optimized for SDR display devices. In a backward-compatible system, the decoded SDR images ( 156 ) may be outputted in an output SDR video signal (e.g., over an HDMI interface, over a video link, etc.) to be rendered on an SDR display device. 
     Optionally, alternatively, or in addition, in the same or another embodiment, a backward reshaping block  158  extracts the backward (or forward) reshaping metadata ( 152 ) from the input video signal, constructs the backward reshaping functions based on the reshaping metadata ( 152 ), and performs backward reshaping operations on the decoded SDR images ( 156 ) based on the optimal backward reshaping functions to generate the backward reshaped images ( 160 ) (or reconstructed HDR images). In some embodiments, the backward reshaped images represent production-quality or near-production-quality HDR images that are identical to or closely/optimally approximating the reference HDR images ( 120 ). The backward reshaped images ( 160 ) may be outputted in an output HDR video signal (e.g., over an HDMI interface, over a video link, etc.) to be rendered on an HDR display device. 
     In some embodiments, display management operations specific to the HDR display device may be performed on the backward reshaped images ( 160 ) as a part of HDR image rendering operations that render the backward reshaped images ( 160 ) on the HDR display device. 
     Blind Local Reshaping 
     Embodiments based on the systems depicted in  FIG.  1 A  and  FIG.  1 B  may be considered to be using “global reshaping,” since the same forward reshaping function is used for remapping all pixels in a frame.  FIG.  2 A  depicts an example of an embodiment of “local reshaping,” where the encoder may apply multiple forward reshaping functions, where each of the functions is selected according to local image characteristics. 
     Compared to  FIG.  1 A , as depicted in  FIG.  2 A , there is now a new table  205  of forward mapping indices (FMI) which indicate which one of the forward reshaping functions, among a finite set of such functions, should be used for each pixel in the reference HDR image ( 120 ). Given forward mapping table  205 , forward reshaping ( 215 ) is performed as before, except that the reshaper engine ( 215 ) uses more than one forward reshaping function, as provided by unit ( 210 ), thus supporting local reshaping. To provide backwards compatibility with decoders which can&#39;t support locally-reshaped SDR images, in an embodiment, as in  FIG.  1 A , an optional unit  150  may also generate a global backward reshaping function or other metadata related to a global forward reshaping function, which can be transmitted together with the coded reshaped SDR image ( 144 ) as metadata ( 152 ). Note that the FMI array ( 205 ) does not need to be transmitted to the decoder. As will be explained later, in an example embodiment, a decoder (e.g., as depicted in  FIG.  2 B ) may apply local inverse or backward reshaping to generate a reconstructed version ( 160 ) of the input HDR image using an iterative decoding process. This type of reshaping, allowing a decoder to perform local backward reshaping without any metadata from the encoder, may be referred to as “blind” reshaping. 
     Notation 
     Given an input reference HDR ( 120 ) sequence, let its bit-depth be denoted as B v . Let the bit-depth of the corresponding reshaped SDR sequence ( 134 ) be denoted as B s . Let v t,i  denote the i-th pixel of the t-th frame in the input reference HDR signal. In an embodiment, one can collect all P pixels in the t-th frame together as an array denoted as V t . 
     Let s t,i  denote the i-th pixel in the t-th frame for a reference SDR signal. One can collect all P pixels in the t-th frame together as the vector S i . In an embodiment, without loss of generality, to facilitate our discussion, the pixel values (v t,i  and s t,i ) are not normalized (e.g. in [0, 1]) and are assumed to be their original bit depth range in this document (e.g., in [0, 2 B     v   −1] for each color plane). While methods presented herein may be discussed for a single color plane (say, luma Y), they are applicable to all available color planes in an input signal, regardless of their color space (e.g., RGB, YCbCr, and the like). 
     Denote the family of forward reshaping functions as {F &lt;l&gt; ( )|l=0, . . . , L−1}, and denote the family of backward reshaping functions as {B &lt;l&gt; ( )|l=0, . . . , L−1}, where L denotes the number of functions in each family. In an embodiment, these two families are revertible, within reasonable approximations related to quantization errors due to bit-depth differences and non-uniform intervals, thus: 
         F   &lt;l&gt; ( )= B   &lt;l&gt;   −1 ( ) l= 0, . . . , L− 1, 
         B   &lt;l&gt; ( )= F   &lt;l&gt;   −1 ( ) l= 0, . . . , L− 1.  (1)
 
     Denote as 
         M   t   =G ( V   t )  (2)
 
     the process of generating the forward-mapping indices (FMI) ( 205 ), where, elements in M i  are denoted as m t,i , where m t,i  is between 0 and L−1 and indicates the forward reshaping function to be used for the i-th pixel. 
     As mentioned earlier, since M t  is not communicated to a decoder, a decoder may use an iterative process to estimate the elements of M t  and a corresponding table (N t ) ( 240 ) with estimated backward mapping indices n t,i . For notation purposes, at the k-th iteration, denote the reshaping function selection index in the forward path as m t,i   (k)  and in the backward path as n t,i   (k) , where m t,i   (k)  and n t,i   (k)  have value between 0 and L−1. Note that both selections may not be identical owing to the precision of estimation and convergence criteria. Furthermore, in a decoder, denote the selected forward reshaping function for the i-th pixel is F m     t,i   ( ) and the selected backward reshaping function as B n     t,i   ( ). 
     Local Forward Reshaping 
     As depicted in  FIG.  2 A , in an encoder, given M t , in block  215 , the reshaped SDR signal ( 134 ) is generated as 
         ŝ   t,i   =F   m     t,i   ( v   t   ,i ).  (3)
 
     As an example, in an embodiment, without limitation, the mapping function G( ) in equation ( 2 ) to generate M t  may be expressed as 
         G ( )= G   2 ( G   1 ( )).  (4)
 
     For example, the first operator, G 1 ( ), may be the Gaussian blur operator, which when applied to the input HDR image it generates blurred pixel values 
     
       
         
           
             
               
                 
                   
                     
                       z 
                       ⁡ 
                       ( 
                       
                         m 
                         , 
                         n 
                       
                       ) 
                     
                     = 
                     
                       
                         1 
                         
                           
                             ( 
                             
                               
                                 2 
                                 ⁢ 
                                 W 
                               
                               + 
                               1 
                             
                             ) 
                           
                           2 
                         
                       
                       ⁢ 
                       
                         
                           ∑ 
                           
                             k 
                             = 
                             
                               - 
                               W 
                             
                           
                           W 
                         
                           
                         
                           
                             ∑ 
                             
                               l 
                               = 
                               
                                 - 
                                 W 
                               
                             
                             W 
                           
                             
                           
                             
                               
                                 g 
                                 1 
                               
                               ( 
                               
                                 k 
                                 , 
                                 l 
                               
                               ) 
                             
                             ⁢ 
                             
                               
                                 v 
                                 t 
                               
                               ( 
                               
                                 
                                   m 
                                   - 
                                   k 
                                 
                                 , 
                                 
                                   n 
                                   - 
                                   k 
                                 
                               
                               ) 
                             
                           
                         
                       
                     
                   
                   , 
                 
               
               
                 
                   ( 
                   5 
                   ) 
                 
               
             
           
         
       
     
     with weights defined as: 
     
       
         
           
             
               
                 
                   
                     
                       
                         g 
                         q 
                       
                       ( 
                       
                         x 
                         , 
                         y 
                       
                       ) 
                     
                     = 
                     
                       
                         1 
                         
                           2 
                           ⁢ 
                           πσ 
                         
                       
                       ⁢ 
                       
                         e 
                         
                           - 
                           
                             
                               
                                 x 
                                 2 
                               
                               + 
                               
                                 y 
                                 2 
                               
                             
                             
                               2 
                               ⁢ 
                               
                                 σ 
                                 2 
                               
                             
                           
                         
                       
                     
                   
                   , 
                 
               
               
                 
                   ( 
                   6 
                   ) 
                 
               
             
           
         
       
     
     where x and y denote the distance of the weighted pixel from the center of the filter, 2 W+1 denotes the width and height of the filter (e.g., W=12), and σ denotes the standard deviation of the blur (e.g., σ=50 for 1080p content). 
     As an example, in an embodiment, the second operator G 2 ( ) is a uniform quantizer, allocating one of the 0 to L−1 values to the output of the blur filter. 
     
       
         
           
             
               
                 
                   
                     
                       
                         G 
                         2 
                       
                       ( 
                       x 
                       ) 
                     
                     = 
                     
                       clip 
                       ⁢ 
                       3 
                       ⁢ 
                       
                         ( 
                         
                           
                             ⌊ 
                             
                               x 
                               U 
                             
                             ⌋ 
                           
                           , 
                           0 
                           , 
                           
                             L 
                             - 
                             1 
                           
                         
                         ) 
                       
                     
                   
                   , 
                 
               
               
                 
                   ( 
                   7 
                   ) 
                 
               
             
           
         
       
     
     where U denotes the quantization interval, and z=clip3(x, a, b) denotes a clipping function where 
     
       
         
           
             z 
             = 
             
               { 
               
                 
                   
                     
                       
                         a 
                         , 
                         
                           
                             if 
                             ⁢ 
                                 
                             x 
                           
                           ≤ 
                           a 
                         
                       
                     
                   
                   
                     
                       
                         b 
                         ; 
                         
                           
                             if 
                             ⁢ 
                                 
                             x 
                           
                           ≥ 
                           b 
                         
                       
                     
                   
                   
                     
                       
                         x 
                         ; 
                         
                           
                             if 
                             ⁢ 
                                 
                             a 
                           
                           &lt; 
                           x 
                           &lt; 
                           b 
                         
                       
                     
                   
                 
                 . 
               
             
           
         
       
     
     For L uniform intervals, with 2 B     v    HDR codewords, 
     
       
         
           
             
               
                 
                   U 
                   = 
                   
                     
                       
                         2 
                         
                           B 
                           v 
                         
                       
                       L 
                     
                     . 
                   
                 
               
               
                 
                   ( 
                   8 
                   ) 
                 
               
             
           
         
       
     
     In some embodiments, the uniform quantizer may be replaced by a non-uniform quantizer or some other mapping function. In some embodiments, equation ( 4 ) is not applied to any letterbox area that may be surrounding the active area of a frame. Instead, when a letterbox area is detected, a single constant value (e.g., m t,i =c, corresponding to the c-th forward reshaping function) may be applied to all the pixels in the letterbox area. In an embodiment, instead of using a blur filter one may use a low pass filter. 
     Local Backward Reshaping 
     The goal of local backward reshaping is to generate a reconstructed HDR image ( 160 ) which approximates, as close as possible, the original reference HDR image ( 120 ). In the reconstructing process, e.g., as depicted in  FIG.  2 B , one needs to estimate the forward function selection ( 225 ) and the backward function selection ( 240 ), each one associated with corresponding indices m t,i   (k)  and n t,i   (k) , where k denotes the k-th iteration in an iterative estimation process. 
     One of the convergence conditions is that both function selections need to be approximately equal, i.e. m t,i   (k) ≈n t,i   (k) ; however, satisfying this convergence condition does not necessarily imply that the reconstructed HDR image will be close to original HDR image, since any trivial constant value, such as m t,i   (k) =n t,i   (k) =constant, for all values of i, can easily satisfy such a requirement but fail to predict the correct HDR signal. In an embodiment, given that the reshaped SDR signal ( 156 ) is known, another convergence condition is to check whether a reshaped SDR image (denoted as SDR (k) ) ( 232 ) generated using the reconstructed HDR image ( 160 ) is close enough to the original input SDR image ( 156 ). Thus, if these two convergence conditions are met, the estimated HDR image should be close to the original HDR image. 
     In an embodiment, the estimation process can be formulated as an optimization problem to minimize the (weighted) sum of a) the difference between the two reshaping function selection indices; and b) the difference between the input reshaped SDR and the estimated reshaped SDR (k) . An iterative algorithm is proposed to reach this goal. In each iteration, the estimation difference from both convergence conditions is tested and if it fails the values of m t,i   (k) : and n t,i   (k)  are suitably adjusted. The steps of this iteration process are discussed with respect to both  FIG.  2 B  and the more detailed example process flow in  FIG.  3 A . 
     Step  1  ( 305 ): Initialization
         1. k=0;   2. Initialize (e.g., to a constant c=L/2) the array of backward mapping indices (BMI) {n t,i   (k) } ( 240 ) used to select the local backward reshaping functions (B &lt;l&gt; ( )).       

     Step  2  ( 310 ): Perform Local Backward Reshaping ( 220 ) 
     For each pixel ŝ t,i  in the input reshaped SDR signal ( 156 ), find the corresponding reshaping function index n t,i   (k)  and apply the corresponding backward reshaping function to generate the reconstructed HDR signal {circumflex over (v)} t,i   (k) : 
     
       
         
           
             
               
                 
                   
                     
                       v 
                       ^ 
                     
                     
                       t 
                       , 
                       i 
                     
                     
                       ( 
                       k 
                       ) 
                     
                   
                   = 
                   
                     
                       
                         B 
                         
                           n 
                           
                             t 
                             , 
                             i 
                           
                           
                             ( 
                             k 
                             ) 
                           
                         
                       
                       ( 
                       
                         
                           s 
                           ^ 
                         
                         
                           t 
                           , 
                           i 
                         
                       
                       ) 
                     
                     . 
                   
                 
               
               
                 
                   ( 
                   9 
                   ) 
                 
               
             
           
         
       
     
     The reconstructed HDR image at the k-th iteration may be expressed as vector V t   (k) . 
     Step  3  ( 315 ): Generate an estimate array of forward mapping indices (FMI) ( 225 ) based on the reconstructed HDR image. The G( ) function may be the same as the one being used by the encoder. 
         M   t   (k)   =G ( V   t   (k) ).  (10)
 
     Step  4  ( 325 ): Update the BMI array ( 240 ) based on the differences between the current estimated FMI and BMI arrays.
         1. First compute the difference between the existing estimate FMI and BMI arrays       

       Δ mn   t,i   (k)   =m   t,i   (k)   −n   t,i   (k) .  (11)
 
     and compute the average difference for an entire frame 
     
       
         
           
             
               
                 
                   
                     Δ 
                     ⁢ 
                     
                       mn 
                       t 
                       
                         ( 
                         k 
                         ) 
                       
                     
                   
                   = 
                   
                     
                       1 
                       P 
                     
                     ⁢ 
                     
                       
                         ∑ 
                         
                           i 
                           = 
                           0 
                         
                         
                           P 
                           - 
                           1 
                         
                       
                         
                       
                         
                           
                             ❘ 
                             &#34;\[LeftBracketingBar]&#34; 
                           
                           
                             Δ 
                             ⁢ 
                             
                               mn 
                               
                                 t 
                                 , 
                                 i 
                               
                               
                                 ( 
                                 k 
                                 ) 
                               
                             
                           
                           
                             ❘ 
                             &#34;\[RightBracketingBar]&#34; 
                           
                         
                         . 
                       
                     
                   
                 
               
               
                 
                   ( 
                   12 
                   ) 
                 
               
             
           
         
       
         
         
           
             2. Next, update the BMI array based on the average difference 
           
         
       
    
         n′   t,i   (k)   =n   t,i   (k)   +h (α 1   ·Δmn   t,i   (k) .  (13)
         In an embodiment, h( ) is a rounding and/or clipping function, and α 1  controls the convergence speed (e.g., α 1 =1).       

     Step  5  ( 330 ): Given the updated array of BMI values ( 240 ), perform local backward reshaping again ( 220 ). For each input reshaped SDR pixel, find the updated backward reshaping function index n′ t,i   (k)  and apply local backward reshaping ( 220 ) to obtain an updated (second) version of the reconstructed HDR signal 
     
       
         
           
             
               
                 
                   
                     
                       v 
                       ^ 
                     
                     
                       t 
                       , 
                       i 
                     
                     
                       ′ 
                       ⁡ 
                       ( 
                       k 
                       ) 
                     
                   
                   = 
                   
                     
                       
                         B 
                         
                           n 
                           
                             t 
                             , 
                             i 
                           
                           
                             ′ 
                             ⁡ 
                             ( 
                             k 
                             ) 
                           
                         
                       
                       ( 
                       
                         
                           s 
                           ^ 
                         
                         
                           t 
                           , 
                           i 
                         
                       
                       ) 
                     
                     . 
                   
                 
               
               
                 
                   ( 
                   14 
                   ) 
                 
               
             
           
         
       
     
     The updated (second) version of the reconstructed image at the k iteration may be denoted as V′ t,i   (k) . 
     Step  6  ( 335 ): Estimate a Second FMI Array ( 225 ) Based on the Updated HDR Reconstructed Signal 
         M′   t   (k)   =G ( V′   t,i   (k) ).  (15)
 
     Step  7  ( 340 ): Perform local forward reshaping ( 230 ) to obtain an estimate of the reshaped SDR image, SDR (k) , based on the estimated reconstructed HDR signal. 
     For each pixel {circumflex over (v)} t,i   (k) , find the forward reshaping function index in m′ t,i   (k)  from M′ t   (k)  and apply ( 230 ) the corresponding forward reshaping function to generate an estimated version of the reshaped SDR signal ( 232 ). 
     
       
         
           
             
               
                 
                   
                     
                       s 
                       ^ 
                     
                     
                       t 
                       , 
                       i 
                     
                     
                       ′ 
                       ⁡ 
                       ( 
                       k 
                       ) 
                     
                   
                   = 
                   
                     
                       
                         F 
                         
                           m 
                           
                             t 
                             , 
                             i 
                           
                           
                             ′ 
                             ⁡ 
                             ( 
                             k 
                             ) 
                           
                         
                       
                       ( 
                       
                         
                           v 
                           ^ 
                         
                         
                           t 
                           , 
                           i 
                         
                         
                           ′ 
                           ⁡ 
                           ( 
                           k 
                           ) 
                         
                       
                       ) 
                     
                     . 
                   
                 
               
               
                 
                   ( 
                   16 
                   ) 
                 
               
             
           
         
       
     
     Step  8  ( 345 ): Compute the Difference Between the Input SDR Reshaped Image and the Estimated SDR Reshaped Image 
     
       
         
           
             
               
                 
                   
                     
                       Δ 
                       ⁢ 
                       
                         
                           s 
                           ^ 
                         
                         
                           t 
                           , 
                           i 
                         
                         
                           ( 
                           k 
                           ) 
                         
                       
                     
                     = 
                     
                       
                         
                           s 
                           ^ 
                         
                         
                           t 
                           , 
                           i 
                         
                       
                       - 
                       
                         
                           s 
                           ^ 
                         
                         
                           t 
                           , 
                           i 
                         
                         
                           ′ 
                           ⁡ 
                           ( 
                           k 
                           ) 
                         
                       
                     
                   
                   , 
                   
 
                   
                     
                       Δ 
                       ⁢ 
                       
                         
                           s 
                           ^ 
                         
                         t 
                         
                           ( 
                           k 
                           ) 
                         
                       
                     
                     = 
                     
                       
                         1 
                         P 
                       
                       ⁢ 
                       
                         
                           ∑ 
                           
                             i 
                             = 
                             0 
                           
                           
                             P 
                             - 
                             1 
                           
                         
                           
                         
                           
                             
                               ❘ 
                               &#34;\[LeftBracketingBar]&#34; 
                             
                             
                               Δ 
                               ⁢ 
                               
                                 
                                   s 
                                   ^ 
                                 
                                 
                                   t 
                                   , 
                                   i 
                                 
                                 
                                   ( 
                                   k 
                                   ) 
                                 
                               
                             
                             
                               ❘ 
                               &#34;\[RightBracketingBar]&#34; 
                             
                           
                           . 
                         
                       
                     
                   
                 
               
               
                 
                   ( 
                   17 
                   ) 
                 
               
             
           
         
       
     
     Note that in Step  4  and in this step one may replace the L 1  error with a mean square error metric or other error metrics known in the art, such as the signal to noise ratio (SNR) or peak SNR. Such metrics are more computationally-intensive but may improve convergence speed. 
     Step  9  ( 350 ): Determine Convergence and Update the BMI Array
         1. Compute the Overall Error       

         D   t   (k)   =w   1   ·Δŝ   t   (k)   +w   2   ·Δmn   t   (k)   (18)
         where w 1 +w 2 =1 are weighting factors to weight the two types of errors. For example, if both errors are deemed equally important w 1 =w 2 =0.5.   2. If the overall error (D t   (k) ) is smaller than a threshold A (e.g., for unnormalized 10-bit data, Δ=0.5), then the decoder has converged. The current BMI array {n′ t,i   (k) } is considered the final one, and in output step  355 , the output of Step  5  ( 330 ) (equation ( 14 )) is considered the final reconstructed HDR output.   3. If D t   (k) &gt;D t   k−1  it implies one may not be able to find a better solution. The previous BMI array {n t,i   (k−1) } is considered the final one, and in output step  355  the previously generated signal       

     
       
         
           
             
               
                 v 
                 ^ 
               
               
                 t 
                 , 
                 i 
               
               
                 ′ 
                 ( 
                 
                   k 
                   ⁡ 
                   ( 
                   
                     - 
                     1 
                   
                   ) 
                 
               
             
             = 
             
               
                 B 
                 
                   n 
                   
                     t 
                     , 
                     i 
                   
                   
                     ′ 
                     ⁡ 
                     ( 
                     
                       k 
                       - 
                       1 
                     
                     ) 
                   
                 
               
               ( 
               
                 
                   s 
                   ^ 
                 
                 
                   t 
                   , 
                   i 
                 
               
               ) 
             
           
         
       
         
         
           
              is considered the final reconstructed HDR output. 
             4. Otherwise (step  360 )(D t   (k) &gt;Δ and D t   (k) &lt;D t   (k−1) ), update ( 235 ) the BMI array based on the reshaped SDR differences and return to Step  2  ( 310 ), that is: 
           
         
       
    
         k=k+ 1 
         n   t,i   (k)   =n   t,i   (k−1)   +h (α 2   ·Δŝ   t,i   (k−1) ).  (19)
 
     return to Step  2  ( 310 ), 
     where α 2  is another variable to manage convergence, (e.g., α 2 =1). 
     Compared to  FIG.  2 A , one may notice that in each iteration this process includes two separate updates of the FMI array: a) in Step  3  ( 315 ) and b) in Step  6  ( 335 ). The first time FMI array is updated, the BMI array is updated based on the error between the current BMI and FMI values (step  325 ). The second time the FMI array is updated, the decoder uses the second FMI array to generate a more accurate reshaped SDR estimate, before computing the reshaped SDR error in Step  8  ( 345 ). Experimental results have shown that such a process iterates much faster. 
     In another embodiment, this duplicate step can be eliminated to reduce complexity, but overall, convergence may be slower. This scheme is depicted in  FIG.  3 B , where Step  5  ( 330 ) and Step  6  ( 335 ) from  FIG.  3 A  are now removed. This implies, that previous Step  8  ( 345 ), to compute the reshaped SDR difference, will now be replaced by step  345 B which also computes the BMI-FMI error: 
     
       
         
           
             
               
                 
                   
                     
                       Δ 
                       ⁢ 
                       
                         mn 
                         
                           t 
                           , 
                           i 
                         
                         
                           ( 
                           k 
                           ) 
                         
                       
                     
                     = 
                     
                       
                         
                           m 
                           
                             t 
                             , 
                             i 
                           
                           
                             ( 
                             k 
                             ) 
                           
                         
                         - 
                         
                           
                             
                               n 
                               
                                 t 
                                 , 
                                 i 
                               
                               
                                 ( 
                                 k 
                                 ) 
                               
                             
                             . 
                             
 
                             Δ 
                           
                           ⁢ 
                           
                             mn 
                             t 
                             
                               ( 
                               k 
                               ) 
                             
                           
                         
                       
                       = 
                       
                         
                           
                             1 
                             P 
                           
                           ⁢ 
                           
                             
                               ∑ 
                               
                                 i 
                                 = 
                                 0 
                               
                               
                                 P 
                                 - 
                                 1 
                               
                             
                               
                             
                               
                                 
                                   
                                     ❘ 
                                     &#34;\[LeftBracketingBar]&#34; 
                                   
                                   
                                     Δ 
                                     ⁢ 
                                     
                                       mn 
                                       
                                         t 
                                         , 
                                         i 
                                       
                                       
                                         ( 
                                         k 
                                         ) 
                                       
                                     
                                   
                                   
                                     ❘ 
                                     &#34;\[RightBracketingBar]&#34; 
                                   
                                 
                                 . 
                                 
 
                                 Δ 
                               
                               ⁢ 
                               
                                 
                                   s 
                                   ^ 
                                 
                                 
                                   t 
                                   , 
                                   i 
                                 
                                 
                                   ( 
                                   k 
                                   ) 
                                 
                               
                             
                           
                         
                         = 
                         
                           
                             
                               s 
                               ^ 
                             
                             
                               t 
                               , 
                               i 
                             
                           
                           - 
                           
                             
                               s 
                               ^ 
                             
                             
                               t 
                               , 
                               i 
                             
                             
                               ( 
                               k 
                               ) 
                             
                           
                         
                       
                     
                   
                   , 
                   
 
                   
                     
                       Δ 
                       ⁢ 
                       
                         
                           s 
                           ^ 
                         
                         t 
                         
                           ( 
                           k 
                           ) 
                         
                       
                     
                     = 
                     
                       
                         1 
                         P 
                       
                       ⁢ 
                       
                         
                           ∑ 
                           
                             i 
                             = 
                             0 
                           
                           
                             P 
                             - 
                             1 
                           
                         
                           
                         
                           
                             ❘ 
                             &#34;\[LeftBracketingBar]&#34; 
                           
                           
                             Δ 
                             ⁢ 
                             
                               
                                 s 
                                 ^ 
                               
                               
                                 t 
                                 , 
                               
                               
                                 ( 
                                 k 
                                 ) 
                               
                             
                           
                           
                             ❘ 
                             &#34;\[RightBracketingBar]&#34; 
                           
                         
                       
                     
                   
                   , 
                 
               
               
                 
                   ( 
                   20 
                   ) 
                 
               
             
           
         
       
     
     where ( 340 B), SDR (k)  is given by: 
     
       
         
           
             
               
                 
                   
                     
                       s 
                       ^ 
                     
                     
                       t 
                       , 
                       i 
                     
                     
                       ( 
                       k 
                       ) 
                     
                   
                   = 
                   
                     
                       
                         F 
                         
                           m 
                           
                             t 
                             , 
                             i 
                           
                           
                             ( 
                             k 
                             ) 
                           
                         
                       
                       ( 
                       
                         
                           v 
                           ^ 
                         
                         
                           t 
                           , 
                           i 
                         
                         
                           ( 
                           k 
                           ) 
                         
                       
                       ) 
                     
                     . 
                   
                 
               
               
                 
                   ( 
                   21 
                   ) 
                 
               
             
           
         
       
     
     In addition, updating the BMI array based on the error between the current BMI and FMI difference ( 325 ) is being absorbed into step  360 B, since there is no need to update the BMI array if there is convergence. Thus, in step  360 B 
         k=k+ 1 
         n′   t,i   (k)   =n   t,i   (k−1)   +h (α 1   ·Δmn   t,i   (k−1) ).
 
         n   t,i   (k)   =n′   t,i   (k−1)   +h (α 2   ·Δŝ   t,i   (k−1) ).  (22)
 
     return to Step  2  ( 310 ), 
     where the error metrics may be computed using equation ( 20 ). 
     Now, if there is convergence (e.g., step  355 B), the current BMI array {n t,i   (k) } is considered the final one and the output of Step  2  ( 310 ) (equation ( 9 )) is considered the final reconstructed HDR output ( 160 ). 
     Constructing Local Reshaping Functions 
     The methods described so far are applicable to any type of revertible reshaping functions. In this section some specific examples of local reshaping functions and their properties will be discussed. 
     Local reshaping functions based on a global reshaping function 
     Denote the global forward and backward reshaping function as F( ) and B( ), respectively. Ideally, within a quantization error, F( )=B −1 ( ) In an embodiment, the selection of the local reshaping functions may depend on the properties of the luma pixels (e.g., their value, or a value, say mean, standard deviation, and the like, computed based on neighboring pixels). 
     In an embodiment, for the set of local reshaping functions the following properties may be desirable:
         use local reshaping to locally increase the sharpness and contrast ratio of the reshaped SDR image. This may be achieved by increasing the slope of each local forward reshaping function while compressing the global forward reshaping function in the x-axis; i.e., by reducing the width (range) of the non-flat areas of the global reshaping function in the HDR x-axis while maintaining the same range in the SDR y-axis. Denote this x-axis-compression ratio as a, where 0&lt;α&lt;1.   Maintain a constant global brightness. This may be achieved if, given an HDR codeword, each local reshaping function yields a reshaped SDR value close to the value provided by the global reshaping function.       

     Given the local forward reshaping functions, the local backward reshaping functions can be built by inverting the local forward reshaping functions. As discussed earlier, one needs to construct L forward local reshaping functions and L backward local reshaping functions. 
     For the first property mentioned above, if the x-axis compression ratio is fixed for all L forward/backward reshaping functions, one can build a template forward function, F T  ( ), and a template backward reshaping function, B T  ( ), to be used as the foundation functions. Next, one can shift the template forward reshaping function across the x-axis to generate the desired set of local forward reshaping functions. These steps are described next. 
     Step  1 . Identify Properties of the Global Reshaping Function 
     The first step is to identify the properties of the global forward reshaping function F( ), such as, its input and output range (e.g., its minimum and maximum input and output codewords), its mid value in the non-flat range, and the like. Without limitation, an example of a global forward reshaping function, mapping 16-bit HDR data ( 4 , 000  nits, PQ) to 10-bit SDR data ( 100  nits, gamma) is shown in  FIG.  4 A . As depicted in  FIG.  4 A , a typical global reshaping function has a sigmoid characteristic with two flat areas in the dark region and the highlight region due to limitations on what are considered valid input and output values. To build the template forward reshaping function, one may exclude those flat regions and only consider (scale) the regions with slope&gt;0. As an example, to identify the beginning and end points of the non-flat region, one may apply the pseudo code in Table 1, where δ denotes a very small, larger than zero, threshold, related to the numerical accuracy of our computations (e.g., δ=0.0001 for floating point operations). 
     
       
         
           
               
             
               
                 TABLE 1 
               
               
                   
               
               
                 Search for flat segments in the global reshaping function 
               
               
                   
               
             
            
               
                   
               
            
           
           
               
               
            
               
                   
                 // search for flat areas in the darks area 
               
               
                   
                 for( ν = 1; ν &lt; 2 B     V    ; ν++){ 
               
               
                   
                  if( | F (ν) − F (ν − 1) | &gt; δ ){ 
               
               
                   
                   ν L  = ν− 1; 
               
               
                   
                   break; 
               
               
                   
                  } 
               
               
                   
                 } 
               
               
                   
                 // search flat areas in the highlights area 
               
               
                   
                 for( ν = 2 B     V    − 2; ν &gt;= 0; ν−−){ 
               
               
                   
                  if( | F (ν + 1) − F (ν) | &gt; δ ){ 
               
               
                   
                   ν H  = ν + 1; 
               
               
                   
                   break; 
               
               
                   
                  } 
               
               
                   
                 } 
               
               
                   
                   
               
            
           
         
       
     
     Then, one can compute the entire valid input HDR range as: 
         v   R   =v   H   −v   L .  (23)
 
     The middle point of the valid input HDR range can be calculated as 
     
       
         
           
             
               
                 
                   
                     v 
                     M 
                   
                   = 
                   
                     
                       round 
                       ( 
                       
                         
                           
                             v 
                             H 
                           
                           + 
                           
                             v 
                             L 
                           
                         
                         2 
                       
                       ) 
                     
                     . 
                   
                 
               
               
                 
                   ( 
                   24 
                   ) 
                 
               
             
           
         
       
     
     Step  2 . Generate the Template Forward Reshaping Function 
     Given an x-axis compression ratio a, the new scaled range in HDR signal is 
         v   T,R   =┌α·v   R ┐.  (25)
 
     Owing to the ceiling operator, the value of a may be updated as 
     
       
         
           
             
               
                 
                   α 
                   = 
                   
                     
                       
                         v 
                         
                           T 
                           , 
                           R 
                         
                       
                       
                         v 
                         R 
                       
                     
                     . 
                   
                 
               
               
                 
                   ( 
                   26 
                   ) 
                 
               
             
           
         
       
     
     Then, the template forward reshaping function, F T ( ) may be constructed as depicted in Table 2. 
     
       
         
           
               
             
               
                 TABLE 2 
               
               
                   
               
               
                 Example of generating a template function based 
               
               
                 on the global reshaping function 
               
               
                   
               
             
            
               
                   
               
            
           
           
               
            
               
                 for(v = 0; v = v T,R ; v++) 
               
               
                  //find the corresponding point in original un-scaled 
               
               
                  global reshaping function 
               
               
                   
               
               
                  
         v     T   ,   g       =       v   L     +     v   α           
 
               
               
                   
               
               
                  //find two nearest integer points 
               
               
                  v L   T,g  = └v T,g ┘ 
               
               
                  v H   T,g  = ┌v T,g ┐ 
               
               
                  //find weighting factor 
               
               
                  w H   T,g  = v T,g  − v L   T,g   
               
               
                  w L   T,g  = 1 − w H   T,g   
               
               
                  //interpolated from these two integer points 
               
               
                  F T (v) = w H   T,g  · F(v H   T,g ) + w L   T,g  · F(v L   T,g ) 
               
               
                  F T (v) = clip3(F T (v), 0, 2 B     s    − 1) 
               
               
                 end 
               
               
                 //find the max and min value after the mapping 
               
               
                 F max   T  = max{F T ( )} 
               
               
                 F min   T  = min{F T ( )} 
               
               
                   
               
            
           
         
       
     
       FIG.  4 B  depicts an example of a template forward reshaping function generated based on the global forward reshaping function of  FIG.  4 A  using α=0.8. 
     Step  3 . Generate the Template Backward Reshaping Function 
     The template backward reshaping function, B T  ( ), can be reconstructed by inverting the template forward reshaping function. An example process is described in Table 3. Given, the template forward reshaping function in  FIG.  4 B ,  FIG.  4 C  presents the corresponding template backward reshaping function. 
     
       
         
           
               
             
               
                 TABLE 3 
               
               
                   
               
               
                 Example process to generate a template backwards reshaping 
               
               
                 function from the template forward reshaping function 
               
               
                   
               
             
            
               
                   
               
            
           
           
               
            
               
                 s L   T  = F T (0) 
               
               
                 s H   T  = F T (v T,R ) 
               
               
                 //construct the middle part 
               
               
                 for(s = s L   T ; s &lt;= s H   T ; s++) 
               
               
                  //find the HDR codewords which map to SDR codeword s 
               
               
                  Φ s  = {v|F T (v) = s} 
               
               
                  //compute the average of those HDR codewords 
               
               
                   
               
               
                  
           B   T     (   s   )     =       1          Φ   s            ⁢       ∑     v   ∈     Φ   s         v           
 
               
               
                   
               
               
                 end 
               
               
                 //construct the dark part 
               
               
                 for(s = 0; s &lt; s L   T ; s++) 
               
               
                  B T (s) = B T (s L   T ) 
               
               
                 end 
               
               
                 //construct the highlight part 
               
               
                 for(s = s H   T  + 1; s &lt; 2 B     s   ; s++) 
               
               
                  B T (s) = B T (s H   T ) 
               
               
                 end 
               
               
                   
               
            
           
         
       
     
     Step  4 : Generate the Family of Local Forward Reshape Functions 
     Given the template forward reshaping function and the template backward reshaping function, one can build the entire family of local reshaping functions as follows. 
     Build Shifted Version of Each Local Reshaping Function 
     Consider building L local forward reshaping functions F &lt;l&gt; ( ) and B &lt;l&gt; ( ). When m t,i =1, then the i-th HDR pixel is reshaped using the l-th forward reshaping function. In an embodiment, first one may partition the input codeword range into L uniform intervals and find the center for each interval. 
     
       
         
           
             
               
                 
                   
                     
                       I 
                       v 
                     
                     = 
                     
                       
                         2 
                         
                           B 
                           v 
                         
                       
                       L 
                     
                   
                   , 
                   
 
                   
                     
                       C 
                       l 
                       v 
                     
                     = 
                     
                       
                         round 
                         ( 
                         
                           
                             ( 
                             
                               0.5 
                               + 
                               l 
                             
                             ) 
                           
                           ⁢ 
                           
                             I 
                             v 
                           
                         
                         ) 
                       
                       . 
                     
                   
                 
               
               
                 
                   ( 
                   27 
                   ) 
                 
               
             
           
         
       
     
     Given the goal of maintaining global brightness, in an embodiment, one solution comprises to force having the same mapped value for both the original global reshaping function F (C l   v ) and the scaled-shifted version of local reshaping function F &lt;l&gt; (C l   v ) at the center of interval, C l   v . Note that a horizontal shift in a local forward reshaping function will cause a vertical shift in the corresponding local backward reshaping function. In other words, one can use this property to determine the “shift” for the l-th local reshaping function from the template function without recomputing the function. This is depicted in Table 4, where the main idea is that to generate the l-th local reshaping function based on the template function, the template forward reshaping function is shifted so that it intersects the global reshaping function at the l-th bin-center C l   v . In other words, at the l-th bin-center, the l-th local reshaping function and the global reshaping function map to the same value. Thus, to generate the l-th local forward and backward reshaping functions: 
     
       
         
           
               
             
               
                 TABLE 4 
               
               
                   
               
               
                 Example of generating a local reshaping function by shifting the 
               
               
                 template forward reshaping function to match its brightness 
               
               
                   
               
             
            
               
                   
               
            
           
           
               
            
               
                 //initialize F &lt;l&gt; ( ) for darks and highlights 
               
               
                 for(v = 0; v &lt; v M ; v++) 
               
               
                  F &lt;l&gt; (v) = F min   T   
               
               
                 end 
               
               
                 for(v = v M ; v &lt; 2 B     v   ; v++) 
               
               
                  F &lt;l&gt; (v) = F max   T   
               
               
                 end 
               
               
                 //find the matching point set 
               
               
                 Ω l   v  = {v|F(C l   v ) = F T (v)} 
               
               
                 //find the average matching point. This matching point indicates 
               
               
                 F(ϕ l   v ) = F &lt;l&gt; (ϕ l   v ) 
               
               
                   
               
               
                 
                   
                     
                       
                         
                           ϕ 
                           l 
                           v 
                         
                         = 
                         
                           round 
                           ( 
                           
                             
                               1 
                               
                                  
                                 
                                   Ω 
                                   l 
                                   v 
                                 
                                  
                               
                             
                             ⁢ 
                             
                               
                                 ∑ 
                                 
                                   v 
                                   ∈ 
                                   
                                     Ω 
                                     l 
                                     v 
                                   
                                 
                               
                               v 
                             
                           
                           ) 
                         
                       
                     
                   
                 
               
               
                   
               
               
                 //find the starting point and ending point for the shifted version 
               
               
                 a l   v  = C l   v  − ϕ l   v   
               
               
                 b l   v  = a l   v  + v T,R  − 1 
               
               
                 //copy the mapped value if not out of range 
               
               
                 If((a l   v  &gt;= 0) &amp;&amp; (b l   v  &lt; 2 B     v   )) 
               
               
                  //set valid flag 
               
               
                  ω l   v  = 1 
               
               
                  //perform copy for forward local function 
               
               
                  for(v = a l   v ; v &lt;= b l   v ; v++) 
               
               
                   F &lt;l&gt; (v) = F T (v − a l   v ) 
               
               
                  end 
               
               
                  //perform copy for backward local function 
               
               
                  for(s = 0; s &lt; 2 B     s   ; s++) 
               
               
                   
               
               
                   
           B     &lt;   l   &gt;       (   s   )     =         B   T     (   s   )     +       a   l   v       2     B   v               
 
               
               
                   
               
               
                  end 
               
               
                 else 
               
               
                  //set invalid flag if start or end points of shifter version are 
               
               
                  //out of legal codeword range 
               
               
                  ω l   v  = 0 
               
               
                 end 
               
               
                   
               
            
           
         
       
     
     For those local functions with an invalid flag (e.g., because their start or end points are outside of the valid range [0 2 B     v   )), local functions may be generated by either interpolating from the nearest local reshaping functions or by copying their nearest local reshaping function. An example of this process, without limitation, is depicted in Table 5. 
     
       
         
           
               
             
               
                 TABLE 5 
               
               
                   
               
               
                 Example of interpolating a local reshaping function from 
               
               
                 its neighbors when a valid function can&#39;t be found 
               
               
                   
               
             
            
               
                   
               
            
           
           
               
               
            
               
                   
                 for( l = 0; l &lt; L; l++) 
               
               
                   
                  // if current function is not valid 
               
               
                   
                  if( ω l   ν  == 0 ) 
               
               
                   
                   // find the nearest valid functions 
               
               
                   
                   {tilde over (l)} L  = max{{tilde over (l)} | ω l   ν  = 1, {tilde over (l)} &lt; l} // dark part 
               
               
                   
                   {tilde over (l)} H  = min{{tilde over (l)} | ω l   ν  = 1, {tilde over (l)} &gt; l} // highlight part 
               
               
                   
                   If( (l − {tilde over (l)} L ) &lt; ({tilde over (l)} H  − l) ) // dark part is closer , use dark part 
               
               
                   
                    F &lt;l&gt;  ( ) = F &lt;{tilde over (l)}     L     &gt;  ( ) 
               
               
                   
                    B &lt;l&gt;  ( ) = B &lt;{tilde over (l)}     L     &gt;  ( ) 
               
               
                   
                   else  // highlight part is closer , use highlight part 
               
               
                   
                    F &lt;l&gt;  ( ) = F &lt;{tilde over (l)}     H     &gt;  ( ) 
               
               
                   
                    B &lt;l&gt;  ( ) = B &lt;{tilde over (l)}     H     &gt;  ( ) 
               
               
                   
                   end 
               
               
                   
                  end 
               
               
                   
                 end 
               
               
                   
                   
               
            
           
         
       
     
     As an example,  FIG.  4 D  depicts four of the L=1,024 local forward reshaping functions, for α=0.8, and the original global forward reshaping function. Smaller values of a cause sharper slopes and bigger shift. The sharper slope results in higher contrast ratio. Unless one adjusts both luma and chroma, a bigger shift may distort the colors of the image, e.g., the colors may look washed out.  FIG.  4 E  depicts eight of the corresponding 1,024 local backward reshaping functions. 
     Variations and Notes 
     One of the potential issues in the proposed scale and shift-based derivation of local reshaping functions is the hard highlight/dark clipping in the local areas. As the slope becomes higher, the highlight and dark parts become saturated earlier. To avoid the early saturation issue, one can apply the following alternative solutions. 
     a) Apply Different Scale and Offset in Each Local Reshaping Function 
     In such an embodiment, for example, one may avoid scaling at the highlight and dark parts to avoid clipping. To make the transition smooth in the luminance domain, one may gradually change the scaling factor from 1 to the target value (say 0.8) from dark to mid-tones, stay a constant value at the mid-tones, and gradually increase to 1 when in the highlights part. With this approach, one can delay the early saturation issue. On the other hand, it also implies that the contrast ratio will be reduced in this approach. 
     b) Fusion of Local and Global Reshaping Functions 
     Under this embodiment, one may apply a weighted linear combination of local and global reshaping functions to move the saturation part away. The weighting factor can be a function of the luminance. When the local reshaping function is in dark or highlight part, the weights will be toward the global function; when the local function is in the mid-tone, the weights will be toward the local function. 
     Denote the weighting factors for global and local function as θ &lt;l&gt;   G  and θ &lt;l&gt;   L , where 
       θ &lt;l&gt;   G +θ &lt;l&gt;   L =1.
 
     The final fused local reshaping function can be expressed as 
         F   &lt;l&gt; ( )=θ &lt;l&gt;   L   ·F   &lt;l&gt; ( )+θ &lt;l&gt;   G   ·F   T ( ),
 
         B   &lt;l&gt; ( )=θ &lt;l&gt;   L   ·B   &lt;l&gt; ( )+θ &lt;l&gt;   G   ·B   T ( ).  (28)
 
     For example, in an embodiment, for 1=0 to L=1,023: 
     
       
         
           
             
               
                 
                   
                     θ 
                     
                       &lt; 
                       l 
                       &gt; 
                     
                     L 
                   
                   ⁢ 
                   
                     { 
                     
                       
                         
                           
                             
                               
                                 
                                   
                                     l 
                                     * 
                                     
                                       1 
                                       300 
                                     
                                   
                                   ; 
                                   
                                     
                                       for 
                                       ⁢ 
                                           
                                       0 
                                     
                                     ≤ 
                                     l 
                                     &lt; 
                                     300 
                                   
                                 
                               
                             
                             
                               
                                 
                                   1 
                                   ; 
                                   
                                     
                                       for 
                                       ⁢ 
                                           
                                       300 
                                     
                                     ≤ 
                                     l 
                                     &lt; 
                                     273 
                                   
                                 
                               
                             
                             
                               
                                 
                                   
                                     
                                       
                                         ( 
                                         
                                           - 
                                           
                                             1 
                                             300 
                                           
                                         
                                         ) 
                                       
                                       * 
                                       l 
                                     
                                     + 
                                     
                                       1023 
                                       300 
                                     
                                   
                                   ; 
                                   
                                     
                                       for 
                                       ⁢ 
                                           
                                       724 
                                     
                                     ≤ 
                                     l 
                                     ≤ 
                                     1023 
                                   
                                 
                               
                             
                           
                           . 
                           
 
                           
                             θ 
                             
                               &lt; 
                               l 
                               &gt; 
                             
                             G 
                           
                         
                         = 
                         
                           1 
                           - 
                           
                             θ 
                             
                               &lt; 
                               l 
                               &gt; 
                             
                             L 
                           
                         
                       
                       , 
                       
                         
                           for 
                           ⁢ 
                               
                           l 
                         
                         = 
                         
                           0 
                           ⁢ 
                               
                           to 
                           ⁢ 
                               
                           
                             1,023 
                             . 
                           
                         
                       
                     
                   
                 
               
               
                 
                   ( 
                   29 
                   ) 
                 
               
             
           
         
       
     
     c) Using Local Reshaping as a Sharpening Operator 
     As appreciated by the inventors, when the global reshaping function is a simple one-to-one mapping, then the set of local forward reshaping function, as constructed using the algorithms discussed earlier, may be used as a sharpening operator. Thus, in an embodiment, one may use a set of local reshaping functions for SDR to SDR mapping with the ultimate goal to improve the perceived sharpness of the transmitted SDR images 
     d) Backwards Compatibility 
     Local reshaping does not require any additional metadata, but it may require a predefined knowledge of the local forward and backward reshaping functions, or at minimum, the characteristics of a global forward reshaping and/or a global backward reshaping function, for example, as defined by metadata  152 , so that the local reshaped functions may be reconstructed locally. A legacy decoder that can&#39;t apply local backward reshaping can still apply global reshaping (e.g., as shown in  FIG.  1 B ), even though the incoming SDR signal was coded with a local reshaper. 
       FIG.  5    depicts an example summary of the process of generating a family of local reshaping functions based on a global reshaping function. As depicted in  FIG.  5   , given a global forward reshaping function ( 502 ), step  505  finds its properties (e.g., flat areas, range, and middle point). Given an x-axis scaling parameter a and the collected properties of the global forward reshaping function, in step  510 : a) generate the template forward function, and b) after the generation of the forward function, generate the corresponding template backward reshaping function. Finally, given the desired number of functions (L), and an optimization constraint, say to maintain global brightness, step  515  generates the family of local forward and backward reshaping functions based on the template forward and backward reshaping functions. 
     Example Computer System Implementation 
     Embodiments of the present invention may be implemented with a computer system, systems configured in electronic circuitry and components, an integrated circuit (IC) device such as a microcontroller, a field programmable gate array (FPGA), or another configurable or programmable logic device (PLD), a discrete time or digital signal processor (DSP), an application specific IC (ASIC), and/or apparatus that includes one or more of such systems, devices or components. The computer and/or IC may perform, control or execute instructions relating to blind local reshaping, such as those described herein. The computer and/or IC may compute, any of a variety of parameters or values that relate to blind local reshaping as described herein. The image and video dynamic range extension embodiments may be implemented in hardware, software, firmware and various combinations thereof. 
     Certain implementations of the invention comprise computer processors which execute software instructions which cause the processors to perform a method of the invention. For example, one or more processors in a display, an encoder, a set top box, a transcoder or the like may implement methods for blind local reshaping as described above by executing software instructions in a program memory accessible to the processors. The invention may also be provided in the form of a program product. The program product may comprise any non-transitory and tangible medium which carries a set of computer-readable signals comprising instructions which, when executed by a data processor, cause the data processor to execute a method of the invention. Program products according to the invention may be in any of a wide variety of non-transitory and tangible forms. The program product may comprise, for example, physical media such as magnetic data storage media including floppy diskettes, hard disk drives, optical data storage media including CD ROMs, DVDs, electronic data storage media including ROMs, flash RAM, or the like. The computer-readable signals on the program product may optionally be compressed or encrypted. 
     Where a component (e.g. a software module, processor, assembly, device, circuit, etc.) is referred to above, unless otherwise indicated, reference to that component (including a reference to a “means”) should be interpreted as including as equivalents of that component any component which performs the function of the described component (e.g., that is functionally equivalent), including components which are not structurally equivalent to the disclosed structure which performs the function in the illustrated example embodiments of the invention. 
     Equivalents, Extensions, Alternatives and Miscellaneous 
     Example embodiments that relate to blind local reshaping for HDR images are thus described. In the foregoing specification, embodiments of the present invention have been described with reference to numerous specific details that may vary from implementation to implementation. Thus, the sole and exclusive indicator of what is the invention, and what is intended by the applicants to be the invention, is the set of claims that issue from this application, in the specific form in which such claims issue, including any subsequent correction. Any definitions expressly set forth herein for terms contained in such claims shall govern the meaning of such terms as used in the claims Hence, no limitation, element, property, feature, advantage or attribute that is not expressly recited in a claim should limit the scope of such claim in any way. The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.