1. A method of processing a quantized input image, comprising: detecting if a selected pixel in the quantized image belongs to a ramp area in each of multiple pre-defined directions by comparing luminance of pixels in the pre-defined directions to a threshold, wherein the threshold is determined based on luminance values of pixels in the pre-defined directions; if the selected pixel belongs to a ramp area, dynamically selecting a quantization level for each of the pre-defined directions based on the corresponding detection comparison results; refining the selected pixel based on the selected quantization levels by determining a gain value based on the neighboring pixel differences along a selected direction within a refined segment and further based on a ratio of: sign changes of the neighboring pixel differences along the pre-defined directions within the refined segment, and pixels within the refined segment.