Photoshop + MATLAB
14 March 2009
As a researcher who works with digital images, I have two programs
open all day long: Photoshop and MATLAB. Since Photoshop CS3 came out about two
years ago, I have been increasingly using both programs together. I frequently
send images to Photoshop from MATLAB and also read images back into MATLAB from
Photoshop. In this post, I give a demonstration of some of my favorite ways to
use these programs together.
Navigation
Not surprisingly, Photoshop has a great set of tools for navigating around
images. Once you know the keyboard shortcuts, you can quickly zoom-in to a
specific region or zoom out to see the entire image. You can also move around
at a set zoom level by dragging the red box in the Navigator pane. You can
certainly show images and zoom within MATLAB, but I find Photoshop’s tools to be
more comfortable to use. I also like to toggle between the color channels and
check the histogram.
Layers
For many image processing algorithms, the output can be viewed as an image. For
example, in a segmentation task, the labels can be converted to grayscale values.
In such cases, it is useful to overlay the result and original image to visually
compare the two images at every pixel. Photoshop’s layers are a natural way to
create overlays.
The two commands for opening a set of images in layers are
psnewdocmatrix and psnewlayermatrix. I find it useful
to toggle layer visibility and to change the opacity of the layers.
In recent projects, I have also been sending all intermediary results to
separate layers and saving the psd file as a record of the full
algorithm. As the code changes, I can judge improvements by loading the
psd files of past results.
Masks
In this clip, I show how to make a quick mask. The image can be any image in
your MATLAB workspace, though if it is double-precision, you may want to convert
it to an 8-bit image with im2uint8 before sending it to Photoshop.
The basic steps are:
psnewdocmatrix: Create a new Photoshop document from an image in
the MATLAB workspace.- New Layer: Make a new layer for the mask
- Edit→Fill: Fill the layer with black
- Quick Selection Tool: Select the object with a few strokes
- Edit→Fill: Fill the selection with white
psgetpixels: Read the pixels of the visible layer back into
MATLAB