1

I am using these functions to modify the values of brightness, contrast and sharpness. My default values are 128, 24, 4 respectively. I extracted these values. I don't know how to extract the value of the color to modify it in the same way.

import numpy as np
import cv2
import matplotlib.pyplot as plt
from PIL import Image, ImageEnhance

def brightness_enhancer(img, br):
 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
 img = Image.fromarray(img)
 enhancer = ImageEnhance.Brightness(img)
 factor = 128/br
 return enhancer.enhance(factor)

def contrast_enhancer(img, ct):
 #img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
 #img = Image.fromarray(img)
 enhancer = ImageEnhance.Contrast(img)
 factor = 24/ct
 return enhancer.enhance(factor)

def sharpness_enhancer(img, sh):
 #img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
 #img = Image.fromarray(img)
 enhancer = ImageEnhance.Sharpness(img)
 factor = 4/sh
 return enhancer.enhance(factor)

def color_enhancer(img):
 #img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
 #img = Image.fromarray(img)
 enhancer = ImageEnhance.Color(img)
 factor = 0.5 #enhancement of the image
 return enhancer.enhance(factor)
martineau
  • 119,623
  • 25
  • 170
  • 301
  • What are you actually trying to do, please? You don't call or use any of the functions you have defined. You seem to be mixing up PIL with OpenCV - why would you do that? I'm not criticising, just trying to understand so I, and others can assist you better. Thank you. – Mark Setchell Mar 28 '22 at 17:31
  • My only request is to understand how I can extract the value of "Color", which belongs to PIL library. This to handle it, so I can obtain yellowed images. The script is only to see my functions. I obtained the values for sharpness, contrast and brightness from other functions . But I don't know how to extract that particular "color" value which can be manipulate by the function "ImageEnhance.Color". I used previously CV2 for other image processings. – Andrea Vergine Mar 28 '22 at 18:31
  • Maybe the correct request is: HOW CAN I EXTRACT A SINGLE VALUE REFERRED TO THE SATURATION OF THE IMAGE? – Andrea Vergine Mar 28 '22 at 18:41
  • Should I convert RGB image into HSV image and then obtain the mean value of the saturation between all pixels? – Andrea Vergine Mar 28 '22 at 18:47
  • Sorry, I really can't deduce what you are trying to do. You show 4 functions, you call none of them and you want to what the saturation of some unspecified image is? – Mark Setchell Mar 28 '22 at 19:01
  • saturation = hsv_img[:,:,1] np.mean(saturation) – Andrea Vergine Mar 28 '22 at 19:03
  • Is this the correct way to extract the average saturation of an image? – Andrea Vergine Mar 28 '22 at 19:03
  • It's probably correct but you haven't said what you are trying to achieve yet, so it is potentially not of much use to you. – Mark Setchell Mar 28 '22 at 19:08
  • I have a dataset composed of images and I have to equalize images so I can compare them – Andrea Vergine Mar 29 '22 at 14:02

0 Answers0