3
Tutorials
iVision has a lot of capability. You may need to tap only a portion of its power now, but after you get further involved in
image processing and analysis, you may want to “go deeper.” This manual is designed to get you started as soon as
possible. By working through the tutorials, you will get a feel for the power of iVision, even if you do not need all its
features right now.
It is best to do the tutorials in order. Some items in the later tutorials depend on techniques you would have learned in the
earlier ones. However if you feel comfortable with Macintosh applications software, feel free to skip around. You may
have to refer to the Menu Reference section of this manual to fill in details on some commands that were discussed in the
tutorials you skipped.
3.1
Tutorial 1: Getting Started
3.1.1
Start iVision and Open an Image
This is an easy tutorial just to get started. First you must start iVision. There are actually several ways to do this. The
surest method is the following:
1.
Locate the iVision 4.0 folder on your hard disk. This folder is probably within the Applications folder.
The file path to iVision:
My Computer: Applications: iVision 4.0 Folder: iVision 4.0
2.
Double click on iVision.
iVision starts and you can begin working: either open an image or capture a new one.
Now exit iVision by selecting the Quit command from the iVision menu, or by typing Command-Q (Cmd-Q).
Tutorials
29
Another way to start iVision is often used when you know that you want to open a specific image.
1.
Within the Finder, find one of the sample images that came from the distribution disks. These will be in your home
directory:
The File Path to iVision Images:
My Computer: Users: YourUserName: iVision 4.0 User Folder: iVision Images
Open the image named “Washington.” You can tell that the operating system knows the image belongs to iVision
because the image has an iVision icon.
2.
Double click on the image. This both starts iVision and opens the “Washington” image.
If you have older versions of iVision on your hard disk, double-clicking on an image may start an older version. The
operating system starts the first version of iVision that it finds, and this may not be the one you want.
Once iVision is running, you will want to open other images. There is a menu command to do this:
1.
Go to the File menu and choose the Open command, or type Command-O (Cmd-O).
2.
Using the dialog box that appears, find and open the folder "iVision Images" in your user folder.
3.
Select the image "Washington" by clicking once on its name.
Open Dialog Box
4.
30
Since we are sure this is the image we want, click Open Image.
Tutorials
The dialog disappears and the "Washington" image appears within a new window.
Another way to open an image is to find its icon within Finder and drag that icon onto the iVision icon. Doing this will
start iVision (if necessary) and open the image.
3.1.2
Reading the Status Palette
To see some information about the image, examine the Status palette. Choose the Show Status command from the
Window menu, or type Command-U (Cmd-U).
The position and size of the ROI
in pixels and in image units.
The Length and Angle tools display their
measurements here.
The position of the cursor and
the pixel value at that point.
Min and Max pixel values for this frame.
Current and maximum frame number (1st of 4 frames).
Image width and height.
Image data type.
Display magnification.
The file type and the extension for the file.
The name of the units definition applied to the image,
and the pixel-to-unit conversion factor.
Camera information (collapsed state).
Scope information (collapsed state).
Status Palette
The Status palette shows you detailed information about the active image.
•
The top of the Status palette describes the region of interest, or ROI. The ROI is the moving, dashed line within the
image. You will use the ROI for selecting part of the image to be measured or worked upon.
•
L and R give the X coordinates of the left and right sides of the ROI. T and B give the Y coordinates of the top
and bottom sides.
•
W and H give the width and height of the ROI.
•
If you are using the Measure Length or Measure Angle cursor tool, the most recently measured length or angle is
displayed here. It is updated as the cursor is moved. In this example a multi-part line is being measured.
•
X and Y report the current position of the cursor.
Tutorials
31
•
Val gives you the value, or intensity, of the pixel under the cursor, at the location given by X and Y. For color
images three values are reported: Red, Green, and Blue, in that order.
•
Min and Max report the extremes of data values that are present within the image. These are very useful for judging
the dynamic range of your image. For color images three values are reported: Red, Green, and Blue, in that order.
•
Images can have multiple frames; they are then called sequences. You can only see one frame at a time in a
sequence. Frame tells you which frame is currently visible. The numbers in parentheses report the range of frames
present. In this example, the sequence consists of four frames numbered 0 to 3. The current frame being displayed is
the second one (#1).
•
W × H report the width and height of the entire image.
•
Data Type gives the image's data type. Data types are described in detail on page 137.
•
Each image can have its own units assigned to it. The name displayed here is the name given to a previously defined
unit definition. Read about the Define XY Units command on page 273, and the Set XY Units command on page
272.
The right-hand column of coordinates reports all positions (such as the cursor’s X and Y position) in the image's
units as well as in pixels. If no units have been assigned to the image, then the both columns will show coordinates
measured in pixels.
•
Magnification tells you how much the image has been zoomed in or out. Possible values are 1, 2, 4, 8 and 1/2. 1/4,
1/8.
•
The section below Magnification reports camera information if the image had been captured by iVision’s Camera
Control. It can be expanded or collapsed by clicking on the disclosure triangle.
3.1.3
Using the ROI and Image Tools
The Tools palette contains buttons that turn on tools you use on images. They are in three groups with the headings ROI,
Segment (or Drawing), and Image.
3.1.3.1 Using the ROI Tools
First, examine the ROI tools at the top of the window. These tools allow you to draw a Region Of Interest (ROI) in one
of several ways. ROIs will be discussed in more detail later, but right now you should practice with these tools.
1.
If you do not already have the "Washington" image open, open it now with the Open command in the File menu.
2.
Click on the rectangular ROI tool. This activates the rectangular ROI selection tool.
Clicking on the Rectangular ROI Tool.
3.
Draw a rectangular ROI by doing the following:
a.
Move the cursor into the image
b.
Hold down the mouse button
c.
Drag the mouse to create a rectangular ROI
When you let go of the mouse button, you see a moving dotted rectangle on top of the image to indicate the position
of ROI.
32
Tutorials
Drawing a Rectangular ROI
4.
Try the same thing with the oval ROI tool. When you let go of the mouse button, you see a moving dotted oval.
5.
To draw a perfect square or circle using one of these two tools: hold down the shift key on the keyboard while you
drag the cursor in the image.
6.
Now try drawing an ROI with the freehand tool at the bottom of this group of tools. Now when you click and drag in
the image, the ROI exactly follows your cursor movements. When you let go of the mouse button, the shape is
automatically closed with a straight line from the last point to the first one.
Selecting the Freehand ROI Tool.
The other ROI tools (except for the wand tool
) work in a similar way, except in how you end drawing: to end
drawing with the closed polygon or multi-line tools, you must double-click at the last point you want. You can also end
drawing a closed polygon by clicking once in the little flashing circle around the first point in the shape. You should
experiment with these other ROI drawing tools.
In order to use the wand tool, your image must have segments. You must have added segments using the Segmentation
command or one of the Segment tools. We will wait until Tutorial 7 (page 114) to show you how to use the wand tool.
Once you have drawn the ROI, you can drag it to a new position or resize it:
1.
Draw a circular ROI using the oval ROI tool. (Remember to hold down the shift key on the keyboard while you drag
the cursor in the image.)
2.
Hold down the Option key on the keyboard. You will see four handles appear at the corners of the ROI.
3.
Move the cursor inside the ROI and see the cursor change to an arrow.
4.
Hold down the mouse button inside the ROI and drag the ROI to a new location.
Tutorials
33
Moving (dragging) the ROI: Hold down the Option key.
5.
Again hold down the Option key on the keyboard. You will see four handles appear at the corners of the ROI.
6.
Move the cursor over one of these handles. You will see the cursor change to an “×”.
7.
Hold down the mouse button and resize the ROI.
Resizing the ROI. The cursor is an “×” with the Option key down.
3.1.3.2 Using the Image Tools
Next, consider the tools at the bottom of the Tools window, under the heading Image.
1.
Click on the magnifying glass icon
at the bottom of the window. When you move the cursor into the image, the
cursor changes to a magnifying glass with a plus sign in it .
Selecting the Magnifying Glass Tool
2.
Move this cursor into the image and click once. The image and the window both grow in size.
3.
In the Tools window, near the bottom, you see that the magnification now reads 2x. You can continue to click in the
image until the magnification reads 8x. Each time you click the mouse, the image is magnified by a factor of 2, to a
maximum of 8X.
When you hold down the Option key on the keyboard, the plus sign in the magnifying glass changes to a minus sign
. To de-magnify, click in the image while holding down the Option key.
4.
To scroll the image, click on the hand icon
(the scroll tool) in the Tools palette, and then click within the image
and drag it to the position in the window where you want it.
5.
To rapidly move the image so that the top-left corner is aligned with the top-left corner of the window, you have
several options:
34
Tutorials
•
Use the scroll tool to drag the image
•
Select the Home command from the View menu
•
Press the Home key found on most keyboards. (The End key aligns the bottom-right corners.)
3.1.4
Using Segment and Drawing Tools
Return the image to magnification level 1. You can use the magnifying glass tool (press the Option key, too, to
demagnify).
If you want to discard all changes made to the image, select the command Revert To Saved from the File menu. This
closes the image and re-reads it from the last version saved to disk.
Now, consider the tools in the middle of the Tools palette. One group is labeled Segment and the other Drawing.
Segment and Drawing Tools in the Tools Palette
These tool sets let you draw into two different types of overlays. These overlays do not affect the image data at all. They
can be shown or hidden, erased or stamped onto the image (stamping onto the image does affect the image data values).
The segment layer is like an image which lays on top of the real image data. It colors each individual pixel one of 8
different colors (or none). It is used primarily for defining regions to be measured.
The drawing layer contains drawing objects which you can select and move. It is used primarily for annotation.
Double click on each of these tools to see options about filling objects and the size of the drawing tool.
The first four tools are the same. They let you draw rectangles, ellipses, closed polygons, and multi-lines (i.e. piecewise
linear objects). To draw a perfect square or circle, choose the rectangle or ellipse tool and hold down the Shift key while
you draw in the image. If you hold down the Shift key while using the multi-line tool, the lines will be limited to 45° and
90° angles.
Segment tools include a paintbrush in the space where the drawing tools include a freehand shape tool. The paintbrush
and freehand drawing tools are functionally similar in that you can create freehand drawings with either, but with
segments it is more like painting into the overlay, and with the drawing tool it is more like drawing a boundary. Also, the
freehand drawing tool always closes itself, but the segment paintbrush allows you to draw any shape.
There is an eraser among the segment tools. There is no eraser among the drawing tools because you remove drawing
objects by selecting them and deleting or cutting them from the drawing layer. The drawing tools include a text drawing
tool, and an arrow tool which is used to select and move objects. Selected objects have a dotted outline.
Each set of tools has cut, copy and paste icons. The drawing cut and copy tools work on selected draw objects. The
segment cut and copy tools work on the portion of the segment overlay within the ROI.
First, we will copy and paste selected drawing objects.
1.
Open the Washington image as the front window.
2.
Click in the color menu beneath “Drawing” and choose the dark blue color.
Tutorials
35
3.
Click on the freehand drawing tool
. Then move the cursor in to the image and draw three or four random shapes.
4.
Click on the arrow tool. Click within each of the objects you drew, one by one. You see that the one you click inside
of has a dotted outline, which indicates that it is selected. You can select more than one object with the arrow tool by
dragging a rectangle around several objects, or by holding down the Shift key while you click on each object. You
can also de-select an object by holding down the Shift key and clicking inside it.
5.
With several objects selected (their outlines appears dotted), click on the Cut button in the Tools window. The
selected objects disappear. Now click on the Paste button. The objects are pasted back onto the overlay.
6.
Click and drag inside any group of selected objects to drag them to another location within the image.
Now Let us work in the segment layer of the overlay.
7.
Click in the color menu beneath “Segment” and select any color you wish.
8.
Ddouble-click on the closed polygon tool
. Check the Fill option.
Closed Polygon Tool Dialog Box
Get it by double-clicking on the
button
9.
Next, draw several closed polygons on the image. You can finish each polygon by double-clicking on the last point.
You can also finish the polygon by clicking on the polygon's first point, which will appear as a little flashing ring.
10. Double-click on the eraser tool
and choose a medium sized eraser. Then erase parts of the segment overlay.
Notice that you cannot erase any of the drawing objects you created earlier.
11. Now, suppose you want to copy and paste a part of the segment overlay. First, select one of the ROI tools at the top
of the Tools window. The freehand tool may be a good choice here. Then place an ROI around one of the polygons
you drew.
12. Click on the Cut button in the Tools window. The portion of the segment overlay which was inside the ROI is
erased.
13. Now click on the Paste button in the Tools window. That portion of the segment overlay is pasted back onto the
image, but it has a flashing outline. This indicates that the paste is not complete yet.
If you move your cursor inside that flashing outline, the cursor turns to an arrow. You can now click and drag the
paste region. When you have dragged the paste region to the location you want, move the cursor outside the paste
region and click again. This completes the paste.
14. Click again on the Past button. Again, you see the paste region with the dotted outline. This time you decide you
don’t want to keep the paste. To cancel the paste, press the Delete key on the keyboard.
This tutorial is over. With this beginning, you are now ready to process image data. Quit iVision by selecting the Quit
command from the iVision menu. If any alerts ask you to save images, answer Don’t Save.
36
Tutorials
3.2
Tutorial 2: Image Enhancement
3.2.1
Overview of the Enhance Menu
The Enhance Menu
Now Let us consider some of the image enhancement operations which are built into iVision. Click on the Enhance
menu to see what the menu contains. You will see that it is divided into four sections. At the top of the menu are
commands that relate to contrast enhancement. Next, come a group of commands that relate to pseudocoloring.
Following that is a group of commands related to image filtering. Finally, comes a group of commands related to
geometric manipulation. You will get a chance to use most of these commands in these tutorials.
1.
First start iVision using one of the methods you learned in Tutorial 1.
2.
Next open the "Washington" image using the Open command in the File menu.
3.2.2
Contrast Enhancement
Contrast enhancement is one of the most common applications of image processing. It is a simple way to help you see
more detail in your images. First, we will talk about enhancing grayscale images. Then we will discuss contrast
enhancement on color images.
3.2.2.1 Adjusting Contrast on Grayscale Images
We will enhance the contrast in the image in a couple of ways. So the first thing to do is to make a copy of the
"Washington" image and adjust the contrast on one of the copies:
1.
From the Window menu, select the command Duplicate Window.
Tutorials
37
Select the Active (Front) Window, Portion = Entire, and type in the new name “Manual Contrast Adjust”. Click
OK, and a copy of the "Washington" image appears in a new "window" with the name “Manual Contrast Adjust”.
Duplicate Window Dialog Box
2.
From the Enhance menu, select Normalization.
3.
Click on the Expand/Collapse triangle ( ) so you can see the histogram of the data within the ROI of the image.
(Because the ROI is around the entire image, this is the histogram of the entire image.)
The dialog shows a plot of the contrast function and the histogram of the data. The contrast function plot describes how
values in the image are mapped into display intensities. Initially, the plot shows a diagonal line from the lower left corner
of the plot to the upper right. This type of contrast function is the identity function. Display intensities are directly
proportional to pixel values. There are several approaches to adjusting the contrast function plot. You should experiment
with each of these methods:
38
a.
Type values in for the minimum and maximum intercept points (at the bottom edges of the histogram).
b.
Click and drag at the handles below the function plot.
Tutorials
One accepted procedure for enhancing the contrast of an image is to match the contrast function to the integrated
histogram. Try this by first selecting Integrated from the Type menu. Then drag the sliders under the plot to
approximately the locations shown in the figure below.
Normalization Dialog Box
With this technique, you can make the linear contrast function match the histogram in a certain range of values.
Tutorials
39
However, you can apply a nonlinear contrast function that matches the histogram over a wider range.
1.
Type in a Mid Point value of 85%.
2.
Drag the endpoints in the plot, or type in values, so that the min. and max. are 0 and 184. The dialog should look
approximately like the following figure.
Normalization with a Nonlinear Contrast Function
The gamma function is a nonlinear contrast function which, in this case, more closely matches the histogram curve.
There are other uses for gamma contrast functions, for example to compensate for nonlinearities in the image capture
process, or in the image display system. Of course, the real test of effectiveness is, “How good does the image look?”
For this, we defer to your judgment.
Sometimes, you may want to enhance the contrast in only a portion of the image and you are willing to sacrifice contrast
in other portions. We use the ROI to define the portion you are interested in.
1.
First, Cancel this dialog, and then do the following steps to set the ROI to a portion of the image.
2.
Next, click on the rectangle tool at the top left of the Tools window, directly under the ROI label.
40
Tutorials
3.
Move the cursor within the image and click-drag a rectangle similar to the following figure. You see a moving
dotted rectangle on top of the image to indicate the ROI.
Drawing a Rectangular ROI
4.
Select Normalization again from the Enhance menu. Click on the Use ROI Values button. The minimum and
maximum parameters are updated.
5.
Now adjust the contrast in any way you want to make the image look as good as possible. Click on the OK button in
the Normalization dialog when you are finished.
iVision for Macintosh also has an automatic method for adjusting the contrast so that the contrast function plot exactly
matches the integrated histogram of the data within the ROI.
We will work on the original of "Washington" so you’ll later be able to compare results with your manual contrast
adjustment techniques. The image "Manual Adjust Contrast" is currently the front window (it has its title bar
highlighted).
1.
Go to the Window menu and select the image named "Washington" from the list of images at the bottom of the
menu. This brings the "Washington" image to the front. You can also click directly on the image.
2.
From the Enhance menu, select Equalize Contrast. Check the Create New Window checkbox. Get the statistics
from the entire image and change only the color table. Click OK.
Equalize Contrast Dialog Box
Another new window is created with the results of the contrast equalization command, which computed an
“optimal” lookup table to apply to the image. This lookup table exactly matches the integrated histogram of the
image data.
Tutorials
41
Now arrange the images on the screen so you can see all of them at once:
3.
From the Window menu, select Tile.
You’ll see all of the images spread out on your monitor. You must decide whether the Equalize Contrast function
gives a pleasing looking image, or if you prefer the results you got in "Manual Adjust Contrast".
We do not want to keep any of these images. You can click on the red go-away button of the active window to close the
image. When you do that, you are presented with an alert that asks you if you want to save the new image before you
close it. Answer Don’t Save to that alert.
Another way to get rid of open windows that you know you will not want to save is to use the Dispose Image command
in the Window menu. Notice that the Dispose Image command has command key combination Command-K(Cmd-K)
like “kill that window”. Another alternative in this case is to select the Dispose All Images command from the Window
menu.
3.2.2.2 Pseudocoloring
Another method of enhancing the contrast in an image is to pseudocolor it. A colorizing technique is to map each
possible pixel value into some color, not just a gray level intensity. To do this, the pixel values are passed to a lookup
table which has 256 entries. Each entry contains relative Red, Green, Blue (RGB) intensity values which are displayed at
any pixel with value equal to that entry. To get gray intensities, the entries in the color table must have Red = Green =
Blue. If this formula does not hold, then colors are displayed. For example, if entry number 100 has the RGB triplet
(128,0,0) in it, then all pixels in the image with value 100 will display as a mid-intensity red, with absolutely no green or
blue in them. Since the lookup table can generate colors, we call it a color lookup table, or CLUT, or just color table. In
this section, you will apply color tables to an image and edit them.
1.
From the File menu, select Open and open the "3t3 Cell" image.
2.
From the Enhance menu, select the command Pseudocolor.
Pseudocolor Dialog Box
(Also shown with pre-built color tables listed)
3.
There are several built-in color lookup tables. Choose the Rainbow option and click OK.
The image immediately changes from a grayscale image to a pseudocolor image. The pixel values are not changed, but
the new color table has colors in all of its entries.
4.
Go to the Tools window and click on the Rotate Color Table tool (the donut shaped icon at the bottom of the Tools
palette ).
42
Tutorials
5.
This tool allows you to rotate the color table interactively. Move the cursor inside the image and hold down the
mouse button and you’ll see the colors in the image change as the color table rotates. To change the direction of
rotation, hold down the Option key and the mouse button. For slower action, use the arrow keys on the keyboard to
rotate the color table.
6.
You can see what this color table looks like. At the bottom of the Analyze menu, there is a hierarchical menu called
Extract. From the Extract menu, select Color Table. A new window is made which holds the Red, Green, and
Blue entries in the color table. It is displayed as a graph, but you can also display the actual values by using View:
as Text in the View menu. You can use the scroll bars on the right side of the window to look at all of the entries. It
is possible to edit this table directly, and re-attach the modified table to the image, but we will look at another way to
edit the color table. To close this window which contains the color table, click in its go-away box in the upper left
corner of the window and answer Don’t Save to the alert that appears.
7.
From the Enhance menu, select the Edit Color Table command. Click on the label called Show List in the lower
left corner of the dialog. From the scrolling list in the middle, select the Blue Green Red color table. The image
changes to reflect the new color table. You can start from this color table to create a new one. Click in the
Histogram checkbox to view the histogram; this may help you edit the color table.
Edit Color Table Dialog Box
8.
Click on the New button and name the new color table “Black Red Yellow.” This name gets added to the scrolling
list and you can begin editing it. The color ribbon at the top of the dialog shows you the how the color table assigns
colors.
9.
To edit the color table, you insert anchor points within the table that tell how you want to treat that point. Move the
cursor inside either the color ribbon or the boxed area in the middle of the dialog. As you do, the index box changes
to show you the index value at the point of your cursor. Move the cursor to the far left where the index value shows
0. Click there and see a vertical line appear at the anchor point 0. Also the Original radio button becomes active and
the color box matches the color of the table at this point. This is the original color at this index in the color table.
10. Your other choices among the radio buttons here are to make it a Single (new color), a Solid color from this anchor
point up to the next anchor point (or the end of the table), or a Ramp of colors from this anchor point to the next.
Choose the Ramp radio button. You will see the flag on the anchor point change to a triangle that points to the right.
11. We are going to set the color at this anchor point to black. Double click on the flag of the anchor point, or click once
in the color box. The color picker appears and you can set a color. The exact form of the color picker depends on the
version of the operating system you have. Set the color to black(that is, intensity = 0) if it is not already at that value.
Tutorials
43
12. Place another anchor point at approximately 100. Make it a ramp by clicking on the Ramp radio button. Also set it
to a red color. Click in the color box to bring up you system’s Color Picker.
13. Place a third anchor point at approximately 200. Use the radio buttons to make it solid, and use the Color Picker to
set its color to an 80% yellow color. The final color table editor looks approximately like the figure below. It has a
ramp of colors from black to red and then to yellow.
Final, Edited Color Table
14. You can edit the color table further by dragging the anchor points around. For example, you might drag the yellow
anchor point left and right to see how the brightest pixels of the image are enhanced. Dragging the red anchor point
affects the range of mid-value pixels.
15. Save the color table you just made and okay this dialog. The changes are left on the image. You can close the image
without saving it.
3.2.2.3 Adjusting Contrast on Color Images
There is a color image on the distribution disk for you to play with.
1.
Open the image “Color Histology.”
Notice on the Status palette that this image is Color 24 data type. This type of image does not need a color table to
display color, unlike grayscale images. The color image has three primary color channels, red, green, and blue, all in the
same image. Each color channel has 256 levels of intensity. (Each channel has 8 bits and there are three channels for a
total of 24 bits, hence the name Color 24.) This provides the possibility to have millions of different colors in a single
image, when you count all of the combinations of the primary colors. This is clearly more colorful than pseudocolor
images which can allow at most 256 different colors in the same image. If your monitor is set to display millions of
colors you will see the image at its best. If your monitor is set to display only 256 colors you probably will see some
color contouring.
As you move the cursor around the image, you see the value field of the Status palette updates three numbers. These are
the intensity levels of the red, green, and blue components of the image. For example, at the (x,y) location (50,80), the
value field on the Status palette reads 197,138,161. This shows that the intensity of the red channel is much higher than
the green and the blue channels; hence the image looks red there.
44
Tutorials
2.
Select the Normalization command from the Enhance menu.
Remember that the color image has three components: red, green ,and blue. You can pick which color channel you want
to work on; pick it from the Channel pop-up menu at the top of the Normalization dialog box. The Channel pop-up
menu also has an item called All the Same which allows you to work on the overall brightness and contrast of the image.
Choose which
color to work
upon
The Normalization Dialog Box
3.
Select the All the Same item from the pop-up menu labeled Channel. Select Integrated from the pop-up menu
labeled Type. This shows the integrated histogram of the luminance or overall brightness of the image.
4.
Adjust the slope and position of the contrast map line by grabbing and dragging the handles under the plot. This
changes the min. and max. parameters and affects the overall brightness of the image.
5.
Alternatively, you can select Red, Green or Blue from the Channel pop-up menu and adjust the contrast of that
color channel separately. Notice that when you select the select Red from the Channel pop-up menu, the image
reverts to the original and you begin adjusting the red contrast from there. The effects are not cumulative between
selections from the Channel pop-up menu.
Here is something to keep in mind as you adjust the contrast on color images. When you select, for example, Red from
the Channel pop-up menu, and adjust the min. and max. parameter values, you are affecting the pixel values of the red
channel only, but you see effects which seem to enhance all of the colors.
6.
Select Red from the Channel pop-up menu, set the min. value to 100 and press the Tab key on the keyboard. The
image appears to be more blue-green. This is because everywhere in the image where the red plane had values less
than 100 got set to zero, and most other red values got reduced. Since the red contribution is reduced, the other
colors (blue and green) appear more pronounced.
Tutorials
45
7.
With Red still selected, set the min. and max. values to 0 and 100 respectively. This really emphasizes the red
channel so you see blue and green almost disappear.
8.
Cancel the Normalization dialog so none of your changes are kept.
You see in the original image that there are white cells with a slightly off-white tint to them. Assume that these cells
should in fact be nearly white. Such tinting often occurs as a result of an uncalibrated camera. We can adjust the overall
tint of the image so that the background pixels are closer to white.
9.
Select the freehand ROI tool from the Status palette and draw an ROI within one of the off-white regions as shown
in the figure below.
Courtesy Dr. Lynn Heinel, Thomas Jefferson Univ.
Outlining a Region of Background for White Balance
10. Before processing the image, Let us see what a distribution of the pixel values looks like in that region. Go to the
Analyze menu and select the Histogram command. Fill in the dialog as shown in the figure below and click on OK.
Histogram Dialog Box
46
Tutorials
11. A new plot window is created. There are three curves plotted which indicate the number of pixels in each color
plane with each possible pixel value from the red, green and blue planes. Although the three plots are clustered
together, they are not right on top of each other. this indicates that the region has a slight off-white tint to it. This
plot window is just for information purposes. It helps to verify that what you think you see with your eyes actually
does correspond to the real data. This may not always be the case, especially if the monitor has a tint to it, in which
case even perfectly white regions may look tinted.
Blue
Green
Red
Histograms of the Red, Green and Blue Pixel Values in the ROI
They are not exactly aligned, indicating a tinted region.
12. With the "Color Histology" image as the front window and the ROI selected as shown above, select the White
Balance command from the Enhance menu.
The White Balance dialog box will ask you if you want to white balance the current frame or the entire sequence.
Since the image has only one frame, this does not make a difference. Click OK.
13. Let us verify that the ROI region actually is whiter. Again, go to the Analyze menu and select the Histogram
command. Fill in the dialog as before and click on OK. The histogram window will be updated to match the new
data. In the resulting plot window, you’ll see that the three curves almost perfectly overlap, indicating that the data
in that region is whiter.
Histograms of the Red, Green And Blue Pixel Values in the ROI
They are almost perfectly aligned, indicating that the data in that region is whiter.
Tutorials
47
This completes the tutorials on contrast enhancement. Go to the Window menu and select the Dispose All Images
command before going to the next tutorial session.
3.2.3
Filtering
In this session we will use the "Washington" image again. Open that image now. Since the "Washington" image is rather
noisy, Let us try a process that reduces the noise.
1.
From the Enhance menu, select Median Filter.
Median Filter Dialog Box
2.
Check the Create New Window checkbox.
3.
Click in the gray area of the mask until the solid black outline surrounds a 3x1 area of gray blocks as shown in the
figure above.
4.
Click OK.
A new window called "Washington.F" is created and the processed image is displayed in it.
The median filter reduces the noise, but also seems to blur the image somewhat. So Let us sharpen the "Washington.F"
image with a linear filter. A sharpening filter is already included in the Linear Filter command dialog.
Linear Filter Dialog with Sharpen1 3x3 Selected
48
Tutorials
5.
From the Enhance menu, select Linear Filter.
6.
Check the box labeled Put Results in New Window.
7.
Scroll the list of filters to the bottom, highlight the Sharpen1 3x3 filter, and then click OK.
Another new window is created with the results of the sharpen filter. You may be interested in seeing the kernel which is
used for Sharpen1 3x3, or you may want to create your own linear filter kernels. You can do both of these things using
the Define Linear Filter command in the Enhance menu.
Define Linear Filter Dialog Box
Scroll down the list of built-in filters and click on the one called Sharpen1 3x3. The filter kernel for that filter is
displayed so you can see it. You can experiment with other filters later. Right now, just click on the Done button.
There are several other ways to filter the image data. In the linear filter dialog you could have chosen the Use Filter in
Window: option. In this case you must have another data window on screen which contains the linear filter kernel you
want to use. Some filter kernels are supplied with iVision and you can create your own. For more information about that,
see the section on Linear Filter in the Menu Reference chapter, on page 246. iVision also lets you filter images in FFT
space. For more information on doing that, see the section on the FFT Filter command. There is also an Edge Filter
command with several built-in standard edge finding filters. See the description of the Edge Filter command on page
247 for more information on that.
3.2.4
Color Image Filtering
Here we consider two ways of filtering color images.
1.
Open the image called “Color Image”.
2.
So we can do a comparison of two different filter methods, duplicate the entire "Color Image" using the Duplicate
Window command in the Window menu. Name the new image “Filtered Directly.”
3.
With “Filtered Directly” as the front window, select the Linear Filter command from the Enhance menu. Find the
filter named Sharpen1 3x3 in the scrolling list of built-in filters. Highlight that filter, and do not check the box
labeled Put Results in New Window. Click OK.
The image is filtered and looks like a sharpened version of the original. However there are some artifacts. For one thing,
there appears to be a blue halo around the top of the apple. This is due to the fact that filtering this way applies the filter
to the RGB components of the image. While this is often a fast and accepted way of filtering, this process can also
Tutorials
49
introduce colors into the filtered image that were not in the original. Another method is to filter only the intensity
information of a color image, not the color information.
Here is how you do it:
1.
Bring "Color Image" to the front. Either click in its title bar or find it in the list of windows at the bottom of the
Window menu.
2.
Go to the Math menu and select the command Split Color Channels. Remember that a color image has three
components, or coordinates: red, green, and blue. You could choose R-G-B and create three new image windows
that contain these components. However, we are going to reduce the H-S-V coordinates (i.e. the blue halo). H and S
stand for Hue and Saturation. They contain the color information in the image. The V coordinate is Value. It
contains the intensity information. That is the one we will use for filtering. Click OK.
Split Color Coordinates Dialog Box
3.
Three new windows are created to hold the H, S and V coordinate images. Go to the Window menu, find the one
called “Color Image.V” (it should be the third one on the list at the bottom of the Window menu) and make it the
front window.
4.
Apply the Sharpen1 3x3 filter to this image using the Linear Filter command in the Enhance window. In this case
put the results into a new window. When you click OK the new filtered image has the name “Color Image.V.F.”
5.
Now that the intensity information is filtered, we must put this back together with the color information to create
another color image. From the Math menu, select the command Merge Color Channels. The Merge Channels are
HSV, and the Final Image should be Color 24. The names of the input windows are as shown in the figure below.
Drag down each individual window to correspond to the appropriate color image. You are using the unchanged H
and S coordinate windows and the filtered V window. When the dialog is filled out, click OK.
50
Tutorials
Merge Color Channels Dialog Box
6.
A new color image is created with a name like "Untitled 1". Use the Rename Window command (Window menu)
to name this "Filtered Intensity".
7.
Use the Tile command in the Window menu to spread out the images on the screen so you can see them. You may
want to close the four intermediate images that were created, "Color Image.V.F", "Color Image.V", "Color
Image.H", and "Color Image.S". You can click in their go-away boxes to close them. Don’t save them.
Seeing the images “Filtered Directly” and “Filtered Intensity” side by side, you will probably agree that the latter looks
more like a real image. While it is handy and quick to use the Linear Filter command directly, you may want to
consider this sequence of steps of color image sharpening for some applications.
Don’t worry that there are too many steps to remember. iVision has a way to encode a repetitive sequence of steps like
this into a script that you can easily apply at the touch of a button. Scripting is covered in "Tutorial 6: Scripting", starting
on page 97.
Tutorials
51
3.2.5
Geometric Operations
At the bottom of the Enhance menu is a group of commands for geometric processing.
Geometric Processing Commands in the Enhance Menu
Use the Flip command to exactly rotate images by 90° increments or flip them horizontally or vertically. These
operations are perfectly reversible.
Rotate & Scale can be used to perform arbitrary angle rotations and re-sizing. But, unlike the Flip command, Rotate &
Scale is not reversible. When you rotate an image by 20°, for example, the coordinates of each pixel in the rotated image
do not fall exactly on the coordinates of the original. So there must be some form of interpolation, which cannot be
exactly reversed. So rotating by 20° then by -20° will result in an image that is slightly different than the original.
Use the Mosaic command to make one large image out of two smaller ones. You can join them vertically, or horizontally
at the edges of the images. Or if there is an overlap between the images, you can place registration marks on each image
to align them properly. Here is how you do that:
1.
Open the files called “Slide DAPI 1” and “Slide DAPI 2.” These are two images taken from a microscope slide.
Between “Slide DAPI 1” and “Slide DAPI 2” the stage was translated so that the field of view overlapped. Notice
that where the two images overlap you can see at least part of a long chromosome in each. This is what we will use
as a landmark to help register the images.
DAPI 1
DAPI 2
"Slide DAPI 1" and "Slide DAPI 2" Images: Overlapping Images of a Microscope Slide
Showing the Placement of Registration Marks.
2.
52
Make "Slide DAPI 1" the front window (click in its title bar or select it from the window list at the bottom of the
Window menu).
Tutorials
3.
Pick up the “®” tool on the Tools window (click on the tool). Then locate and click on the centromere in the long
chromosome (the bright part at the center). Place it exactly at cursor location (118,114). When you click in the
image, you see a special symbol placed at the point that you clicked. This is the registration mark symbol. Do the
same to place a registration mark at the corresponding point in the "Slide DAPI 2" image. Place it exactly at cursor
location (9,114).
Mosaic Dialog Box
5.
From the bottom of the enhance menu, select the Mosaic command. Select the names of the two images, "Slide
DAPI 1" and "Slide DAPI 2", by dragging the right arrow and select the Placement option Registration Marks.
Click OK. A new image is formed which is the composite of the two. The second image (in this case, "Slide DAPI
2") overwrote the first image in the region where they overlapped.
6.
Keep this image on the screen. It will be used in the next session.
Finally, a note about the Register command: this command is used to align two images that are out of sync by pixel shift
or rotation or scale. The primary way to use this command is first to place registration marks in the two images, similar
to what you did in the Mosaic command example above. Then one of the images is considered the reference and the
other image is the one which will be rotated, shifted and scaled so that its registration marks come into alignment with
the reference image.
3.2.6
Adjusting the Size of the Image
Above, we gave you the exact coordinates for placing the registration marks. This resulted in a mosaic of exactly the
right size. But in most cases the size of a mosaic based on registration marks will be different for each pair of images
used. If you need to merge these images together (as in the next tutorial) or perform other operations, they will most
likely all have to be the same size. There are two methods you can use to produce a fixed size image.
The first method is to use the Crop Image command, in the Edit menu, to trim the edges of the image. The Crop Image
command keeps everything within the ROI and throws away the rest. If the ROI is not rectangular, then the smallest
rectangle that includes the ROI is used. The Define ROI command can be used to repeatedly set the ROI to a specific
location.
The second method is to copy the existing data and paste it into a new image of the right size. It is assumed here that you
have another window (the “model” window) of the desired size already open.
1.
Make the "Slide DAPI 1.M" image the front window. Click on the rectangular ROI tool in the Tools window and
select the command Select All from the Edit menu. This ensures that the ROI is around the entire image.
2.
Next, select Copy from the Edit menu.
Tutorials
53
3.
Make the “model” window the front window. Click on the rectangular ROI tool in the Tools window and select the
command Select All from the Edit menu.
4.
Go to the File menu and select New Image. Fill in the dialog as shown in the figure below and click OK. This
creates a new blank image window the same size as the “model” image.
New Image Dialog
Create a new window the same size as the front image
5.
Now go to the Edit menu and select Paste. This pastes the image you copied from the original DAPI window into
this "New DAPI" window.
6.
You can drag the image around in the new window to position it. Once you click outside of the paste region the
paste is completed, and the data is now in the new window.
3.2.7
Color Overlaying or Color Merging
Many people use a grayscale camera together with colored filters to capture high-resolution images at different source
wavelengths. iVision can be used to merge up to three of these grayscale images into a single high-resolution color
image.
You should still have the window called "Slide DAPI 1.M" (which was created in the previous session). This image was
captured with colored filters matched to the DAPI probe. It will be merged with another image taken through a color
filter matched to the FITC probe. Of course, there are many other sources of multi-spectral image data including remote
sensing and laser optics, but this example will show you the basics.
The command we will use here allows you to merge up to three images to form a color image. For merging images of
more than three wavelengths, see the optional Fluorescence CV extension (described in the separate Extensions
manual).
1.
Open the image "Slide FITC".
2.
Go to the Math menu and select the command Merge Color Channels. The Merge Channels are assumed to come
from RGB, and the Final Image should be Color 24. For the G (green) window, use "Slide FITC", and for the B
(blue) window, use "Slide DAPI 1.M". There is no red channel, so clear the entry for the R (red) window. OK the
dialog.
54
Tutorials
Merge Color Channels Dialog Box
3.
If you had made a mosaic from the images in the previous session exactly at the points we indicated, you should
now have a new color image which is a color merge of the DAPI and FITC images. If instead, you got a message
that said something about the images needing to be the same size, refer to the previous section for methods to
change the size of an image.
3.2.8
Other Enhance Commands
There are two other commands in the Enhance menu, which we have not yet mentioned. They are Image Ratios and
Invert, found near the top of the Enhance menu within the grouping of contrast enhancement commands. We will just
mention how you might use them here, without actually applying them to any images.
The Invert command is used to invert the meaning of pixel values or color table values within an image. This is
sometimes necessary when you get image data from another source. For example, some popular free imaging software
packages encode images so that 0 = white and 255 = black. Of course this is backwards to standard scientific
interpretation of intensities. Since for most functions you will prefer to have 0 = black and 255 = white, you need a way
to convert those “foreign” images. The Invert command does this for you.
The Image Ratios command actually does several related things, depending on the option you select from the dialog.
You can use it to:
•
Take the ratio of two images in a very accurate way; or
•
Use it to compute optical density; or
•
Use it for “flat fielding” an image, i.e. correct for non-uniformities in the image capture process.
This completes the tutorials on basic image enhancement. You can quit iVision by selecting the Quit command from the
iVision menu, or type Command-Q (Cmd-Q).
Tutorials
55
3.3
Tutorial 3: Particle Segmentation
3.3.1
What is a Segment?
When you want to quantitatively measure individual regions in an image, the first step is to separate, or segment, those
particles from the background. Therefore in this manual we refer to a ”segment” as any connected region of pixels which
has been identified as being a single item of interest for measuring. The way segments are identified in iVision is by the
color of pixels in the segment overlay. The segment overlay is like an image that overlays the original image. In most
places, you can see right through the segment overlay, that is, it is transparent. However, at pixels on identified
segments, the segment overlay shows an opaque color.
You can have several different colored segments in an image. For example, you may be interested in two or three
different kinds of particles in an image. In that case you would identify each kind of particle by a different color of
segment overlay pixels.
There are several ways to perform segmentation. We will consider three here:
1.
Manually; that is, drawing by hand;
2.
Thresholding intensity values with possible manual touch-up;
3.
Pre-processing for certain kinds of texture and then thresholding.
After any of the segmentation methods, you may want to apply some “cleaning” techniques (binary morphology) to
improve the quality of the segments. We will also show you some of those techniques.
3.3.2
Hand Drawing Segments
Manually tracing particles is a good place to start when understanding segments. In fact, there may be some cases where
the image you are working with may be too difficult for any of the other segmentation techniques.
1.
Find and open the image "Three Phase" from the Images folder. This is a metal alloy with three distinct phases
represented by different intensities.
2.
On the Tools window are several tools, which are used to draw into the segment overlay.
Portion of the Tools Window Showing Segment Tools
3.
Below the word Segment in the Tools window is a color bar with an arrow next to it. If you click on that bar, you
see a pop-up list of color choices. The original default color is the green near the bottom of the menu. Select this
color if it is not already selected. Now all of the drawing tools below that pop-up will use that color when you draw
into the segment overlay.
4.
The paintbrush tool, for example, is used to define freehand drawing segments. Double-click on the paintbrush. The
dialog that appears allows you to select a paintbrush size and shape. Choose the third or fourth one, which are about
the same size, except one is square and the other is round.
56
Tutorials
Paintbrush Tool Size Options Dialog Box
5.
Now move the cursor into the image and use it to paint the inside boundary of two or three of the smaller white
particles. You do not need to fill in the interior of the particle. Hole filling can be done later. However, you must be
careful to create a fully closed region, especially if you eventually want to fill the interior holes or include the
interior holes in the measurements.
Showing one properly closed segment and one that is not properly closed.
It is important to note that you are painting into a non-destructive overlay on top of the image data. The segment overlay
layer is used to define regions (or particles) which you want measure. You can remove the segment overlay, modify it, or
just hide it, all without affecting your image data.
•
You can draw as many segments as you want, using different colors for different particle types. To change the
color, with which you draw the segments, simply click on the pop-up list at the color bar beneath the word
Segment in the Tools window. The color bar changes and shows what color will be used for subsequent
segment drawing.
•
If you make a mistake, you can erase it with the eraser tool, which is also found on the Tools window below the
paintbrush. As with the paintbrush, you can double-click on the eraser tool to change its size.
•
There is one important thing to keep in mind about segments, especially if you want to do measurements on
them later. Segments are defined as “connected sets of pixels.” Therefore, you cannot have two segments of
the same color touching each other. If segments touch, they are really one set of connected pixels.
At any time you want, you can remove the segment overlay:
6.
Choose the Dispose Segment Layer command from near the bottom of the Analyze menu.
After you have drawn all of the segments you want, you can measure all of the segments of a single color at one time. In
the next session we show you additional methods of placing segments. If you would like to go directly to measuring
segments, you can skip ahead to the next tutorial.
Now we will try another way of entering segments. You can close the "Three Phase" image. We will use a different one
for the next session.
Tutorials
57
3.3.3
Placing a Segment at the ROI
Sometimes you may want to place many segments of exactly the same size and shape. In this exercise you will learn how
to do that, using one of the ROI tools.
1.
Find and open the image called “Gel.”
2.
Since the image is small, Let us magnify it. Click on the magnifying glass tool on the Tools window, and then click
in the image once. You may want to align the image with its window by using the Home command from the View
menu or the Home key on the keyboard.
3.
Now select an ROI tool. Click on the rectangular ROI tool at the top of the Tools window.
4.
Now draw a region of interest around one of the bands in the image.
Selecting a Band
5.
There is a command that draws a segment at exactly the boundary of the ROI. From the Analyze menu, select the
Segment at ROI command. Notice that it has command key combination Command-2 (Cmd-2). You may not see
anything happen, but a segment was drawn. You’ll see it after the next step.
6.
Now, instead of drawing a new ROI, drag this one to a new location. Hold down the option key and move the cursor
inside the ROI rectangle. You will see the cursor change to an arrow.
With Option key down, cursor becomes arrow inside the ROI
With the option key still down, you can now click inside the ROI and drag it to surround the next band. Once you
have moved the ROI out of the way, you can see the segment that you created.
7.
Now press Command-2 (Cmd-2) again, which does the command Segment at ROI.
8.
You can continue this method of dragging the ROI and doing Segment at ROI several times. This creates a set of
segments, all with the same size and shape.
Note:
Remember that the segments must not be touching if you want to do measurements on them later. Otherwise the
touching segments would be one big segment.
You can also use any of the other ROI tools in this way to create multiple segments.
3.3.4
Copy and Paste a Segment
An alternative to the Segment at ROI command is to copy and paste segments. You have already learned how to copy
and paste segments in Tutorial 1, but we can review the procedure here.
58
Tutorials
1.
With the "Gel" image still as the front window, draw a single segment on the image. Don’t forget to first make sure
that the Segment/Drawing name on the Tools window reads Segment so you have access to the segment tools.
2.
To define what portion of the segments overlay to copy, we need the ROI. So select one of the ROI tools at the top
of the Tools window. The freehand tool may be a good choice here. Then place an ROI around the segment you
drew.
3.
Click on the Copy Seg. button on the Tools window. You have now copied the portion of the segment overlay that
was inside the ROI.
4.
Now click on the Paste Seg button on the Tools window. That portion of the segment overlay is pasted back onto
the image, but it has a flashing outline. This indicates that the paste is not complete yet. If you move your cursor
inside that flashing outline, the cursor turns to an arrow, at which time you can click and drag around the paste
region. When you have dragged the paste region to a location you want to keep it, move the cursor outside the paste
region and click again. This fixes the segment in place.
5.
Click again on the Paste Seg. button. Again you see the paste region with the dotted outline. This time you decide
you don’t want to keep the paste. To cancel the paste, press the Delete key on the keyboard.
By copying and pasting you can create multiple segments of the same size and shape. What’s more, you can copy and
paste multiple segments at once. Use one of the ROI tools to create an ROI around several segments:
6.
Click on the Copy Seg. icon on the Tools window. Again that portion of the segment overlay which was inside the
ROI is copied, although this time it contains multiple segments.
7.
Now when you click on the Paste Seg. icon in the Tools window you see a larger portion of the segment overlay
pasted, including multiple segments.
3.3.5
Intensity Thresholding
A common method of creating multiple segments at once is to use intensity thresholding. iVision’s Segmentation
command lets you determine the thresholds interactively.
1.
Find and open the image "Three Phase" from the Images folder. This is an image of a metal alloy.
2.
With the "Three Phase" image as the front window, you want to make sure that the ROI is around the entire image.
If not, click on the rectangular ROI button in the Tools window. Next, go to the Edit menu and select the command
Select All. This places the ROI around the entire image.
3.
Now you are ready to segment the image.
Go to the Analyze menu and select the Segmentation command.
Tutorials
59
Segmentation Dialog Box
4.
Click the Duplicate button. This makes a new segmentation set, which is a file that saves the parameters you are
about to enter. Name the set whatever you like.
You will see the name of your new set displayed in the Set pop-up menu at the top of the dialog box.
5.
Choose the color of the segments to make. Choose the green color. This is important because the Measure
Segments command will only measure segments of one color, the color that is picked in the Measurement Options
command.
6.
Use the Segmentation dialog's histogram to select part of the image. Use the red and blue handles under the
histogram to select part of the histogram. The corresponding intensities within the image will be segmented.
You want to segment the white particles, whose intensites are represented on the right of the histogram. So drag the
red and blue handles to the right side of the histogram. You can do this by dragging the left (blue) handle to the
right; this will push the right (red) handle in front of it.
7.
Drag the left handle back to the middle of the histogram.
The brightest half of the pixels should now be selected.
As you click inside the particles in the "Three Phase" image, you will see the min. and max. thresholds on the
histogram being adjusted automatically.
8.
Click OK. The dialog box disappears and the segment overlay becomes green over the brightest phase particles. In
other words, there are green segments over the brightest particles.
Before you measure the segments, you may want to touch-up the global segmentation results.
60
Tutorials
There is a clump of particles, which should have been separated from each other, but they are touching in the overlay.
Since these segments touch, they would be measured as one object. Therefore, you must separate them before
measuring if you want them measured separately.
Portion of the Segmented Image Showing Touching Segments
You can use the overlay drawing tools to correct this. Since the image is very small and you will be doing fine work, it is
handy to magnify the view first.
9.
Use the magnifying glass icon at the bottom of the Tools window and click once in the image near the clump of
three particles.
To scroll the clump of particles to the center of the window, click on the hand cursor. Then click within the image
and drag it to the position in the window that you want.
10. Make certain the Segment tools are showing and not the Drawing tools.
Among the tools available when you are using segment tools is an eraser (it is found beneath the paintbrush). Doubleclick on the eraser tool. In the dialog that appears, select one of the small-sized erasers.
11. Now move the cursor to the image and paint two lines to separate the clump of particles into a group of three. The
eraser actually paints in transparent color into the segment overlay.
12. If you make a mistake, or you want to draw in an area which was not previously set by the Segmentation command,
you can do that by hand drawing the segments as in the previous section of this tutorial.
13. When you are finished with this exercise, you can close the "Three Phase" image, since we will use another image
for the next session. You can click in the go-away box of the window, or you can select Close Image from the File
menu (Cmd-W), or Dispose Image from the Window menu (Cmd-K).
3.3.6
Cleaning Segments: Binary Morphology
In the last session, you saw that you could clean up the results of the Segmentation command manually, using the tools
on the Tools window to erase mistakes or draw in new parts of segments. In this exercise, you will use a computer-aided
technique that is often called Binary Morphology. This is just a fancy name for a kind of filtering you can do to the
overlay which defines segments. First, we will open another image to play with.
1.
Open the image “Grains”.
2.
Select the Segmentation command from the Analyze menu.
This time, we will try a different method of segmenting the image.
2a. Set the lower threshold to about 189 by dragging the left handle under the histogram.
2b. Set the upper threshold to 255 by dragging the histogram's right handle.
You can also type the values in the editable text boxes under the histogram's left and right edges.
2c. This time, choose the red color from the Segment Color pop-up menu.
2d. Finally, OK the dialog.
Tutorials
61
Segmentation Dialog Box
3.
Since the image is rather small, you may want to use the magnifying glass tool from the Tools window to magnify
the view of the image.
Notice that, in general, the segments are well defined over the grains. However, there are several segments with holes
and there appear to be a few very small segments within the boundaries. These “errors” can be globally cleaned up using
the Modify Segments command.
4.
Select the Modify Segments command from the Analyze menu.
There are many options here to explore.
4a. First, select the Fill Holes and Create New Window options.
4.b. Next, choose red from the Segment Color pop-up. This is because we want to process the red colored segments.
4c. Finally, OK the dialog.
62
Tutorials
Modify Segments Dialog for the Hole-Filling Operation
5.
A new processing image is created. Only the overlay has been affected. The holes within the segments on the grains
are now filled in.
6.
Select the Modify Segments command again. This time, we will use it to eliminate the small segments and clean up
rough edges on all of the segments.
6a. Select the Open operation.
6b. Also, click on the squares within the Mask to make the shape rectangular as shown in the figure below.
6c. Click OK.
The Open operation performs an Erode and then a Dilate, using the mask you have selected. Erode reduces the size of
every segment by eroding its boundary. Erode eliminates small segments. The Dilate operation then increases the size of
the remaining segments to bring them back to approximately their original size.
Modify Segments Dialog for Morphological Open Operation
While there are many other operations you can experiment with in the Modify Segments command, there is one more
we will show you here.
Tutorials
63
7.
Select the Modify Segments command again.
7a. This time, choose the Boundary Only and Create New Window options.
7b. Click OK.
Only the boundaries of the grain segments are kept.
If you want to return to the filled version, run Modify Segments again and choose the Fill Holes option.
You can close this image because we will use a different one for the next session.
3.3.7
1.
Using Grain Boundaries
Open the image named “Multi-Grain”.
This image has two different kinds of particles, which are distinguished by their size. We want to get a distribution
of the sizes and then the mean intensity on the larger particles.
For this image, we will use a slightly different approach from the one we used in the previous sessions. We will actually
work on getting the boundary pixels right and then take the complement of the boundary pixels to get the particles.
'Taking the complement' means to turn non-segment pixels into segment pixels while turning segment pixels into nonsegment pixels.
2.
Use the Segmentation command from the Analyze menu.
2a. Choose the green color for the segment color
2b. Set the maximum threshold to about 100
2c. Set the minimum threshold to 0.
2d. Then OK the dialog.
This creates segments which cover the boundary pixels.
3.
Now Let us work on this boundary to make it as thin as possible, but still able to separate the particles.
3a. Select the Modify Segments command
3b. Select the Skeletonize option.
3c. Be sure the segment color is the same as the one you used in the Segmentation command.
3d, OK the dialog.
64
Tutorials
Use the Skeletonize option
You will get an image which has thin boundary lines of green separating the particles.
4.
The boundary lines are one pixel thick, which is actually too thin to adequately separate particles (the boundary line
also breaks in some places).
4a. So select Modify Segments again.
4b. This time, use the Dilate option.
4c. Set the Mask as shown in the figure below.
This thickens the lines and helps to connect them. It also does some minor damage to the boundary definitions
of the smallest particles.
Thicken the boundaries with the Dilate option
5.
The last step is to take the complement of this segment overlay definition.
5a. Again, select the Modify Segments command.
5b. This time choose the Complement option.
5c. OK the dialog.
The resulting image shows the particles in the segment overlay.
Tutorials
65
This multi-step procedure shows you that sometimes it takes a little ingenuity to derive a good segmentation technique.
You can close all of the open images before proceeding.
3.3.8
Pre-Processing For Texture
The Segmentation command lets you set thresholds on the intensity values within an image. Sometimes particles cannot
be separated from the background simply by setting intensity thresholds. In this session, you will learn one form of preprocessing on image data that will help separate particles based on a concept called texture. For a measure of texture, we
use a simple technique of computing the difference between the minimum and maximum pixel values in a neighborhood
around each pixel. While this is a very specific procedure for computing texture, the idea of pre-processing an image to
enhance particles can be used in other scenarios as well.
1.
Open the image “Curds&Whey”. Notice that this image has clearly identifiable particles of nearly uniform intensity
on a background of highly variable intensity.
2.
From the Analyze menu, select the Segmentation command. You can try adjusting the thresholds, but no matter
what settings you use, the uniform particles cannot be segmented from the background because the background has
some of the same intensity values within it.
Cancel the Segmentation dialog to leave the image unchanged.
3.
Now we will apply a series of steps that will result in an image in which the particles can be segmented by intensity.
First, make sure that the ROI is around the entire image. If it is not, you must do two things: click on the rectangular
ROI tool on the Tools window, then do the command Select All from the Edit menu.
4.
From the Enhance menu, select the Morphology command. In that dialog select Erode and click inside the Mask
to make the outline a full 5×5 pixels as shown in the figure below. Also select Create New image. This command
works only within the ROI, which is why we had to use the Select All command first.
Morphology Dialog for Grayscale Processing
In the new image created by this command, each pixel is replaced by the minimum value of the pixels in a 5×5
neighborhood around that pixel.
5.
66
Rename this image. From the Window menu, select the Rename Window command. Type in the new name “Min”
and OK the dialog.
Tutorials
Rename Window dialog for the results of the Erode operation
6.
Now bring the original "Curds&Whey" image to the front. Either click in its title bar or choose it from the list of
windows at the bottom of the Window menu.
7.
Again, make sure that the ROI is around the entire image.
8.
And again select the Morphology command from the Enhance menu. This time choose Dilate and Create New
Window, and then OK the dialog. Another new image is formed. To create this image, each pixel in the original
image is replaced by the maximum value of all of the pixels in the surrounding 5×5 neighborhood.
9.
Rename this image using the Rename Window command. Call it “Max.”
10. Now we have two windows which contain the min. and max. values in a neighborhood around each pixel. To take
the difference between them, use the Image Arithmetic command in the Math menu. Fill out the dialog as shown
in the figure below and OK the dialog. This takes the difference between the "Max" and "Min" images and places
the resulting image into a new window called "Texture".
Image Arithmetic Dialog for Taking the Difference Between the Max and Min Images
11. The image formed from this command shows brighter values where the texture in the original image is “rougher.”
This image is amenable to thresholding. Select the Segmentation command. Adjust the upper threshold to some
Tutorials
67
value between 110 and 130. This includes the particles and rejects the background fairly well. Finally, OK the
dialog.
12. Now Let us transfer this overlay information back to the original image. From the Edit menu, select the command
Transfer Attributes. You want to transfer just the segment layer attributes from the "Texture" image to the
"Curds&Whey" image. When the dialog is filled in like the figure below, OK it.
Transfer Attributes Dialog Box
13. Now bring the "Curds&Whey" image to the front. Either click in its title bar or select it from the list of windows at
the bottom of the Window menu. You can see the particles are well covered by the segments and ready to be
measured. Or you can use the Modify Segments command as you did in a previous exercise to get the boundary
only, or otherwise filter the segment definitions.
There were a lot of steps involved in finding the texture of the image. Don’t worry that you will not be able to remember
all of the steps. That is why we made scripting, to record repetitive sequences of steps like that. More on scripting later,
starting on page 97.
68
Tutorials
3.3.9
Segmentation on Color Images
You can segment color images using the same Segmentation command under the Analyze menu. Since color images
actually have three components to describe them (red, green blue, or some transformation of these components) there are
many ways to threshold color images. You must create a strategy for segmentation that includes components you want to
examine and how to combine thresholds on the various components. The Segmentation dialog gives you a way of
exploring those options.
1.
Open the image called "Color Histology" (Color Histology image courtesy Dr. Lynn Heinel, Thomas Jefferson
University). Notice on the Status palette that this is a Color 24 image. It is a stained histology section. We are
interested in the blue stained nuclei.
2.
From the Analyze menu, select the command Segmentation.
3.
Click the Duplicate button. This makes a new segmentation set, which is a file that saves the parameters you are
about to enter. Name the set whatever you like.
You will see the name of your new set displayed in the Set pop-up menu at the top of the dialog box.
4.
Move the pointer over to the image; the pointer will turn into an eyedropper
.
Click on any of the nuclei in the image. They will all get automatically segmented pretty well. This is how powerful
the Segmentation command in iVision is. See what effect changing each of the Sensitivity slider bars have on the
segmentation by undo-ing the previous segmentation, changing the slider position and then clicking inside the nuclei
again. Undo previous segmentations by clicking on the Backwards button
in the dialog box.
Segmentation Dialog Box for Color Images
5.
If you wish to know what is going on behind the scenes, click on the Histogram tab. In the first pop up menu on the
Histogram tab, select Bs. This is a color component which is equal to the blue value of each pixel divided by the
pixel brightness. It gives a good definition of the blue color. Since we will not need any other color components to
help us define the regions we are interested in, you should select Off in the pop-up menu in the next row.
Tutorials
69
Segmentation Dialog Box Showing the Histogram Tab
5.
To define the Min and Max thresholds on Bs, drag the left threshold so that the min. value reads approximately 90,
and the right threshold all the way to the right edge of the histogram. When you let go of the mouse button, you will
see segments defined in the overlay on the image as green (or the color you have selected as the Segment Color).
OK the dialog and the image is covered with an overlay which defines the segments.
This was an easy example. Now Let us try a more difficult one that will require thresholding on more than one color
component.
1.
70
Open the image called "Color Image". This is also a Color 24 image. The apple has a bright spot on it where
incident light is reflected. It is sort of pink. Suppose this is the color we are interested in.
Tutorials
2.
Use the Freehand ROI tool to outline the bright spot on the apple. This will limit the histogram in the segmentation
dialog to just these pixels.
Use the Freehand ROI to Outline the Bright Spot
3.
From the Analyze menu, select the Segmentation command.
4.
Select the yellow segment color. It will contrast with the other colors in the image, making it easier to see which
pixels have been segmented.
5.
In the first pop up list on the Histogram tab, select Rs. Also select the Off option from the pop-up menu on the next
row as shown in the dialog below.
Segmentation Dialog Box After Applying Rs Thresholds Only
6.
Under the histogram of the Rs values of the pixels in the ROI, drag the thresholds to approximately the values shown
in the figure above.
Tutorials
71
7.
The selected pixels include not only the area we are interested in but also parts of the shadow and the leaf. This is
because those regions also have some red in them. Here is where you must get creative.
What other color characteristics distinguish the desired area from the undesired areas already selected? The answer
is that the desired areas are brighter. There is a way to select only the bright areas. First change the Off to And. This
lets you access another component to use. Select Y (which is a symbol for luminance or brightness) in the second
component pop-up list. This time set the thresholds to approximately the values shown in the figure below. You will
see the yellow segment overlay pixels in the shadow areas disappear.
Segmentation Dialog Box After Applying Rs and Y Thresholds
72
Tutorials
8.
You are almost done. There are still some pixels in the leaf which pass these two thresholds. So turn the next Off to
And and select Hue. Hue corresponds roughly to wavelength or color in a generic sense.
Notice that the histogram is separated at the two ends of the plot. Also notice that the color bar above the histogram
indicates where the red hues lie, at the outside ends of the plot window.
Click on the Invert button
and adjust the thresholds to approximately the values shown in the figure below.
Segmentation with Rs, Y and Hue Thresholds
9.
This is about the best we can do, so click OK to finish up.
Tutorials
73
10. There are still come stray pixels in the segment overlay. You can use the Modify Segments command to clean up
segments on color images just like on grayscale images. First, use Select All from the Edit menu to place the ROI
around the entire image. Then select Modify Segments from the Analyze menu and apply the Open filter with a
large kernel. This will remove small groups of segment pixels while leaving the large group over the bright spot
intact.
Modify Segments Dialog Box
3.3.10
Summary
We have spent a lot of time on segmentation. But that step is often the most difficult and critical step in measuring
particles. There are basically two methods of segmenting an image: drawing the segments by hand and creating segments
by thresholding (with the Segmentation command). We also showed you one pre-processing option which you can use
to consider texture as the criterion for segmentation. Once an image is segmented, you can still clean up the segments,
again either by using the segment drawing tools again or by using the Modify Segments command.
Usually, the next step in the analysis process is to measure the segments. That is the topic of the next tutorial.
74
Tutorials
3.4
Tutorial 4: Particle Measurements
Often the objective of electronic imaging is to measure things that you cannot conveniently measure any other way. This
may include densities (i.e. intensities), areas, and shape information, even the location of particles. You may also want
summary information such as the percentage of the total area that is occupied by certain kinds of particles. There are
several commands in iVision which help you set up and perform those kinds of measurements. In this tutorial you will
learn how to use them.
We will use the "Multi-Grain" image in this tutorial. Find and open it now.
Let us look at the procedures you might use to set up the measurements:
1.
Set the distance units,
2.
define the parameters you want to measure, and
3.
specify any annotation you want on the image to help you recognize the measured segments.
Keep in mind that not all of the procedures are required every time you do a measurement. Usually you will have to do
these setup steps only once and then you can do many measurements with a single command.
3.4.1
Setting Distance Units
Often the first step in measuring anything is to set up the distance units. Let us assume that we know this image was
captured with a specific 10X microscope objective and that we know the size of each pixel in microns. We can set up
iVision to take this information into account whenever we deal with image captured by this objective lens.
1.
From the Analyze menu select the command Define XY Units.
This command lets you build a list of possible “units” from which you can choose. At the start, there is only one
defined unit on the list, “•1:1 Pixels.” There are several ways to enter additional defined units. In this case we will
use some knowledge which we assume we already have about the size of the pixels in an image when we use this
objective.
2.
In the dialog click on the New button. Another dialog asks you for the name you wish to attach to this units
definition. Type in “My 10X” and click OK. Back in the Define XY Units dialog enter the formula “1 pixels = 10
µ(10X).” (To enter the “µ” character, hold down the Option key and type “m”.) The dialog should now look like the
figure below. Click on the Save button. If you have other known units, you could define them in a similar way right
now. For now, just click on the Done button and the dialog disappears.
Tutorials
75
Define XY Units Dialog Box
3.
Now that distance has been set up, you can attach that units definition to the "Multi-Grain" image. From the
Analyze menu, select the command Set XY Units. In the pop-up list you will see "My 10X" which you entered in
the previous step. Select that option. Notice that you could also place a calibration bar in the image. This would go
into the overlay of the image so it would not overwrite any of your image data. But for now, simply leave this option
unchecked, and OK the dialog.
Set XY Units Dialog Box
76
Tutorials
4.
Now in the Status palette, you can see certain location coordinates given in µ(10X).
Status Palette Showing the Units of the Image.
All size and position measurements are now done in the units of µ(10X).
IMPORTANT: If you define additional units in the Define XY Units dialog, you should try to keep the text you use for
the units definition distinct. So, for example, if you decide to keep this units definition, you should not use the term
“µ(10X)” for any other units definition.
Now that you have set the units on this image to be µ(10X), that information is saved with the image (if you save it as an
iVision image file, more on that later). Also, any new image that you create using the New Image command from the
File menu, or any new image that you capture using one of the commands from the Camera menu will have this
distance unit definition.
What if you want to transfer this distance unit definition to another image, or set of images? The Transfer Attributes
command of the Edit menu does this. The User's Guide describes the command on page 212.
3.4.2
Setting Up Measurements
There are two commands to help you set up the types of measurements you want to perform. Both are found in the
Analyze menu: Set Measurements and Measurement Options. These commands are usually performed once before a
set of measurements is done. In fact you do not even need to have an image open in order to use these two commands.
1.
First, select the command Set Measurements. This dialog lists many measurements you can perform on each
particle. Check the boxes labeled Sum, Mean, Area, and Minor Axis. These parameters give basic information
about each particle that is measured. The Sum parameter is the sum of all of the pixel values within the particle,
while the Mean is the sum divided by the number of pixels in the particle. The Area will be measured in the
distance units you have attached to the image. The Minor Axis is a measure to the diameter of each particle (it is in
fact the width of an ellipse that is fitted to the shape of the particle). It is also measured in the units you have
attached to the image. We want this parameter so we can limit the size of particles we will accept.
Tutorials
77
Set Measurements Dialog Box
2.
To limit the size of particles we will accept, check the box next to Minor Axis under the column titled Limit?. Enter
100 for the Min, 100,000 for the Max. This will reject all of the small segments, those less than 100 µ(10x) (which
corresponds to 10 pixels, recall from our defining formula of 1 pixel = 10 µ(10x)). Since we expect no particles over
100,000 µ(10x) (or 1000 pixels) in diameter, this will measure only the big ones.
3.
You don’t have to do anything about the checkbox that reads Single Measure: Column-ordered, or the line below
it, Max. Number of Segments, since you are performing more than one measurement.
4.
It is sometimes handy to create a map of the segments, classified by color according to their relative sizes (or some
other criterion). To do this, check the box labeled Classify According To, and from the pop up list select Area.
5.
Finally, click on the OK button.
6.
Next, select the command Measurement Options from the Analyze menu. We must decide which color segments
we will be creating and measuring. Select yellow from the list of Segment Colors. Fill in the other check boxes as
you see in the figure below. We will include interior holes in the segments as part of the measurements since we
don’t expect the grains to actually have holes. Later on, we will show an application where we don’t want to include
the interior holes.
In most cases you should ignore segments that touch the edge of the ROI. When a segment touches the edges of the
ROI , you cannot be sure how big it really is, so its area computation biases the distribution of areas of whole
particles. We will choose to annotate the image by drawing an outline in the drawing overlay layer around each
particle that is measured. Choose the red color from the pop-up list of color for the Outline/Number Color. You
can enter any name you want for the results window. The default of 1000 measurements will be adequate for this
tutorial. If you plan to measure many particles over multiple images, you may want to increase this number. Since
we are measuring particles in a single image, we won’t label the rows in the results window. But if you were
measuring particles in multiple images, you might want to place the image name on each row of the results window.
Finally, OK the dialog.
78
Tutorials
Measurement Options Dialog Box
3.4.3
Measuring Segments
You must first segment the image in order to measure its particles. While we used a rather elaborate technique to
segment the "Multi-Grain" image in the last tutorial, we will just use a simple one here.
1.
With the "Multi-Grain" image as the front window, select the Segmentation command from the Analyze menu.
Enter 110 and 255 for the Min and Max values, choose the yellow segment color, and then OK the dialog.
2.
This gets most of the segments, but leaves many of them touching. To separate them, go to the Analyze menu and
select Modify Segments. Fill in the dialog as in the figure below. Be sure you use the yellow segment color. OK the
dialog. An image called "Multi-Grain.F" is formed with better-separated segments.
Tutorials
79
Modify Segments Dialog to Help Separate Touching Grains
3.
Once setup is done, the measuring step is trivial. Now measure all of the segments in "Multi-Grain.F" at once by
selecting the command Measure Segments from the Analyze menu.
The segments which satisfy the criteria are measured and outlined. A new "Measurement Results" window is created
behind all of the existing windows. In addition, if you checked the box Classify According To in the Set
Measurements dialog, there is also another image window behind the results window which shows the color coded
classes of particles. If you have other measurements to perform, for example on other images, you could do them now,
and the results will be collected in the same Measurement Results window (until you reach the maximum number of
measurements). To view the results, bring the Measurement Results window to the front by selecting it from Window
menu or by clicking in its title bar.
Example Results Window
Don’t discard this results window; we will use it in the next session to give a distribution of the mean intensities of
the particles. This results window can be saved as a text file so you can import it into a spreadsheet or word processing
document. You can also copy and paste the contents of the Measurement Results window to a spreadsheet or word
processing document.
Let us also look at the window called “Multi-Grain.Classes”. Select this window name from the bottom of the Window
menu. You see this window has all of the measured particles separately color coded by their area. This image contains
floating point data. If you move the mouse cursor into the image and watch the value field on the Status palette, you see
that the pixel values on each particle are all of the same. In fact the pixel value within each particle is exactly the area
value which is calculated by the Measure Segments command and placed into the table of results. You can close this
image (click in its go-away box in the upper left corner of the window).
80
Tutorials
Classes Window Showing the Particles Color Coded by Size
Now we will repeat the measurement command, but this time just to measure a few of the segments. (In a later tutorial,
you will learn how to measure a single particle by pointing to it with the wand tool.) First, Let us remove the red outlines
that show each measured particle.
4.
Make sure the "Multi-Grain.F" image is the front window (its title bar should be highlighted). If it is not, select it
from the list of windows at the bottom of the Window menu. From the Edit menu, select the command Clear All
Drawings. This removes all of the red outlines from the drawing layer overlay.
5.
Now go to the Tools window and click on the freehand ROI tool
6.
Move the cursor into the "Multi-Grain.F" image and draw an ROI around a few of the segments. Be sure to fully
enclose all of the segments you want to measure, because any segments that touch the ROI boundary will be
ignored.
.
Placing an ROI around a few of the segments
7.
Since we want these measurements kept separately, go to the Measurement Options command in the Analyze
menu and change the name of the results window to be "Limited Results".
Changing the name of the results window in Measurement Options
Tutorials
81
8.
Now do Measure Segments again. This time, only the segments within the ROI are outlined, and the new results
window contains measurement results for only those segments.
Only segments within the ROI were measured
Now you can continue to outline groups of particles and measure them, or you can capture new images and segment
them, then measure segments in those images. You do not need to return to the Set Measurements or Measurement
Options commands again unless you want to change some of the those options.
There is also a wand tool that helps you point and measure individual segments. You will see later how to use that in a
later tutorial.
Before continuing with the next lesson, close all of the windows except the one called "Measurement Results".
3.4.4
Distribution of Parameter Values: Graph
Now let us use the measurement results to get a distribution of the mean intensity levels on the segments. You can use
the same techniques to get the size distribution.
1.
Find the "Measurement Results" window and make it the front one (select it from the list of windows at the bottom
of the Window menu). Looking at the Status palette, you can see that the height of this window is probably around
60. Since there is one measurement per row, this number tells how many particles were measured.
2.
Click at the top of the column labeled Mean. That action selects the one column as the ROI. The data values within
an ROI are shown in red underline when the data is displayed as text. Notice that when you clicked at the top of the
Mean column, only the values in that column get displayed in red underline.
3.
Now get a histogram of the mean values: From the Analyze menu, select the Histogram command. Make the
number of bins 20. Select on ROI and check the boxes labeled Use Data Minimum and Use Data Maximum.
Then OK the dialog.
82
Tutorials
Histogram Dialog Box
4.
A new graph window appears. We will now make this plot look pretty so you can use it directly in reports.
Original Histogram Plot of the Mean Densities of the Measured Particles
5.
Click-and-hold on the label “Bin Value” at the bottom of the plot. A pop-up menu shows several options. Select
Label. In the dialog that appears, type in “Mean Intensity” and click OK.
6.
Click-and-hold on the Y-axis label, which currently reads “Pixel Count”, and from the pop-up menu select Label.
Type “Particle Count” for the new label and click OK.
7.
Click-and-hold on the title line of the plot which currently reads “Histogram of Measurement Results”, and from the
pop-up menu select Label. Type “Distribution of Mean Intensity” for the new label and click OK.
8.
Again, click in the plot window and select X Axis from the pop-up menu. Another dialog that appears:
8a. In the Scale section, Uncheck the Use Data Min./Max. option.
8b. Type in your own Minimum and Maximum values. We used 100 and 200 since those numbers spanned the min.
and max. mean intensity values found in the original plot. You can use any numbers you wish for the Minimum and
Maximum scale values.
8c. In the Number Format section, set the decimal places to 0.
Tutorials
83
Changing X-Axis Options in the Graph
9.
You can size the plot by clicking in the lower right corner of the plot window and dragging it.
Example Graph of the Mean Intensity Distribution
You can copy and paste the graph to another application (Copy from the Edit menu), you can print the graph (Print
from the File menu), and you can export it as a PICT or TIFF file (Export: to File from the File menu).
Dispose of all of the open windows before proceeding.
84
Tutorials
3.4.5
Measuring Donut Shaped Regions
Sometimes, you need to measure particles with holes, and you do not want to include the holes in the measurements.
1.
Find and open the image called "Gray Histology". This image has several dark circular objects whose area must be
determined. (The "Gray Histology" image is courtesy Beth Ann Nobel, H.T., Thomas Jefferson University)
2.
When working with PICT or TIFF files, you may look at the Status palette and notice that the units attached to this
image are µ(10X). This distance unit definition was the last one you set. iVision automatically assigned the last units
you specified to PICT and TIFF files. You can change the units back to 1:1 Pixels using the command Set XY
Units.
3.
Select the Segmentation command from the Analyze menu. Set the minimum intensity to 23 and the maximum
intensity to 95. Set the Segmentation Color to blue color and OK the dialog.
Segmentation Dialog for the "Gray Histology" Image
Tutorials
85
4.
Now clean up the segmentation using Modify Segments twice. Using Modify Segments twice helps to remove
small particles and also smooth out the edges of the segments.
4a. The first time, use the Open option with the mask set to the largest (5×5).
4b. The second time, use the Close option also with the largest mask.
Each time, be sure you have the color set to blue.
Modify Segments Dialog for the Close Operation
86
Tutorials
5.
Now use the Set Measurements command to set up the measurements we want to do. We are going to measure only
a single parameter: area. Make sure all of the other measurement checkboxes are unchecked as shown in the dialog
below.
Set Measurements Dialog Box
6.
For this case, we will also check the box labeled Single Measure: Column Ordered. This will report the results
for the different segments in columns instead of rows. Since we do not expect there to be more than 10 segments,
leaving the default value of Max. Number of Segment equal to 10 does not hurt anything. This defines the width of
the results table, which you should choose to be a little bigger than the number of segments you expect to measure.
You will see that the results table will contain some zero valued columns for segments which do not exist, but this
does not matter.
Tutorials
87
7.
Next, select the Measurement Options command from the Analyze menu. In this case, DO NOT include interior
holes since it is precisely the donut shaped regions which are of interest. Also, number the segments as well as
outline them. Be sure that the Segment Color is blue and OK the dialog.
Measurement Options Dialog for the "Gray Histology" Image
8.
Finally, select Measure Segments from the Analyze menu. A new Measurement Results table is created in the
background. Make it the front window. You see that the columns are labeled “Area#1, “Area#2,” etc. These are the
area values for each of the particles found in the image. Since there were likely less than 10 particles found in the
image, some of the columns have zero in them.
Single Measurement, Column-Ordered Results
If we want, we can get the area of the holes also. We perform the measurement again, this time including holes. Then we
take the difference between the results.
9.
Make the image "Gray Histology" the front window again.
10. Remove the outlines and numbers: From the Edit menu select the command Clear All Drawings.
88
Tutorials
11. From the Analyze menu, select Measurement Options. This time, check the box Include Interior Holes In All
Measurements. Change the name of the results window to “Measurement Results Filled.” OK the dialog.
This time, include the interior holes, and rename the Results Window.
12. Do Measure Segments again. Now you have another results window, this one called "Measurement Results Filled".
You can see it by selecting it from the list of windows at the Window menu's bottom.
Tutorials
89
13. We want to take the difference between this results window and the results window from the previous measurement
to get the area of the holes. From the Math menu select the command Image Arithmetic. You want to subtract the
results including holes from the results not including holes. Fill in the dialog as in the figure below. Then OK the
dialog.
Image Arithmetic Dialog to Compute the Areas of the Holes
14. A new window is created which has the results of the difference for each column.
Computed Areas of Holes
Dispose of all of the open windows before going on to the next tutorial.
3.4.6
Measuring Intensity Changes Over Time
In the previous session, you saw how to create column ordered results when measuring a single parameter. One primary
application of this is in measuring intensity changes over time. For example, suppose you identify several cells whose
intensity you wish to monitor. If the cells are immobile, you can do the following:
1.
Use the Set Measurements command to select only the sum or the mean intensity values to report. Also, check the
box to place the results into a column ordered results table.
2.
Capture a single image. Use the segment drawing tools to outline the cells of interest.
3.
Periodically capture another image into the same window and measure the segments. (In most acquire commands,
use the Into Front Window option to capture the image into the same window.
When you are finished with the series of image captures and measurements, each column of the table gives you a time
history of the intensities within each cell.
90
Tutorials
This repetitive series of steps is best done within a script. If you want to jump ahead to learn how to make scripts, see the
tutorial on scripts later in the manual.
3.4.7
Area Fraction and Other Particle Summary Results
The Quantify Segments command measures area and intensity information on all of the segments and reports a single
line summary. Quantify Segments uses the limits defined in Set Measurements and the additional conditions defined in
Measurement Options when it determines whether to include a specific segment in the computation.
Example Results Window from the Quantify Segments Command
For example, you can use Quantify Segments to determine area fractions. Area fractions are the percentage of total area
occupied by a specific type of material or stained specimen. IMPORTANT: For area fraction calculation accuracy, you
should probably NOT ignore segments which touch the edge of the ROI and you should probably NOT include interior
holes in the measurements.
3.4.8
Manual Measuring
There are several more commands in the Analyze menu which help you to measure particles and regions.
The Measure ROI command performs all of the measurements that you specify in the Set Measurements command,
but it does this on the region defined by the interior of the ROI. Use this as a quick way to get a measurement on a
region, without drawing segments. Notice that this command has the command key Command-1 (Cmd-I).
You can also measure lengths of particles manually using the Measure Lengths tool. Select the tool from the Tools
window. Click on one end and then double-click on the other end of a particle. To measure the length of curved lines,
click once at each point along the curved boundary and double-click when you are done. Each subsequent measurement
is added to the results window.
The Measure Angles tool works the same way. Select the tool. Click once on the starting point, once at the vertex, and
double-click at the ending point. This tool measures the inside of the angle that you just drew.
The Measure Length and Measure Angle tools on the Tools palette.
For both Measure Lengths and Measure Angles, numbered lines are drawn in the object drawing layer of the overlay to
show where you have done the measurements. These can be deleted by using the Drawing arrow tool to select and then
cut or delete the objects.
Tutorials
91
3.5
Tutorial 5: Extracting More Intensity Information
Besides particle analysis there are several additional commands in the Analyze menu which help you extract information
from images. Many of these are designed to give you different ways of looking at the intensity levels within an image.
3.5.1
Extracting Plots of Intensities
The Histogram command gives a count of the number of pixels at each possible gray level in the front image or data
window. You have already used the Histogram command to get a distribution of the mean intensity within each particle.
You can also use it to get the histogram of intensities within an image. Open the "16Bit XRay" image and try the
Histogram command in Analyze window. The result is reported in a graph which can be exported or copied and pasted
into another application.
Example Histogram Plots:
Bar graph on left, Line graph on right
The histogram is reported as a bar graph. You can change this to a line graph and back as follows:
92
1.
Click in the plot window.
2.
In the pop-up menu that appears, select Gallery, and then from that menu, select Line or Bar. A line graph is
shown above.
Tutorials
Next is the Row/Column Plot command.
1.
To use this command, first open the "Gel" image.
2.
Select the rectangular ROI tool from the Tools window and draw an ROI from the top of the image to the
bottom, exactly covering one lane of the gel.
Make an ROI to cover one lane of the gel
3.
Now go to the Analyze menu and select the Row/Column Plot command. Choose the Row Sum on the ROI
and OK the dialog. This gives a plot of the sum of the pixel intensities on each row.
Row/Column Plot Dialog Box
4.
Result of Row/Column Plot applied to the ROI
The areas under each peak represent the total sum of all of the pixels within each band. You can measure these
areas. To do this, you need to draw an ROI around a peak. You cannot draw ROIs on this graph, so change it to
an image by following these directions.
While viewing the "Gel.sum" plot, choose View: as Image from the View menu. Now you can draw an ROI
around one of the peaks.
Tutorials
93
5.
Select the Set Measurements command in the Analyze window and set it up to measure only the sum (and
don’t select column ordered results this time). Now use the rectangular ROI tool and drag an ROI around one of
the peaks. Then select Measure ROI from the Analyze menu (or type Cmd-1). Continue to draw new ROIs
around each peak and measure all of the peaks. You can also drag the ROI to the left and right by holding the
option key down and clicking within the ROI.
(For a more detailed gel analysis product, ask us about ONE-Dscan.) The results of these measurements go into
a Measurement Results window which is placed behind all of the other windows.
Sometimes, you will want to find the pixel values along some slice through the image. (NOTE: This is sometimes called
a “histogram” although the term “histogram” is correctly applied only to the distribution of pixel values).
6.
Open the "16Bit XRay" image or make it the front window. Select the multi-line ROI tool (below the oval ROI
tool in the Tools window). Draw a line along the spine of the subject. If necessary, you can click at more than
one place to make a piecewise linear ROI. At the end, double click to finish.
Multi-part line ROI
94
6.
Go to the Analyze menu. At the bottom is a hierarchical menu called Extract. From that list choose ROI
Values. The result is presented in a graph view, giving the values of the pixels along the linear ROI that you
drew. Alternatively you can view this information as text. (Select the view you want from the View As
hierarchical menu at the bottom of the View menu).
7.
Another alternative to get the values along a boundary is the Extract: ROI Boundary command. Bring the
"16Bit XRay" image to the front (click in its title bar or select it from the bottom of the Window menu). Again,
go to the bottom of the Analyze menu and select the ROI Boundary option from the Extract submenu.
8.
The results are presented as a three-column table showing the (x,y) coordinates of each point along the ROI and
the intensity values at each point. These commands can be applied to any ROI, not just linear ROIs.
Tutorials
3.5.2
Density Calibration
There are nonlinearities in most image acquisition systems. Some, such as film scanning, are known to be worse than
others are. If you have a standard image with known intensities, you can correct for these nonlinearities. The idea is to
create a table with measured intensity values and known intensity values then use this table as a mapping function which
transforms each pixel value in an image into calibrated intensity values.
In this session we will again work with the image called "16Bit XRay". Open that image or bring it to the front if you
have it already open.
1.
There are two support files which we need in order to calibrate the intensities in this image. Find and open the files
called "Standard Image" and "Standard Values".
"Standard Image" and "Standard Values"
2.
The "Standard Image" contains squares of known density values. We will treat this image as if you had captured it
from a specimen with known density squares. We have already drawn in segments which will help us measure the
mean values within each of the squares. Normally, you would do this yourself.
3.
Go to the Analyze menu and select the Set Measurements command. Choose only the Mean value parameter (Do
not check the Single Measure: Column Order Results option. You want these results row-ordered.). OK the
dialog.
4.
Select the Measurement Options command and make sure the Segment Color is green. It will not be necessary to
outline or number these segments. Name the results window “Measured Intensities” and OK this dialog.
5.
Finally, with the "Standard Image" as the front window, select Measure Segments. To see the results bring the
"Measured Intensities" window to the front.
Tutorials
95
Measured Intensities from the "Standard Image"
6.
Column # 1 forms part of the table we need. The other part of the table is found in the "Standard Values" window.
Now we are ready to calibrate the intensities on the "16Bit XRay" image. From the Analyze menu, select Calibrate
Intensities.
Calibrate Intensities Dialog Box
7.
The image you want to change is the "16Bit XRay". The measurements are found in the window named "Measured
Intensities", in column #1. The standard values are found in the window named "Standard Values", in column #0.
Experiment with the best fitting curve to find the one that works best for this set of data. This curve shows how the
data will be transformed. Then click OK.
A new image is created. This window contains floating point data for the best possible accuracy, calibrated to values
between 0 and 10. You can now save this image as a calibrated intensity image and do all your intensity measurements
on this.
96
Tutorials
3.6
Tutorial 6: Scripting
3.6.1
Basic Scripting
Researchers need to create their own protocols, teachers and students need to experiment with alternative methods, and
technicians often need to automate repetitive tasks. The script is the method iVision uses to address these issues. A script
is simply a sequence of commands selected from the menus.
In this tutorial you will learn how to make and edit scripts.
3.6.1.1 Editing a Script
Let us start with an existing script that is distributed with iVision.
1.
From the Script menu, select the Open Script command.
2.
Find the "Tutorial Scripts" folder within the Scripts folder within the folder, "iVision 4.0 User Folder".
3.
Click once on the script called "Background Subtract", and then select Open Script. A script window appears.
Example Script Window
The commands that make up the script are shown in a scrollable list in the script window. The "Background Subtract"
script performs a background subtraction on the "Chromosomes" image. To estimate the background, the script applies a
series of morphological erosion filters (erosion computes the minimum value in a neighborhood). Then the script
subtracts that estimated background from the original image.
(Before continuing with the script itself, it is worth mentioning that there is another common problem in the image
capture process. This problem is due to “uneven illumination.” Although many people think of using background
subtraction for this problem, there is a much better method to correct for uneven illumination, called “flat field
correction.” This is covered in the command Image Ratios under the Enhance menu.)
Tutorials
97
Whenever a script window is open, a new floating palette appears:
The Script Commands Palette
You will notice that some of the commands in this window (Cut, Copy, Save, Print, etc.) are duplicates of commands in
the menus. However, these commands apply only to the front-most script window, not to image windows. When a script
is open the commands in the menus are recorded into the script, so you must use the buttons in the Script Commands
palette to operate on the script itself.
Scripts are opened, by default, with recording turned off, so that they can’t be changed by accident. To examine or edit a
script, recording must be on. The Record ON/OFF button at the top of the script controls this.
1.
Click once on the Record OFF button, so that it changes to Record ON.
Now you can look at the dialog and parameters that are used by each command in the script.
2.
Double-click on the first Morphology command in the script.
The dialog for that command appears and shows you that it will perform a 5×5 erosion and place the results into a
new window. Click Cancel in the dialog. This script is made to operate on the "Chromosomes" image. You need to
add an Open command in the script so that it will open the image before performing the rest of the commands.
3.
Click once on the Change Window command at the top of the script.
4.
Select the Open command from the File menu,
5.
Find the folder that has the images and select the "Chromosomes" image and click Open.
Instead of opening the image, the Open command appears as the first item in the script. This is how you make a
script. Just select menu commands as if you were performing the operation. When a script window is the active
window, the script intercepts the command and places it into the script.
Now run the script:
6.
Click on the Run button at the top of the script window. The script is self-running and it displays a series of alerts
that tell you what it is doing. When it is finished, the script window comes back.
Notice the script left two windows on the screen. Let us edit the script to delete both of those windows and go into a loop
that performs the same commands over again several times.
7.
Scroll to the top of the script if it is not already there.
Click on the first command, which should be the Open command you inserted earlier.
98
Tutorials
8.
Select Dispose All Images from the Window menu,
Dispose All Images closes all of the windows without asking you if you want to save them. You are recording the
Dispose All Images command at the start of the script so that existing windows do not confuse the script. The script
will open the one window it needs by itself.
Another handy command is the Dispose Image command. When you know that a certain window will be of no use
from then on, in a script, you’ll want to use Dispose Image or Dispose All Images to get rid of it instead of Close
Image, which may ask you if you want to save.
NOTE: Because we just scripted the Dispose All Images command, remember to save all of your data before you run
this script!
9.
Click the Start Loop button on the Script Commands palette.
10. Scroll to the bottom of the script and click on the END line.
11. Click the End Loop button on the Script Commands palette.
The End Loop command loops back to the Start Loop command at the top of the script.
12. Enter 5 for # of Iterations to tell it to perform the same set of commands 5 times. Click OK.
End Loop Dialog Box
13. Click on the Run button again.
When you get tired of the script running, press the escape key at any time that there is not an alert showing on the screen.
The script stops. Now let us delete the changes we made to the script.
15. Scroll up to the top of the script window.
16. Click on the Dispose All Images command at the top of the script.
Then shift-click on the Open command.
The commands Dispose Image, Start Loop, and Open should now be highlighted.
17. Click the Clear button on the Script Commands palette to delete these command lines from the script.
18. Scroll to the bottom of the script and click on the End Loop command.
19. Click the Clear button again.
Tutorials
99
3.6.1.2 Not Editing a Script
While you are looking at the "Background Subtract" script, you may want to open the "Chromosomes" image without
scripting the Open command. To do this, turn the script off:
1.
Click on the Record button until it says, "Record OFF".
Most of the buttons in the Script Commands palette will be dimmed. You will still be able to save and print the
script, and to revert to an earlier saved version.
The script window is locked against editing, so you cannot now double-click on the recorded commands to open
their dialog boxes.
2.
You can now perform commands from the menus without recording those commands. For example, choose the
Open command and open the "Chromosomes" image.
3.
Click the Run button to run the script.
Recording is off, but the Continue and Run buttons still work.
3.6.1.3 Recording Commands vs. Using Commands
If you try to use the Edit menu's Cut, Copy, Paste, and Clear commands, you will record them in the script instead of
editing the script. Instead, use the Cut, Copy, Paste, and Clear buttons on the Script Commands palette.
Likewise, the only way to close a script window is to use the go-away button in the upper left corner of the script
window:
Click the red circle to close the script window.
Close the "Background Subtract" script and any windows which might still remain. Do not save any changes.
100
Tutorials
3.6.2
Allowing Dialog Interaction in a Script
Some commands, such as Segmentation, require user interaction with the dialog. We can easily build this into scripts.
For this example, we will consider the texture segmentation algorithm which you learned in a previous tutorial.
1.
Open the script called Texture Segmentation.
Texture Segmentation Script Showing a + in the Dialog Column
2.
You will notice that there is a column in the middle of the script which has a “-” symbol for most of the lines, except
the command line with Segmentation on it, which has a “+”symbol.
This column indicates whether you want the dialog for that command to appear when it is reached. A “+” in this
column tells the script that you do want the dialog to appear when this command is reached so the user can enter
new values as the script is running. A “-” in this column tells the script not to display the dialog when this command
is reached, and instead just use the dialog values you entered when you made the script.
Some commands in a script, such as Tile in this script, have neither a “+” nor “-” symbol next to them. These
commands do not have a dialog.
3.
With script recording OFF, open the image called "Curds&Whey". Then click on the script’s Run button.
4.
When the script reaches the Segmentation command, the Segmentation dialog appears. You can then interactively
segment the image by moving the upper threshold to about value 150 and clicking OK. When you do, the script
continues with the next command after Segmentation, the Transfer Attributes command.
Close this script and the images to continue with the next session.
Tutorials
101
3.6.3
Allowing Drawing Interaction in a Script
Sometimes, you want the user of a script to place an ROI or some other drawing item in an image before continuing with
the next set of commands. In this session you will learn how to do that. Find and open the script, "Color Sharpen".
"Color Sharpen" Script
The Alert stops the script for user interaction
1.
In the middle of the script, you see the command named Alert. This was placed in the script by clicking the Alert
button in the Script Commands palette.
Turn on recording. Double click on the Alert line in the script to see its dialog.
Alert Dialog Box
2.
This dialog allows you to compose a message to the user. It also has the option to continue the script, suspend the
script or stop this script (and all scripts it may have been called from) at this point. Cancel this dialog so we can run
the script and see how it works.
3.
Turn off the script, open "Color Image", and then run the script.
102
Tutorials
4.
When the script reaches the Alert, it displays the message:
Message Displayed When the Script Reaches the Alert Command.
5.
When you click OK, you are free to create the rectangular ROI you wish to process. The Script Status palette
opens. The “Suspended” state indicates that you can make any needed changes and then continue the script from
where it left off.
The Script Status Palette
After creating the rectangular ROI, click on the Continue button in the Script Status palette. The script will then finish.
Close the image and script without saving them to continue with the next session.
3.6.4
Attaching Scripts to Function Keys
Sometimes, a script is so useful that you will want to use it many times. In that case it can be cumbersome to select the
script from the Run Script dialog each time. Fortunately, you can create a one-button way to run such scripts, by
assigning them to function keys on the keyboard. To illustrate this, we will use the "Color Sharpen" script from the
previous example.
1.
Go to the Edit menu and select the command Assign F Keys.
If that command is dimmed, you probably have a script as the active window. Either turn the script off or close the
script window.
2.
When the dialog appears, click on the F9 line in the dialog box. Then go to the Script menu and select Run Script
from the menu.
Tutorials
103
3.
In the Run Script dialog, find the "Color Sharpen" script and click Run Script.
You will see the name of the script appear in the Assign F Keys dialog next to F9. You may enter a different name
for the script. This name will be used in the FKeys palette (described below).
Assign F Keys Dialog Box After Setting the F9 Key
4.
Just for exercise, let's assign another command to a function command.
4a. Click on the F10 line in the dialog box.
4b. Select the New Image command from the File menu.
4.
OK the Assign F Keys dialog.
Now you can run the script by pressing a single button on the keyboard.
5.
Close all of the open windows and open the image "Color Image".
6.
Press the F9 key.
That key runs the "Color Sharpen" script, which is described on page 102.
104
Tutorials
A palette of F-key buttons lists all of the assigned function keys. You may find these on-screen function-keys useful in
the dark in a microscope room.
Choose Show FKeys command from the Window menu.
FKeys palette with two assigned keys.
You can click on the button in the window to perform the action, or use the keyboard as before. You can make the
palette smaller by clicking on the green zoom button. (The zoom button is the right-most round button on the title bar.
It's green when you hold the mouse over it.)
Zoom button
FKeys palette after clicking zoom button.
Click on the close button (the red circle on the left of the title bar), or choose Hide FKeys in the Window menu to close
the FKeys palette.
3.6.5
Querying the User with iVision Variables
A script often needs specific information at the time that it is executed. For example, you may want to know how many
times the user wants to execute the commands in a certain loop, or you may want to enter different parameter values into
some command dialogs based on conditions that may change each time you run your experiment. This is where the
iVision variables come in handy.
The variables array is an indexed list of 512 numbers which can be accessed by almost any dialog that accepts numerical
parameters. There are several ways to set the values of variables while a script is running. In this session, we will show
you how to question the user and then use the iVision variables to make decisions in the script based on the user’s
answers.
Among the distribution scripts is a basic script called "Query User" which sets the units for the images it acquires. We
will use that script as the foundation for this discussion. Find and open the script called "Query User", and turn recording
on. We will examine this script in detail.
Tutorials
105
"Query User" Script
Top:
The first line is a label. You have already explored labels in a previous session of this tutorial.
Labeled lines are often used as the destination for Jump and If commands.
Enter Variables:
The next line is the Enter Variables command. We entered this command by clicking the
Enter Var button on the Script Commands palette.
Double-click the Enter Variables line in the script.
Enter Variables Dialog Box.
This command is described more fully in the Scripting chapter, on page 151, but here we can
see that it is set up to accept two numbers: the objective power (for a microscope) and the
number of images to capture. When you run the script, the dialog appears in slightly modified
form and only allows the user to enter numbers in the Value column. This information is
placed into the specified indexes of the iVision variables array (variables # 20 and 30).
Cancel this dialog because we do not want to save any changes to it.
106
Tutorials
Start Loop:
Next in the script is the Start Loop command. We scripted this command by clicking the
Start Loop button on the Script Commands palette. Everything between Start Loop and
End Loop will be repeated; the End Loop command specifies how many times the loop will
be repeated.
New Image:
This is followed by New Image. You would probably record the Acquire command here.
New Image is just a placeholder for demonstration purposes.
If:
Next is an If command. We scripted this command by clicking the If button on the Script
Commands palette. Double-click the If line in the script.
The If Command
This is set to jump to the label 16x when variable #20 equals 16.
The If command tests the value at variable number 20.
•
If the value in variable #20 is equal to 16, then the script jumps to the label 16x in the
script.
•
If the value in variable #20 equals 60 (or anything other than 16), then the script does not
jump to any label and it continues with the next line.
To make the situation a little clearer, we placed the label 60x here.
Recall the Enter Variables command stored the objective power in variable #20. So using the
If statement in conjunction with the Enter Variables command, we are able to conditionally
execute portions of the script based on the user response at the time the script is run. In this
case, the only thing that is done differently is setting the (x,y) units.
You can probably think of other things that you might want to do differently, based on the
microscope objective you used. Those things would be included where the Set XY Units
commands appear now.
Tutorials
107
End Loop:
This section of the script is finish by the End Loop command. Double-click on the End Loop
command in the script.
End Loop Command
The number of iterations are stored in variable #30
You see that the number of iterations is obtained from variable #30, where the Enter
Variables command stored the number of images that the user requested. Cancel this dialog.
Query:
You will see the Query command after the Dispose All Images command in the script. Script
this command by clicking on the Query button in the Script Commands palette. It is also
used to get information from the user. Double-click on the Query command in the script.
Query Dialog Box
This command allows you to program a question that the user will see when he runs the
script. The question may have up to three responses which are encoded into three buttons.
Only two of the buttons are used in this example.
The number of the button chosen by the user is placed into the specified iVision variable. If
the user clicks on the Another button, iVision will set variable #10 to 0. If the user clicks on
Quit, then iVision will set variable #10 to 1.
If:
108
This information is then used by the final command, If. Double-click on the final If command
and you will see that it tests to see if variable number 10 equals value 0 (which would indicate
that the user pressed the button Another). If so, it makes the script jump back to the label
Top, at the beginning of the script.
Tutorials
Before running the script, please open the iVision Variables window so we can see the values changing.
1.
Turn off the script.
2.
Then select Show Variables from the Window menu.
3.
Return to the script and click on the Run button to see how the script operates.
Once you have tried the script a few times, there is one enhancement we think you might want to consider. Let us add a
few lines to the script to keep track of the loop number within the loop. Sometimes the loop number is valuable in setting
other parameters in analysis.
We will use variable #5 to keep track of the loop index. We plan on using the following steps:
a.
Variable #5 must be cleared before the loop starts.
b.
Variable #5 must be incremented each time through the loop.
So please do the following:
1.
Highlight the command Start Loop in the script. When we add the next command, it will be placed above this
selected command.
2.
From the Script menu, select Set Variable.
Set variable number 5 to value 0 and OK the dialog.
Set Variable Dialog Box
This clears or initializes variable #5 to zero.
4.
Next, highlight the command New Image in the script.
This is the first command inside the loop, and we want to place a different command as the first command inside the
loop.
Tutorials
109
5.
Select the command Set Variable from the Script menu.
This time, select the radio button that allows you to do arithmetic on the variable. You want to add the number 1 to
the variable whose index is 5, so fill out the dialog as shown below and then OK the dialog.
Set Variable Dialog
This increment the variable #5 by 1
The new script is now complete. When you run the script. you will not see any difference, but the variable number 5 gets
incremented. We did not actually use the loop count from the Variables window anywhere within this example. To
make use of this loop count, you could place inside the loop any command whose dialog can access variables.
Close the script and all of the open windows to continue with the next session.
110
Tutorials
3.6.6
Advanced Script: Correlation Filter
In this example, we look at a script that performs a pattern matching operation using the Fourier Transform function in
iVision.
The problem you will explore is the following: You have a certain pattern or template that may be found within some
images. You want to find the exact location of that pattern. In this session, you will simulate this situation by creating a
template out of a portion of the "Washington" image. Then you will correlate the template with the original image so that
there is a peak value in the correlation output at the location where your pattern is found.
The pattern-matching algorithm you will use can be called a Phase Only Matched Filter. The mathematical formulation
of the filter is as follows:
(
)
D f x , f y = FFT( Data(x, y))
(
(
)
)
T * f x , f y = Complex Conjugate FFT( Template( x, y ))
€
€
G ( fx , fy ) =
( ) ( )
D( f , f ) T ( f , f )
D f x , f y T * f x, f y
x
y
x
( (
y
Output ( x, y ) = FFT −1 G f x , f y
))
€
The result, Output(x,y), is in the image domain. There will be a peak at the location in the image where the template is
found.
€
You have a script called "Correlation Filter" which implements this formula. Open that script using the Open Script
command from the Script menu and scroll to the top.
"Correlation Filter" Script
This script is fairly complicated and worth looking at in detail.
Tutorials
111
After setting up the process, the Transforms command executes the FFT with Magnitude-Phase output on the active
window. This gives the D(fx,fy) factor. Then the script brings the "Template" window to the front and performs the FFT
again. This gives T(fx,fy). Now a mathematical trick is used to implement the correlation formula given above. The
numerator, D(fx,fy) T*(fx,fy) can be performed by multiplying the magnitudes and taking the difference of the phases.
The next several lines perform the phase difference calculation: Data Phase - Template Phase. The result is left in the
"Template.FFTPhase" window. The formulas above show that the result must be divided by the magnitudes of the Data
and Template transforms. This is equivalent to setting the magnitude of the result to 1. That is done next in the script
with the Set ROI Value command. Then the inverse FFT is performed and the data is displayed. The next set of
commands set up measurements to find the maximum value in the correlation plane, finished by Measure ROI to get the
maximum value.
Once the magnitude of the peak is found, the Set Variable command is used to transfer that peak value to the Variables
array (variable number 10, to be exact). Then the Change Segment Color command uses that variable to set the segment
overlay color only at the peak. Modify Segments makes the red pixel bigger with a dilation. Finally, Transfer
Attributes copies the segment overlay from the "Correlation Plane" window to the "Data" window.
3.6.6.1 Running One Script from Another
This script expects to work from two images. The pattern (the “template”) to search for is one image, and the image in
which to search (“data”) is the other. Furthermore, the pattern must be prepared in a specific manner. To prepare the
template window we will use a second script. Once it has prepared the template, it will run the "Correlation Filter" script
to do its job.
Open the "Set Up Correlation Filter" script.
The "Set Up Correlation Filter" script.
This script defines an ROI on the "Washington" image and then allows the user to move the ROI to different locations
within the image.
112
Tutorials
The script then copies the image data from within the ROI and pastes it into the center of a new window named
“Template”. The Barrel Shift command (Math menu) is then used to prepare the pattern for use by the "Correlation
Filter" script.
"Template" Image Before and After Applying the Barrel Shift Command
Notice that the Run Script command is, itself, scriptable. This allows you to run one script from another. That, in turn,
allows you to break up complicated scripts into a number of simpler scripts. The script being run does not have to be
open, as long as it is available on disk. You can use up to 5 levels of scripts (that is, Script A calls B, which can call C,
which can call D, which can call script E).
Once the "Correlation Filter" script completes, the "Set Up Correlation Filter" script continues with the next instruction
(Change Window). It closes some intermediate windows and tiles the remaining ones.
Now let us run the scripts and see how well they work.
1.
Since scripts are not commonly open when you run them, close both scripts, and any other images that are open.
2.
Next, find and open the "Washington" image.
3.
Use the Run Script command in the Script menu to run the "Set Up Correlation Filter" script.
4.
When the script pauses, leave the ROI where it is. Just press Continue in the Script Status palette.
When the script completes, you will see a new window called "Location" and another, "Correlation Plane". It may look
bizarre, but it contains the information you want. In this image you’ll see a red rectangle. This is the location of the peak
value in the correlation plane. The window called "Location" gives the (x,y) coordinates of this maximum. If you have
done everything as described above, those values should read 85 and 115.
5.
Bring the window "Correlation Plane" to the front.
6.
Select Hide Segment from the Edit menu to hide the red dot.
7.
Move the cursor over to the (x,y) location (85,115). Use the Status palette to tell you where the cursor is. You will
notice that the bright dot is at this location.
8.
When you are finished, use the Dispose All Images command in the Window menu to close all windows.
Tutorials
113
3.7
Tutorial 7: Point And Measure with Wand Tool
In this tutorial, we will show you how to use the wand tool to point at and measure individual segments.
1.
First, define what properties you want to measure. Select the Set Measurements command and check the boxes for
Sum, Mean and Area only, and then OK the dialog.
2.
Next, select the Measurement Options command. Fill in the dialog as shown in the figure below. Make sure the
segment color is green and the outline color is red. Also, you must not check any of the boxes under the heading
Ignore Segments Touching ROI At.
Filling in the Measurement Options Dialog Box
3.
Now open the image called "Three Phase". It has a few clearly defined particles in it to measure.
4.
Next, segment the image. Use the Segmentation command in the Analyze menu with the min. and max. parameters
to 150 and 255, make sure that the color is green, and OK the dialog. This leaves several green segments in the
image.
5.
Select the wand tool
green.
6.
Click on one of the segments in the image. You can also click to the left of a segment. You see the ROI snap to the
outline of the segment. The wand tool places the ROI around the segment nearest your click point whose color you
have set on the Tools window.
7.
Now measure just this object using the Measure Segments command in the Analyze menu.
from the Tools window. Make sure the color in the Segment section of the palette is also
You can continue to measure individual segments by clicking on each one with the wand tool and then selecting
Measure Segments from the Analyze menu.
114
Tutorials
The green overlay covers up your view of the image itself. Sometimes this is not convenient, you may want to see the
image so you can distinguish more easily between the individual segments you want to measure and those you do not.
After the image is segmented, you can hide the segment overlay and still use the wand tool.
8.
Go to the View menu and select the command Hide Segment. You see the green overlay disappear, but the
segments are still defined.
9.
Now continue to use the wand tool to select the segments you wish to measure. As you click in the image, the
segment which is nearest and to the right of your mouse click point will be outlined by the ROI dotted outline.
If you use the Measure Segments command frequently on individual segments, it may be helpful to assign the Measure
Segments command to one of the function keys on your keyboard. You can then invoke the command with a single
keystroke instead of having to go to the menu every time.
10. With the image as the front window, go to the Edit menu and select the command Assign F Keys.
Assigning a Menu Command to an F-Key
11. Click on F9 with the mouse cursor then go to the Analyze menu and select Measure Segments.
12. OK the Assign F Keys dialog.
Now you can use the F9 key anytime you want to apply the Measure Segments command.
Tutorials
115
3.8
Tutorial 8: File Handling
You should be used to the standard Macintosh file Open and Save As commands. Although these are convenient
methods for interactive operation, the basic opening and closing commands require too much interaction to be useful
when you want to process a large number of images. For processing many images, you would desire something like a
“batch mode” of operation. That is, you might have a batch of files to which you want to do the same thing.
To address this issue in iVision, we have introduced ways of addressing collections of images called file sets. There are
three kinds of file sets:
Folder set:
A folder set refers to all the files within a specific folder, or to the folder itself.
Indexed set:
Indexed files have a base name and a count, or index value. Examples of indexed names are
"New Study 0000", "New Study 0001", etc.
List set:
List sets, also called file lists, can contain the names of images from all over your computer.
This is different from folder sets and indexed sets, which require all of the images to be in the
same folder.
Please pursue further details in the description of the Define File Set command, starting on page 188.
You usually use file sets from within a script.* The following example uses an indexed set, but it could just as easily use
a folder set or a list set. The definition of the indexed set in Define File Set looks like this:
Define File Set for the Folder Set “Images to Export”.
The start index is 1, so the first file in this set will be “Thiotimoline_001”. The result variable is set to 31. The result
variable can be used in scripts to determine when you have read all of the images.
*
116
The following commands use file sets whether or not they are scripted: Export: Sequence to Movie (File menu),
Sequence to Frames, and Frames to Sequence (Window menu).
Tutorials
3.8.1
Opening Files with a File Set
A simple example of a file set used within a script
The example script shown above uses a 'repeat loop' and a file set to open every indexed file within an indexed set. Here
is what it does:
Use File Set:
Before using a file set within a script, you must initialize the file set. Do so by recording the
Use File Set command from the Script menu.
(Commands like Export Sequence to Movie, Frames to Sequence, and Sequence to
Frames do not require Use File Set because they already provide information about the
starting frame number.)
This command tells iVision that we are going to use the "Images To Export" file set to open
images.
The Use File Set command recorded in this script
Repeat:
This starts the loop. Everything between this line and End Repeat will be repeated until an
exit condition (in Exit If) is met.
Open:
This command is scripted to open images from the file set "Images To Export", which is an
indexed set.
Tutorials
117
Open Dialog Box When Scripted
The first time the script runs this command, it will open the image “Thiotimoline_001”, then
“Thiotimoline_002”, and so on.
If the file set was instead a folder set, then the script would simply open the first file
(alphabetically) in the given folder. If the script used a list set, then the script would open one
image at a time from the list of images, in the order given by the list.
Exit If:
This command provides the only exit from the repeat loop.
Exit If Dialog Box
If variable #31 does not equal 0, then the repeat ends.
The variable 31 comes from the definition of the “Images To Export” File Set, where the
result is defined to go into variable 31 The possible values of variable #31 are:
Variable #31 = 0
Variable #31 = 1
Variable #31 = 2
if the last indexed file has not yet been opened.
if the last indexed file has been opened.
if an error has occurred.
So the repeat will end if variable #31 does not equal 0. The script will then continue with the
next command, END, at which time the script will end.
End Repeat:
This marks the end of the repeat loop. If the script did not exit at the Exit If command, then it
will again run commands starting from the Repeat line.
3.8.1.1 Running the Script
When you run this script, each image in the folder specified by the Folder Set will be opened in iVision. This simple
script can now be expanded to do more work with each image.
118
Tutorials
3.8.2
Processing Files with a File Set
This example extends the previous script to process and save each opened image to another folder.
First we need to define a second File Set to identify where the images will be saved:
Define File Set for the Folder Set “Exported TIFFs”.
This is a Folder set; it only defines the location for the saved files. Notice that the Result variable is set to 32, which is
different from the one used by the “Images to Export” set. This is important for handling error conditions in the script.
The workflow for the script is for an indexed image to be opened as before. Then a processing step will be performed
(we’ll use the Despeckle command). The processed image will be saved in a different folder and closed. Then the script
will repeat the process until all of the source images have been read.
Example of two file sets: one for Open and one for Save.
Use File Set:
There is now a second Use File Set command for the “Processed Images” set.
Tutorials
119
The Use File Set command recorded for the second File Set.
Despeckle:
This is an example of a command used to process the original image. Of course, you could
include any number of processing commands at this point in the script.
Save As:
This command is scripted to save images to the Folder file set "Processed Images".
Save Dialog Box When Scripted
With a Folder set each file is saved to the given folder using the image’s existing name.
If the script instead used an indexed set, then the name would be built from the File Set’s base
name, starting index and number of digits (e.g. “Image-001”). If the script used a list set, then
the script would save each image to the corresponding name given in the list (first image uses
first name, second image uses second name, etc.).
Dispose Window:
Once the file has been processed and saved, it can be disposed to make room for the next, and
to reduce the clutter when the script is finished.
Note that you could also follow the Save As command with an additional Exit If that tests variable 32, to detect errors
during the save. To make it clear which Exit If actually ended the script you would need to add some additional If
commands and Alert commands after the End Repeat to test whether variable 31 or 32 caused the loop to end.
120
Tutorials
3.9
Tutorial 9: Real Time Image Analysis
Sometimes you may want to analyze images as you are acquiring them, repeatedly updating the analysis results. You can
do this in iVision for Macintosh with the aid of scripting. Here is a typical script you might use to watch the intensity
values on the region of interest in an image:
A Script for Real Time Image Analysis
These are the important parts of the script:
Dispose All Images:
The script begins by disposing of all existing windows. This is not required by the other steps,
but makes it easier to run the script repeatedly.
Single Exposure:
The script then acquires a full frame image preceded by a preview. The preview lets you focus
the microscope or camera and select the field of view. You can also adjust the exposure time.
All of the script's other acquire commands will use this exposure time. The script names this
full-framed image, "RTA".
Alert:
Next, an Alert is used to tell the user what to do. Click OK on the alert message, draw an ROI
on the image, and select Continue from the Script Status palette. Draw the ROI around the
interesting part of the image to be measured in real time.
Tutorials
121
Single Exposure:
After this is done, the script moves the large window aside and acquires another image. This
image will prepare the way for the real-time analysis of all subsequent images. Basically, we
need to perform one measurement and display it as a graph. After that, iVision will update the
graph with each new acquisition.
Within this recorded Single Exposure command, the exposure time is set to equal variable
#255. iVision always stores the last exposure time to be used in variable #255, so this
command uses the same exposure time you used in the initial preview of the sample.
The image size is the ROI on the first image acquired by this script, "RTA". The image is
only the size of the ROI that the user has selected. Capturing on a smaller portion of the image
makes the process somewhat faster.
The image destination, which is the window into which iVision will place the data, is a new
window named, "Data". All future captures will be placed into this window.
Set Measurements,
Measure ROI:
We record the Set Measurements command to specify the quality that we want to measure.
This should be a single parameter because we want to collect the data into a column oriented
results table and plot the intensity versus frame number.
In this example script, we measure the mean intensity. Remember to check the Single
Measure: Column-Oriented option.
The Measure ROI command actually performs the measurement and places it into a
measurement results window. The new measurement results window will be created behind
all of the other windows.
Change Window:
This brings the measurement results window to the front so that we can display it as a graph.
We know the measurement results will be the back window, and we do not know its name for
certain, so we set the Change Window command is set to bring the back window to the front.
If we had wanted to know the results window's name for certain, we would have recorded the
Measurement Options command to set the result window's name.
View Options Graph:
We set the graph-view options to plot the mean intensities (column 1) vs. the frame number
(column 0).
The Columns options within View Options: Graph.
122
Tutorials
View As Graph:
This changes the textual measurements into a graph. It is the same data, displayed differently.
The other windows should have been moved sufficiently for you to see this graph while the
iVision is acquiring the data. If not, adjust the second Move Window command.
Change Window:
We need to bring the window "Data" back to the front so that we can put the future data into it
and so we can measure that window repeatedly.
Show/Hide…
We will be repeatedly acquiring a single frame of data. Every time we do, the Tools, Status,
and FKeys palettes and the Variables window will be hidden and shown again. Since this is
distracting, this script hides all of these palettes and windows. This step is not necessary.
Start, End Loop:
Everything between these two commands will be repeated 100 times. Double-click the End
Loop command to see its settings. This loop contains these two commands:
Single Exposure:
This command collects the 100 frames of data whose mean intensity you will see
plotted in real time on the graph.
Like the previous Single Exposure command, this one sets the exposure time to
equal variable #255 and it uses the ROI on the image "RTA".
This command puts the data into the front window. The preceding Change Window
command made certain that "Data" is the front window.
Measure ROI:
Once again, this command measures the mean intensity and puts the measurement in
the existing results window. Because that results window is being displayed as a
graph (thanks to the View As Graph command), you will see the graph update
immediately after the latest image capture.
The final result of this script is that you can focus on a sample that will change over time and measure the image (for
example, the image's mean intensity) in real time while the sample changes.
This script can be used as a starting place to perform other kinds of real time image analysis. You can, of course,
measure something else besides the mean intensity. You can also use Measure Segments in place of Measure ROI.
This would allow you to measure and plot the intensity values at more than one location on the image, at the cost of
being a little slower.
You can also:
• Plot real time histograms,
• Do real time Fourier analysis,
• Extract and plot a slice or line of data through the image in real time, and
• Get a real time plot of a row sum or column sum of the ROI.
Tutorials
123
Download PDF
Similar pages