Apple's CoreImage power in the Terminal
Marc Liyanage's web site is a very-well maintainted site and a great resource for all kinds of cool terminal tricks and useful OS X software. Last week, he released a very interesting program for those of you interested in image processing. This command-line tool, called CoreImageTool, brings Apple's CoreImage framework to the Terminal. This means you can easily integrate the powerful image manipulations built into Mac OS X into your scripted workflows.
Marc Liyanage's web site offers very detailed instructions on how to install and use this tool. The syntax used by the tool is very well designed and very flexible, allowing dynamic rendering and experimentation on just a few images, of batch-processing of large collections of files. Read more below for a few examples of CoreImage filtering, using this new CoreImageTool.
For the installation, it is really best to just copy and paste the commands posted by Marc Liyanage: the program goes directly from his web site into your local disk using 'curl' (which I thought is a nice trick, skipping the usual unzip-untar-move steps). All the commands below should be in one line, but are shown broken in several lines to have them displayed properly. And my apologies if the images are not "scientific" at all, but good scientific images are rare, and even rarer on my hard drive. All the images used in the example are available at the same subpath as the ones displayed, including the texture file.
Let's start with a simple file format conversion. The MacResearch logo is a gif file, but I really like png better:
CoreImageTool load mrlogo logo.gif store mrlogo logo.png public.png
Note how you load and save image files, and how an image is given a 'name' that you then use instead of the file name, here 'mrlogo'. The available formats are basically the same as what Preview.app offers in the "Save As..." command.
It is just as easy to change the size of a picture, using the filter called 'CILanczosScaleTransform':
CoreImageTool load kids kids.jpg filter kids \
CILanczosScaleTransform scale=0.5 store kids \
kids-medium.jpg public.jpeg
The above command is actually a series of 3 manipulations:
-
load kids kids.jpg= loading the image -
filter kids CILanczosScaleTransform scale=0.5= applying the filter -
store kids kids-medium.jpg public.jpeg= storing the result
You can serialize several of these manipulations in the same command:
CoreImageTool load kids kids.jpg \
filter kids CILanczosScaleTransform scale=0.5 \
store kids kids-medium.jpg public.jpeg \
filter kids CILanczosScaleTransform scale=0.5 \
store kids kids-small.jpg public.jpeg
And you get several sizes at once:



You can apply any of the CoreImage filters listed on Apple web site, and play with them:
CoreImageTool load kids kids-medium.jpg \
load texture texture2.png \
filter kids CIGlassDistortion texture=texture:scale=15 \
store kids kids2.jpg public.jpeg
False color is often used to process astronomical and other scientific data, such as ultraviolet and x-ray images:
CoreImageTool load kids kids-medium.jpg \
filter kids CIFalseColor color0=0.8,1.0,0.1,1:color1=0.5,0.5,1,1 \
store kids kids3.jpg public.jpeg
Finding edges is useful in many scientific applications:
CoreImageTool load kids kids-medium.jpg\
filter kids CIEdgeWork radius=3.0 store kids kids4.jpg public.jpeg
CoreImageTool load kids kids-medium.jpg \
filter kids CIEdges intensity=1.0 store kids kids5.jpg public.jpeg
Adding a crystallize effect is absolutely and completely useless in all scientific applications I am aware of:
CoreImageTool load kids kids-medium.jpg \
filter kids CICrystallize radius=6.0 store kids kids6.jpg public.jpeg
And here is what you get: fun, but hopefully, also useful to advance science...






