~/image/e5 で演習
# -*- coding: utf-8 -*- import Image import scipy import scipy.fftpack as fft # 画像の読み込みと FFT im = Image.open('e5sample1.pgm') f = scipy.array(im.getdata()) L = im.size[0] f.shape = (L,L) F = fft.fft2(f) # 波数空間でのフィルターの作成 U = 1./4 UL = int(L*U) G = scipy.array([1.0]*(UL/2)+[0.0]*(L-UL+1)+[1.0]*(UL/2-1)) G = scipy.outer(G,G) # フィルターの適用と逆FFT F = F * G f = fft.ifft2(F) # 画像データに変換 fimg = Image.new('L', (L,L)) d = [int(f[x][y].real) for x in range(L) for y in range(L)] fimg.putdata(d) fimg.show()
import Image import ImageFilter img = Image.open('e5sample1.pgm') # 5x5, all 1 flt = ImageFilter.Kernel((5,5), [1]*25) imgx = img.filter(flt) imgx.show()
import Image import ImageFilter img = Image.open('e5sample1.pgm') # HPF (1-5x5LPF) flist = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1] flt = ImageFilter.Kernel((5,5), flist, offset=128) imgx = img.filter(flt) imgx.show()
|-1 0 1| |-2 0 2| |-1 0 1|
import Image import ImageFilter img = Image.open('e5sample2.pgm') # differrentiate flist = [-1, 0, 1, -2, 0, 2, -1, 0, 1] flt = ImageFilter.Kernel((3,3), flist, scale=1, offset=128) imgx = img.filter(flt) imgx.show()
import Image import ImageFilter img = Image.open('e5sample2.pgm') imgx = img.filter(ImageFilter.FIND_EDGES) imgx.show()