迭代图像像素并修改它们

时间:2015-12-10 20:35:22

标签: python-imaging-library pixel

我正在尝试以光栅模式移动像素范围(32x32)到256x256图像。我为此定义了一个函数。我正在使用PIL

你能帮我吗?

from PIL import Image
import sys
import os
from Crypto.Cipher import AES
from collections import deque
import numpy as np 
import numpy as numpy
from scipy.sparse import csr_matrix
from pylab import *

使用这些库我已经完成了以下功能。

def raster_SCAN(img_re,pixel_1,num_scan):
img_w,img_h=img_re.size
for j in range(0,num_scan):
    img_2=img_re
    pixel_2=img_re.load()
    for i in range(8):    # for every block of pixels:
        for j in range(8):
            print(i,j)
            if i==1 & j==1:
                pixel_1 [i:(i+1)*32,j:j*32] = pixel_2[224:256,224:256] # set the colour accordingly
            if i<8 & j<8 & i!=1 & j!=1:
                pixel_1[(i-1)*32:i*32,j:j*32] = pixel_2[(i-2)*32:(i-1)*32,(j-2)*32:(j-1)*32]
            if i==1& j!=1:
                pixel_1[i:i*32,(j-1)*32:j*32] = pixel_2[224:256,(j-2)*32:j*32]
            if i==8 & j==8:
                pixel_1[224:256,224:256] = pixel_2[1:32,1:32] 
return pixel_1  

0 个答案:

没有答案