dusty-nv / jetson-utils

C++/CUDA/Python multimedia utilities for NVIDIA Jetson
MIT License
737 stars 289 forks source link

Add / Multiply pixels in CUDA image #192

Open firststep-dev opened 10 months ago

firststep-dev commented 10 months ago

@dusty-nv - How would I add a fixed value, or multiply the value of each pixel in an image, in CUDA?

In CV2, I would so the following:

def process_image_add(file_path, additional_value=10):
    img = Image.open(file_path)
    img_array = np.array(img, dtype=np.uint16)
    brightened_array = img_array + additional_value
    brightened_array = np.clip(brightened_array, 0, 255).astype(np.uint8)
    brightened_img = Image.fromarray(brightened_array)
    return brightened_img
def brighten_image_multiply(file_path, multiplication_factor=1.2):
    img = Image.open(file_path)
    img_array = np.array(img, dtype=np.uint16)
    brightened_array = img_array * multiplication_factor
    brightened_array = np.clip(brightened_array, 0, 255).astype(np.uint8)
    brightened_img = Image.fromarray(brightened_array)
    return brightened_img