简体   繁体   中英

OpenCV saturation adjustment gives very bad results

I'm experimenting with saturation adjustments in OpenCV. A standard approach to the problem is to convert input image from BGR(A) to HSV colour space and simply adjust the S channel like so:

# Convert from BGR to HSV
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

# We want to increase saturation by 50
value = 50

# Grab saturation channel
saturation = hsv[..., 1]

# Increase saturation by a given value
saturation = cv2.add(saturation, value)

# Clip resulting values to fit within 0 - 255 range
np.clip(saturation, 0, 255)

# Put back adjusted channel into the HSV image
hsv[..., 1] = saturation

# Convert back from HSV to BGR
cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)

Below is the input image I am working with and the result of the above operations. You can clearly see that something is terribly off with low frequency areas as well with highlights.

Perhaps there is another approach to solve the problem without producing such blockiness?

PS The blockiness is not a result of JPEG compression as the artefact blocks do not fit into the standard JPEGs 8x8 coding units. Also, I've confirmed the problem persists on the lossless PNG as both input and output format.

Before: 之前的单纯疱疹病毒

After: HSV 之后

I suggest another approach using black and white version of the picture, it worked best for me:

Just sum the picture with the b/w version with coefficient that give 1 in sum. Alpha is the saturation parameter: alpha = 0 gives b/w picture, higher alpha gives more saturated picture. C++ code example:

addWeighted(image, alpha, black_and_white(image), 1 - alpha, 0.0, res);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM