【问题标题】:Dithering in JES/JythonJES/Jython 中的抖动
【发布时间】:2013-11-11 19:25:23
【问题描述】:

我的目标是使用 Floyd-Steinberg 方法在 JES/Jython 中抖动图像。这是我目前所拥有的:

def Dither_RGB (Canvas):
    for Y in range(getHeight(Canvas)):
        for X in range(getWidth(Canvas)):
            P     = getColor(Canvas,X,Y)
            E     = getColor(Canvas,X+1,Y)
            SW    = getColor(Canvas,X-1,Y+1)
            S     = getColor(Canvas,X,Y+1)
            SE    = getColor(Canvas,X+1,Y+1)
        return

上述代码的目标是扫描图像的像素并处理 Floyd-Steinberg 所需的相邻像素。

我难以理解的是如何计算和分配旧像素和新像素之间的 R、G、B 差异。

任何能给我指明正确方向的东西都将不胜感激。

【问题讨论】:

    标签: python jython dithering jes


    【解决方案1】:

    我对您尝试实施的方法一无所知,但对于其余部分:假设Canvas 的类型为Picture,您无法以这种方式直接获得颜色。像素的颜色可以从Pixel类型的变量中获取:

    示例:以下是从图像中获取每个像素的颜色并将它们分配到新图片中完全相同位置的过程:

    def copy(old_picture):
      # Create a picture to be returned, of the exact same size than the source one
      new_picture = makeEmptyPicture(old_picture.getWidth(), old_picture.getHeight())
    
      # Process copy pixel by pixel
      for x in xrange(old_picture.getWidth()):
        for y in xrange(old_picture.getHeight()):
          # Get the source pixel at (x,y)
          old_pixel = getPixel(old_picture, x, y)
          # Get the pixel at (x,y) from the resulting new picture
          # which remains blank until you assign it a color
          new_pixel = getPixel(new_picture, x, y)
          # Grab the color of the previously selected source pixel
          # and assign it to the resulting new picture
          setColor(new_pixel, getColor(old_pixel))
    
      return new_picture
    
    file = pickAFile()
    old_pic = makePicture(file)
    new_pic = copy(old_pic)
    

    注意:上面的例子只适用于你想处理一张新图片而不修改旧图片的情况。如果您的算法需要在执行算法时动态修改旧图片,则最终的setColor 将直接应用于原始像素(不需要新图片,return 语句也不需要)。

    从这里开始,您可以通过操作像素的 RGB 值来计算您想要的任何东西(使用应用于 Pixelcol = makeColor(red_val, green_val, blue_val) 并使用setColor(a_pixel, col) 将返回的颜色应用于像素)。


    RGB 操作示例here

    其他一些here,尤其是here

    【讨论】:

    • 请注意,通过在stackoverflow的搜索引擎中指定标签[jes](带括号)可以获得一些非常有用的JES资源/示例...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多