# coding: utf-8 from dect import calc_shape_corners calc_shape_corners(img) from scipy import ndimage img = ndimage.imread("/home/tpolgrabia/Pobrane/CSFID/tracks_cropped/00003.jpg") img.shape import matplotlib.pyplot as plt plt.imshow(img, cmap="Greys_r") plt.show() from skimage import filters otsu_lvl = filters.threshold_otsu(img) otsu_lvl plt.imshow(img, cmap="Greys_r") plt.show() plt.imshow(img >= otsu_lvl, cmap="Greys_r") plt.show() m = img <= otsu_lvl plt.imshow(m, cmap="Greys_r") plt.show() img_label, nb_labels = ndimage.label(m) nb_labels plt.imshow(nb_labels) plt.imshow(img_label)) plt.imshow(img_label) plt.show() sizes = ndimage.sum(m, img_label, range(0, nb_labels+1)) sizes size_min_limit = 50 remove_segments = sizes < size_min_limit remove_segments[img_label] remove_mask = remove_segments[img_label] img_label[remove_mask] = 0 plt.imshow(img_label) plt.show() import numpy as np get_ipython().magic(u'pinfo np.unique') labels = np.unique(img_label) labels get_ipython().magic(u'pinfo np.searchsorted') img_label = np.searchsorted(labels, img_label) nb_labels = len(labels) plt.imshow(img_label) plt.show() ndimage.center_of_mass(img_label, labels, nb_labels+1) ndimage.center_of_mass(img_label, labels, nb_labels+1) get_ipython().magic(u'pinfo ndimage.center_of_mass') ndimage.center_of_mass(m, img_label, labels) centers = ndimage.center_of_mass(m, img_label, labels) centers centers[0] centers[1] centers[2] centers[3] centers[4] centers[5] labels] labels labels = np.unique(img_label) labels centers = ndimage.center_of_mass(m, img_label, labels) centers centers[:,0] np.array(centers) centers = np.array(centers) centers[:,0] xs = centers[:,0] ys = centers[:,0] xs = centers[:,1] plt.imshow(m, cmap="Greys_r") plt.plot(xs, ys, "r+") plt.show() get_ipython().magic(u'logstart') get_ipython().magic(u'pwd ') help %logstart get_ipython().magic(u'pinfo %logstart') get_ipython().magic(u'logstart -o') get_ipython().magic(u'logstop') get_ipython().magic(u'logstart -o') get_ipython().magic(u'logstop') get_ipython().magic(u'logstart -o -t') get_ipython().magic(u'pwd ') get_ipython().system(u'cat ipython_log.py') pw get_ipython().magic(u'edit') get_ipython().magic(u'edit _') get_ipython().magic(u'edit dect.py') get_ipython().magic(u'edit __') get_ipython().magic(u'edit _') get_ipython().magic(u'edit _') get_ipython().magic(u'edit __') get_ipython().magic(u'edit __') get_ipython().magic(u'edit _') get_ipython().magic(u'edit test.py')