# -*- coding: utf-8 -*- """ Spyder Editor This temporary script file is located here: C:\Documents and Settings\student\.spyder2\.temp.py """ from pylab import * from Image import * from numpy import * from scipy import ndimage img = asarray(open("wonsz.jpg").convert("L")) binary = img > 128 a = zeros((3,3)) structs = [ ndimage.generate_binary_structure(2, 1), ndimage.generate_binary_structure(2, 2) ] i = 1 for struct in structs: for j in range(1, 10, 3): dilation = ndimage.binary_dilation(binary, iterations=j,structure=struct).astype(binary.dtype) erosion = ndimage.binary_erosion(binary, iterations=j,structure=struct).astype(binary.dtype) opening = ndimage.binary_opening(binary, iterations=j,structure=struct).astype(binary.dtype) closing = ndimage.binary_closing(binary, iterations=j,structure=struct).astype(binary.dtype) openingclosing = ndimage.binary_closing(opening, iterations=j,structure=struct).astype(binary.dtype) figure(i) subplot(3,2,1) imshow(binary, cmap="gray", vmin=0, vmax=1) title("BASE") subplot(3,2,2) imshow(dilation, cmap="gray", vmin=0, vmax=1) title("DYLATACJA") subplot(3,2,3) imshow(erosion, cmap="gray", vmin=0, vmax=1) title("EROZJA") subplot(3,2,4) imshow(opening, cmap="gray", vmin=0, vmax=1) title("OTWARCIE") subplot(3,2,5) imshow(closing, cmap="gray", vmin=0, vmax=1) title("ZAMKNIECIE") subplot(3,2,6) imshow(openingclosing, cmap="gray", vmin=0, vmax=1) title("OTWARCIE + ZAMKNIECIE") i+=1 suptitle("ITERATIONS = " + str(j)) tight_layout() subplots_adjust(top=0.88) show()