Created
March 11, 2019 08:31
-
-
Save jborbely/10f713666c88dc16ab2a4e99b43edfb2 to your computer and use it in GitHub Desktop.
interacting with ImageJ from Python
This file contains hidden or 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
| """ | |
| Creates a movie of an image that starts off blurry and gradually comes into focus. | |
| """ | |
| from msl.loadlib import LoadLibrary | |
| jar = LoadLibrary('ij.jar') | |
| ij = jar.lib.ij | |
| def make_movie(url=None, start_sigma=30, nframes=100, fps=24): | |
| if url is None: | |
| url = 'http://wsr.imagej.net/images/lena-std.tif' | |
| opener = ij.io.Opener() | |
| img = opener.openImage(url) | |
| stack = ij.ImageStack(img.getWidth(), img.getHeight()) | |
| gb = ij.plugin.filter.GaussianBlur() | |
| sigmas = [start_sigma * i / float(nframes) for i in range(nframes, -1, -1)] | |
| for sig in sigmas: | |
| print('blurring with a sigma of {}'.format(sig)) | |
| imp = img.duplicate().getChannelProcessor() | |
| gb.blurGaussian(imp, sig) | |
| stack.addSlice(imp) | |
| new_filename = '{}-{}-{}-{}'.format(img.getTitle().rsplit('.', 1)[0], start_sigma, nframes, fps) | |
| imp = ij.ImagePlus(new_filename, stack) | |
| print('Saving AVI...') | |
| ij.IJ.run(imp, 'AVI... ', 'compression=JPEG frame={} save={}.avi'.format(fps, new_filename)) | |
| make_movie() | |
| jar.gateway.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment