【问题标题】:How do I increase/decrease color saturation of an image using Jython (JES)?如何使用 Jython (JES) 增加/减少图像的色彩饱和度?
【发布时间】:2014-11-29 10:47:39
【问题描述】:

我正在尝试创建一对可以增加或减少图像整体色彩饱和度的函数。我知道“饱和度”本质上是指“远离或接近灰色”,所以我需要增加或减少 RGB 通道,但我不能平等地做它们(即 r * 2、g * 2、b * 2) 因为那只会使图像更亮。

我尝试使用此处给出的公式:http://www.georeference.org/doc/colors_as_hue_saturation_and_brightness.htm,但是当我尝试在我的代码中使用它时,图像几乎全是黑色,带有一些黄色斑点。

这是我迄今为止尝试过的:

def upSaturation(pictu):
   '''Takes a picture and increases the overall color saturation'''
   satuP = duplicatePicture(pictu)
   for pixel in getPixels(satuP):
   r = getRed(pixel)
   g = getGreen(pixel)
   b = getBlue(pixel)
   mn = min(r, g, b)
   mx = max(r, g, b)
   lht = (mx + mn) / 2
   if lht <= 128:
     satu = 255 * ((mx - mn) / (mx + mn))
     clr = makeColor(r * satu, g * satu, b * satu)
     setColor(pixel, clr)
   else:
     sat = 255 * ((mx - mn) / (511 - (mx + mn)))
     color = makeColor(r * sat, g * sat, b * sat)
     setColor(pixel, color)
 show(satuP)
 return satuP

我也尝试过只使用 makeColor(sat, sat, sat) 但那个颜色完全是黑色的,带有一些白色的斑点。我不确定此时还能做什么。非常感谢一些指导。

【问题讨论】:

    标签: image-processing colors jes jython-2.7


    【解决方案1】:

    要增加饱和度,您必须增加原色的值。例如,如果像素主要是红色,则必须增加像素的红色含量并减少其余部分。

    def upSaturation(pictu): 
    '''Takes a picture and increases the overall color saturation'''
     satuP = duplicatePicture(pictu)
     for pixel in getPixels(satuP):
      r = getRed(pixel)
      g = getGreen(pixel)
      b = getBlue(pixel)
      # check if red is primary colour
      if r > g and r > b:
       # Saturate with red
       r = r + 5
       if g < b:
         g = g - 5
       else:
         b = b - 5
    
      # check if green is primary colour
      if g > r and g > b:
       # Saturate with green
       g = g + 5
       if r < b:
         r = r - 5
       else:
         b = b - 5
    
      # check if blue is primary colour
      if b > r and b > g:
       # Saturate with blue
       b = b + 5
       if r < g:
         r = r - 5
       else:
         g = g - 5
    
     color = makeColor(r, g, b)
     setColor(pixel, color)
     explore(satuP)
     return satuP
    

    【讨论】:

      猜你喜欢
      • 2012-11-28
      • 1970-01-01
      • 2020-11-30
      • 2019-02-06
      • 2015-11-17
      • 1970-01-01
      • 2017-12-26
      • 1970-01-01
      • 2015-12-24
      相关资源
      最近更新 更多