简体   繁体   中英

Is there any way to manipulate an image using a color curve in python?

I have a series of tif images and was wondering if there is a possibility to write something in python (using maybe scikit-image or OpenCV) to apply a color curve. The data I have looks like the following, where we have a list of x, y, x, y... data like so: (0, 0, 32, 22, 64, 56, 128, 128, 192, 196, 255, 255).

在此处输入图片说明

With the new information you provided I think that the following code should do the trick. lut_in is the vector of input gray levels and lut_out the desired output level. Here it's applied for all 3 channels (like in photoshop). The only thing you need is the interpolation to have a LUT (look up table) of 256 elements, that fits the 256 gray levels of the input. You can apply the same method for other color resolutions.

import cv2
import numpy as np

image = cv2.imread('apple.jpg')

lut_in = [0, 127, 255]
lut_out = [0, 80, 255]

lut_8u = np.interp(np.arange(0, 256), lut_in, lut_out).astype(np.uint8)
image_contrasted = cv2.LUT(image, lut_8u)

cv2.imwrite('apple_dark.jpg', image_contrasted)

Input:
在此处输入图片说明
Output:
在此处输入图片说明

In the comments, some already gave answers on how to apply a color LUT to an image. However when I read your question, I have the impression that you would like to have in fact a 2D colormap, where the color depends on two parameters. If this is the case, I would recommend to visit this post or this one . Hope this helps!

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