Skip to content

Instantly share code, notes, and snippets.

@myjr52
Created February 10, 2015 14:18
Show Gist options
  • Save myjr52/64b8b80da1e2b4efedde to your computer and use it in GitHub Desktop.
Save myjr52/64b8b80da1e2b4efedde to your computer and use it in GitHub Desktop.
analyse c.elegans movement;you need the image files to run this problem; download zip compressed image files from here and extract at the same directory where the below python programme is saved. https://drive.google.com/file/d/0B5smtso7TwjrZmlRUjhKNlNQbWs/view?usp=sharing
import numpy as np
import matplotlib.pyplot as plt
from skimage.segmentation import boundaries
from scipy import ndimage
num_image = 4
fig = plt.figure(1)
for idx in range(0,num_image+1):
print(idx)
file_name = '2015_1_21(15h 2m 0s){0:04d}.tif'.format(idx)
Worm_Image = plt.imread(file_name)
max_val_img = Worm_Image.max()
plt.clf()
plt.imshow(Worm_Image)
plt.hold(True)
Worm_Image = (0.2989*Worm_Image[:,:,0]/max_val_img
+ 0.5870*Worm_Image[:,:,1]/max_val_img
+ 0.1140*Worm_Image[:,:,2]/max_val_img)
Worm_Image = boundaries.find_boundaries(Worm_Image)
Worm_Image = ndimage.binary_fill_holes(Worm_Image)
Worm_Image = boundaries.find_boundaries(Worm_Image)
Worm_Image = Worm_Image.astype('float')
bd_found = np.nonzero(Worm_Image)
x_bd = bd_found[0]
y_bd = bd_found[1]
plt.plot(y_bd,x_bd,'.')
plt.xlim([1, Worm_Image.shape[1]])
plt.ylim([1, Worm_Image.shape[0]])
plt.pause(0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment