我的目标是使用方法在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所需的相邻像素。
我很难理解的是如何计算和分配旧像素和新像素之间R,G,B的差异。
任何能为我指明正确方向的东西都将不胜感激。
发布于 2013-11-02 10:22:33
我对您试图实现的方法一无所知,但是对于其他的方法:假设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值(使用应用于col = makeColor(red_val, green_val, blue_val)的setRed()、setGreen()和setBlue()函数,并使用setColor(a_pixel, col)将返回的颜色应用到像素)来计算任何想要的颜色。
RGB操作的示例
,其他一些, here ,特别是
https://stackoverflow.com/questions/19712454
复制相似问题