Created
April 3, 2013 17:51
-
-
Save automata/5303516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from PIL import Image, ImageFilter, ImageOps | |
from scipy import ndimage, fftpack | |
import pylab as p | |
import numpy as n | |
import imtools | |
import pickle as pk | |
from skimage.morphology import watershed, is_local_maximum, medial_axis, disk, convex_hull_image | |
from skimage.segmentation import * | |
from skimage.util import img_as_float | |
from skimage.filter import canny, threshold_otsu, rank | |
from scipy.misc import imsave | |
from sklearn.feature_extraction import image | |
from sklearn.cluster import spectral_clustering | |
import matplotlib.pyplot as plt | |
NUM_PINTURAS = 1 | |
# artistas = ['Pollock', 'Picasso', | |
# 'Miro', 'Gogh', 'Kandinsky', 'Matisse', | |
# 'Poussin', 'Caravaggio', 'Hals', 'Rembrandt', 'Velazquez', | |
# 'Vermeer'] | |
for teste in xrange(1,11): | |
# abre a imagem | |
im_rgb = Image.open('valida_convexhull/%s.jpg' % teste) | |
im_cinza = im_rgb.convert('L') | |
# equaliza | |
#im_eq = ImageOps.equalize(im_cinza) | |
### FILTRAGEM | |
# filtro media | |
#im_media = Image.fromarray(ndimage.median_filter(im_eq, size=3)) | |
im_binaria = 255.*(n.array(im_cinza)>128) | |
im_binaria[im_binaria == 255] = 1 | |
# calculamos o convex hull | |
convex = convex_hull_image(im_binaria) | |
# area original do segmento | |
Aor = n.sum(im_binaria) | |
# area do convex hull | |
Ac = n.sum(convex) | |
print Aor, Ac, float(Aor) / Ac | |
#plt.clear() | |
plt.imshow(convex, cmap=plt.cm.gray, interpolation='nearest') | |
plt.savefig('valida_convexhull/%s_convex.png' % teste) | |
plt.imshow(im_binaria, cmap=plt.cm.gray, interpolation='nearest') | |
plt.savefig('valida_convexhull/%s_orig.png' % teste) | |
#plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment