# How can I determine the color uniformity in an image?

**URL:** <https://forum.opencv.org/t/how-can-i-determine-the-color-uniformity-in-an-image/20524>\
**Category:** Python\
**Tags:** imgproc\
**Created:** [March 14, 2025, 6:56pm UTC](https://forum.opencv.org/t/how-can-i-determine-the-color-uniformity-in-an-image/20524 "2025-03-14T18:56:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joseph\_trigos11](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@joseph\_trigos11](https://forum.opencv.org/u/joseph_trigos11)\
**Post date:** [March 14, 2025, 6:56pm UTC](https://forum.opencv.org/t/how-can-i-determine-the-color-uniformity-in-an-image/20524/1 "2025-03-14T18:56:46Z")

</div>

I’m trying to determine how uniform the color is across the top of a mandarin (the mandarin is already segmented). I’m working with the CIELAB color space. I tried a statistical analysis using standard deviation, so the mandarin with the highest standard deviation in channel A and channel B would be the least uniform mandarin. This analysis didn’t work for me. I wanted to post on this forum and find out if anyone has done similar work.  
Thank you very much for reading. I welcome any information.

```auto
 image_read = cv2.imread(image_path)
  image_rgb = cv2.cvtColor(image_read, cv2.COLOR_BGR2RGB)/255.0
  image_lab = cv2.cvtColor(image_rgb.astype(np.float32), cv2.COLOR_RGB2Lab)

  # Máscara para eliminar fondo
  gray = cv2.cvtColor(image_rgb.astype(np.float32), cv2.COLOR_RGB2GRAY)
  #Valores menores a mask. mask contiene los índices de los pixeles mayores a gray
  mask = gray > 8/255

  # Separar canales
  L, A, B = cv2.split(image_lab)

  # Filtrar con la máscara
  L_mandarina = L[mask] #Va de 0 a 100
  A_mandarina = A[mask] #Va de -128 a 127
  B_mandarina = B[mask] #Va de -128 a 127

  #Cálculo de la desviación estándar
  std_a=np.std(A_mandarina)
  std_b=np.std(B_mandarina)

```

 ![sisi](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/c/cb13e5cd33cc139d5c4cb65b72f13e90fd819e9a.png)

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 14, 2025, 8:02pm UTC](https://forum.opencv.org/t/how-can-i-determine-the-color-uniformity-in-an-image/20524/2 "2025-03-14T20:02:32Z")

</div>

you could look at each color plane and see if it’s got any value for the analysis. those spots probably show up best in the L component (speculating here). the L component’s “shape” is dominated by lighting, so you’d need to look for local differences. you could do that by running a median filter on it, then taking that as the “surface baseline”, and consider the difference between that and the unfiltered data.
