def analyse_shape_at_time(t): img = exp.load_img(t = t); pos_center, pos_head, pos_tail, curvature_mean, curvature_variation, line_center, line_left, line_right = analyse_shape(img, verbose = True, save = figfile % t); ldat = np.load(linefile, mmap_mode = 'r+'); ldat[t,0,:,:] = line_center; ldat[t,1,:,:] = line_left; ldat[t,2,:,:] = line_right; #ldat.close(); pdat = np.load(posfile, mmap_mode = 'r+'); pdat[t,0,:] = pos_center; pdat[t,1,:] = pos_head; pdat[t,2,:] = pos_tail; #pdat.close(); cdat = np.load(curfile, mmap_mode = 'r+'); cdat[t,0] = curvature_mean; cdat[t,1] = curvature_variation;
""" Created on Wed Jun 29 16:16:00 2016 @author: ckirst """ import cv2 import matplotlib.pyplot as plt import numpy as np import skimage.feature as ftr import experiment as exp; img = exp.load_img(t = 529204) #img = exp.load_img(t = 500017) t = 0; t = t + 1; img = exp.load_img(t = 529204 + t) #img = cv2.medianBlur(img,5); img = cv2.GaussianBlur(img, (5,5), 1); #dx = cv2.Sobel(img, sobel_x, 1, 0, 3); #dy = cv2.Sobel(img, sobel_y, 0, 1, 3);
plot_body_line(tstart = 500000, tend = 500004, dt = 1) plt.figure(300); plt.clf(); nts = 4; cc = cm.Blues; lines = np.load(linefile, mmap_mode = 'r'); poss = np.load(posfile, mmap_mode = 'r'); xy = exp.load(wid = wid); for ti in range(nts): plt.subplot(2,nts,ti+1); tt = 500000 + ti; img = exp.load_img(t = tt); plt.imshow(img, cmap = 'gray', interpolation = 'nearest') cl = lines[tt,0,:,:]; label = "%s\n%s\n%s" % (str(poss[tt, 0,:]), str(xy[tt,:]), str(np.round(xy[tt,:]))); plt.plot(cl[0,:], cl[1,:], color = 'red'); if ti > 0: plt.subplot(2,nts,ti); plt.plot(cl[0,:], cl[1,:], color = 'blue'); plt.subplot(2,nts,ti+nts+1); img2 = exp.load_img(t = tt-1); plt.imshow(np.asarray(img, dtype = float)-img2, cmap = 'jet', interpolation = 'nearest') plt.title(label)
import imageprocessing.active_worm as aw; import experiment as exp import scipy.ndimage.filters as filters from scripts.analyse_wormshape import analyse_shape from skimage.filters import threshold_otsu ### Test phi error - move reload(aw); # load image img = exp.load_img(wid = 80, t= 513466); imgs = filters.gaussian_filter(np.asarray(img, float), 1.0); #imgs[imgs < 60] = 60; imgs = imgs - imgs.max(); threshold_level = 0.95; level = threshold_level * threshold_otsu(imgs); mask = imgs < level; phi = aw.mask2phi(mask); ws = aw.WormModel(); ws.from_image(imgs); ws.widen(0.75);
import copy import imageprocessing.active_worm as aw import experiment as exp import scipy.ndimage.filters as filters from scripts.analyse_wormshape import analyse_shape from skimage.filters import threshold_otsu ### Test phi error - move reload(aw) # load image img = exp.load_img(wid=80, t=513466) imgs = filters.gaussian_filter(np.asarray(img, float), 1.0) #imgs[imgs < 60] = 60; imgs = imgs - imgs.max() threshold_level = 0.95 level = threshold_level * threshold_otsu(imgs) mask = imgs < level phi = aw.mask2phi(mask) ws = aw.WormModel() ws.from_image(imgs) ws.widen(0.75)
ws2 = copy.deepcopy(ws) ws2.bend(0.5, exponent=10, head=True) plot_worms(ws, ws2) ws2 = copy.deepcopy(ws) ws2.bend(0.5, exponent=5, head=False) plot_worms(ws, ws2) ### Generate from image reload(aw) import experiment as exp import scipy.ndimage.filters as filters # load image img = exp.load_img(wid=80, t=500000) imgs = filters.gaussian_filter(np.asarray(img, float), 1.0) ws = aw.WormModel() ws.from_image(imgs, verbose=True) plt.figure(1) plt.clf() ws.plot(image=imgs) ### Self intersections ws = aw.WormModel(theta=np.hstack( [np.linspace(0.1, 0.8, 10), np.linspace(0.9, 0.1, 11)]), length=150)
import numpy as np import matplotlib.pyplot as plt import experiment as exp import scipy.ndimage.morphology as morph from skimage.filters import threshold_otsu import scipy.ndimage.filters as filters from scipy.interpolate import splprep, splev from imageprocessing.active_contour import chanvese import cv2 img = exp.load_img(t=408000); #plt.figure(10); plt.clf(); #plt.imshow(img, cmap = 'gray', clim = (0,256), interpolation="nearest"); #plt.figure(11); plt.clf(); #plt.hist(img.flatten(), bins = 256); ## smooth image -> contour from plt imgs = filters.gaussian_filter(np.asarray(img, float), 1); plt.figure(12); plt.clf(); plt.subplot(1,3,1) plt.imshow(img, interpolation ='nearest') plt.subplot(1,3,2)
# -*- coding: utf-8 -*- """ Created on Thu Jun 9 09:23:59 2016 @author: ckirst """ import time import numpy as np import matplotlib.pyplot as plt import experiment as exp plt.figure(1); plt.clf(); img = exp.load_img(t=100000); plt.imshow(img, cmap = 'gray') #animate movie fig, ax = plt.subplots(1,2) img = exp.load_img(t=100000)[30:120, 30:120]; img2 =exp.load_img(t=100000+1)[30:120, 30:120]; figimg = ax[0].imshow(img, cmap = 'gray', clim = (0,256), interpolation="nearest"); delta = np.asarray(img2, dtype = float) - np.asarray(img, dtype = float) figimg2 = ax[1].imshow(delta, cmap = 'jet', clim = (-30,60), interpolation="nearest"); plt.show(); for t in range(200000, 300000): img = img2; img2 = exp.load_img(t=t+1)[30:120, 30:120];
# -*- coding: utf-8 -*- """ Created on Wed Jun 29 16:16:00 2016 @author: ckirst """ import cv2 import matplotlib.pyplot as plt import numpy as np import skimage.feature as ftr import experiment as exp img = exp.load_img(t=529204) #img = exp.load_img(t = 500017) t = 0 t = t + 1 img = exp.load_img(t=529204 + t) #img = cv2.medianBlur(img,5); img = cv2.GaussianBlur(img, (5, 5), 1) #dx = cv2.Sobel(img, sobel_x, 1, 0, 3); #dy = cv2.Sobel(img, sobel_y, 0, 1, 3); from scipy import ndimage
# -*- coding: utf-8 -*- """ Created on Tue Jun 28 17:00:11 2016 @author: ckirst """ import numpy as np import experiment as exp import scipy.ndimage.filters as filters from skimage.filters import threshold_otsu # load image img = exp.load_img(wid = 80, t= 529204); img = exp.load_img(wid = 80, t= 529218); imgs = filters.gaussian_filter(np.asarray(img, float), 1.0); threshold_level = 0.95; level = threshold_level * threshold_otsu(imgs) import numpy as np from numpy import ma import matplotlib as mpl import matplotlib._contour as _contour _mask = None;
ws2.bend(0.5, exponent = 10, head = True); plot_worms(ws, ws2); ws2 = copy.deepcopy(ws); ws2.bend(0.5, exponent = 5, head = False); plot_worms(ws, ws2); ### Generate from image reload(aw); import experiment as exp import scipy.ndimage.filters as filters # load image img = exp.load_img(wid = 80, t= 500000); imgs = filters.gaussian_filter(np.asarray(img, float), 1.0); ws = aw.WormModel(); ws.from_image(imgs, verbose = True); plt.figure(1); plt.clf(); ws.plot(image = imgs) ### Self intersections ws = aw.WormModel(theta = np.hstack([np.linspace(0.1, 0.8, 10), np.linspace(0.9, 0.1, 11)]) , length = 150); mask = ws.mask(); phi = ws.phi();
else: tag = '' tagfunc = tag_from_function( function=self.function, with_default_parameter=self.with_default_parameter, parameter=self.parameter, **kwargs) return tag_join(tag, tagfunc) def run(self, data=None): """Run the analysis""" img = exp.load_img(t=408000) #plt.figure(10); plt.clf(); #plt.imshow(img, cmap = 'gray', clim = (0,256), interpolation="nearest"); #plt.figure(11); plt.clf(); #plt.hist(img.flatten(), bins = 256); ## smooth image -> contour from plt imgs = filters.gaussian_filter(np.asarray(img, float), 1) plt.figure(12) plt.clf() plt.subplot(1, 3, 1) plt.imshow(img, interpolation='nearest') plt.subplot(1, 3, 2)
# -*- coding: utf-8 -*- """ Created on Thu Jun 30 17:43:48 2016 @author: ckirst """ import matplotlib.pyplot as plt import numpy as np import scipy.ndimage.filters as filters import experiment as exp; img = exp.load_img(t = 529204) imgs = filters.gaussian_filter(np.asarray(img, float), 1.0); imgdata = imgs.flatten(); imgdata.shape = (imgdata.shape[0], 1); plt.figure(1); plt.clf(); plt.hist(imgdata[:,0], 256) ### fit mixture of tw gaussians to it from sklearn import mixture clf = mixture.GMM(n_components=3, covariance_type='full', n_init = 15, verbose = 2) clf.fit(imgdata)
# -*- coding: utf-8 -*- """ Created on Thu Jun 9 09:23:59 2016 @author: ckirst """ import time import numpy as np import matplotlib.pyplot as plt import experiment as exp plt.figure(1) plt.clf() img = exp.load_img(t=100000) plt.imshow(img, cmap='gray') #animate movie fig, ax = plt.subplots(1, 2) img = exp.load_img(t=100000)[30:120, 30:120] img2 = exp.load_img(t=100000 + 1)[30:120, 30:120] figimg = ax[0].imshow(img, cmap='gray', clim=(0, 256), interpolation="nearest") delta = np.asarray(img2, dtype=float) - np.asarray(img, dtype=float) figimg2 = ax[1].imshow(delta, cmap='jet', clim=(-30, 60), interpolation="nearest") plt.show()