Right. Having broken my avi file into pngs, how do I keep track of an object in the vid? Check this out to see what I mean:
I’m not sure what the tapping of the finger is about (at the start of the vid), but I have data from the experiment which I’d like to correlate to the position of the finger on the rig. the idea is to follow that black blob.
Having broken the vid into png images, I loaded them into python using PIL:
from PIL import Image
images = [Image.open('./tmp/'+f) for f in imagenames]
and then made them into numpy arrays, slicing off only the red channel and the middle part of the image(by inspection, the dot was most visible on the red channel):
images = [np.asarray(image)[upper:lower,:,0] for image in images]#0 indexes red
Now, scipy.ndimage has an awesome tool for identifying regions of an image. I used a threshold (set by inspection) first:
images = [image<threshold for image in images] regions = [scipy.ndimage.label(image)[0] for image in images]#[0]:region info. only
Each of the ‘regions’ then is a numpy array of the same size and shape as the images, but with 0’s in the biggest region, 1s in the next biggest, etc. I wrote a simple set of rules to cut out the unwanted regions, and calculated the center of the remaining region. there are occasions where two or more regions pass my simple set of rules, in this case I look at the region identified in the previous image in an attempt to ‘track’ the blob. Crude, but works okay.
I subplotted various stages in the process and stitches the plots together to make this vid:
the top image is the (sliced) original image, with a green dot where I think the block pen mark is. The middle plot is a pylab.imshow() of the regions, and the final subplot is the same after applying my set of rules.
Thanks to Sarah T. for letting me post the videos.
Edit: corrected some code