BLOB 1.5.1

Program Notes: 31 July 2000

General

This program takes a PICT file and finds all the contiguous pixels in the image that are above or below a certain threshold value. It saves these contiguous areas, or "blobs" in a variety of file formats, some of which incorporate a conversion from pixel-based measurements to real distance (cm-based) measurements. The user may use freehand drawing to mask off certain pixels, allowing contiguous areas to be considered as more than one blob. In addition, it allows the use of "edit mode", in which blobs are treated as circles, which can be added/removed/altered by hand.

Memory Required: 4096K (not stress-tested)

Input File Types

PICT, TEXT

Input Limits

Both dimensions of the input PICT file must be less than 16384 pixels. (This ought ot be plenty!) The true maximum size is probably dictated by available memory.

Output File Types

New-style MacRail file, text Merge file (old style), or binary Merge file (new style)

ResTypes (not registered with Apple)

Application (Blob) = ‘qtBB’

Binary Merge file = ‘mRgE’

Operator Notes

  1. Choose New to open a new PICT file for processing. Set the threshold value by a) option-clicking on the image to select that grayscale value as the threshold (the cursor changes into what is supposed to be a cross--hairs over a dropper); b) typing in a specific value in the info window; or c) clicking or clicking and dragging in the grayscale gradient box of the Info Window.
  2. Draw a mask (the smallest brush size is sufficient to separate adjacent blobs) by clicking the pencil tool (Yes, I do realize that a "pencil tool" with "brush size" is a mixed metaphor) and selecting a brush size from the Info Window pull-down menu, and drawing. The command key turns the tool into an eraser. Whatever you draw black over will be un-masked. Although you do not see the underlying image while you draw, after you let go, the image will appear.
  3. Zoom in or out by clicking the zoom tool. Holding Command down turns the tool into a negative zoom tool. You can still sample threshold grayscales with the option key.
  4. Choose light objects or dark objects by clicking the appropriate button on the Tools window.
  5. Once you have drawn your mask, select Find Blobs from the Blob menu, and the program will look for blobs, based on the threshold you’ve set and the mask you’ve drawn. Each separate blob will have an "X" at it’s center of gravity. This point may occasionally not be within the blob itself, if the blob is a non-compact shape. This is normal, and is due to math (or physics, if you prefer). Don’t freak out.
  6. If you know (from other slices) that two or more blobs are really the same crystal, you can choose the arrow tool, and then choose two or more blobs (use shift-clicking to select more than one). Once you have the blobs selected, choose Join Blobs from the Blob menu.
  7. After the blobs are the way you want them, you should select Save... from the File menu. If you choose the MacRail style, the program will save the data in a text file at that point (after asking you for a name). If you choose either Merge format, the data must be converted from pixel-based to cm-based measurements.
  8. Converting. Blob will put up a dialog box for you to input the appropriate values for this sample. If you are running for the first time, these will be zeroes, except for the slice number (it searches the input file name for the last integer in the string, and puts that in as the default slice number. This will work if you name your files "ThisRock.001.PICT" or something similar.). On subsequent files, it will keep the values you used the previous time. You can put a "#" into the comment line to insert the slice number.
  9. Preferences can be set by choosing Blob Preferences... from the File menu. This allows you to set the colors for masking (never set the mask color to white - it won’t work) and blob drawing, as well as the default threshold value, and the minimum blob size, in pixels.
  10. Open Next will scan the filename of the current window, look for the last integer, and try to open another file in the same directory that has the same name, but with that integer incremented by one. If it doesn’t find one, then it should put up the standard select file dialog box. The Command Key for Open Next is [Command]-[Option]-o.
  11. Save, Close, and Open Next. The function should be obvious. The Command key sequence is is [Command]-[Option]-s
  12. Edit Mode. Clicking the button in the Tool palette with the blue circle switched to Edit mode, in which the blobs are portrayed the way they are saved – as circles. In order to modify circles, one or more must be highlighted by clicking (for the first one) and/or [Shift]-clicking (for all subsequent ones). They can be moved with the arrow keys or dragged with the mouse. The "+" key (or the "=" key) will enlarge, and the "-" key will shrink them, or by holding [Control] while dragging, they can be resized. Moving and sizing on the keyboard can be modified with [Shift] (decreases increment to 0.1 pixels) or [Control] (increases increment to 10 pixels). Circles can be created by double-clicking in a spot (gives a minimum circle, which will need to be enlarged), and can be deleted with the [Delete] key. Note that if Edit Mode is engaged after locating blobs in Blob Mode, any changes made while in edit mode will not be reflected in the Blob Mode display, yet it is the state of the Edit Mode display that gets saved in the output file.
  13. Opening files. If files are listed with a creator of Blob, then double-clicking in the Finder will open them in Blob. This is obvious for the PICT files, but will work with the TEXT files as well. If there are pre-existing Merge files with the slice number in their file names, and image files with the slice number in their file names (all slice numbers should be delimited with "."), then the blob data will be automatically read in, and the data displayed in Edit Mode in the appropriate window.

Program Notes

(1) Blob-finding algorithm. The program first creates a 2-D bit array (disguised as a 1-D array of chars) to represent the masked PICT. First it examines each pixel’s grayscale value (if they’re colors, then it uses the darkness value), and based on whether light or dark objects are selected in the Tools window, sets the corresponding bit on or off. It the examines each bit, and if it is masked, turns it off. It then scans the bits in order. If they are off, it marks the corresponding element in a 2-D char array accordingly and loops to the next one. If the current bit is on, then it begins a pseudo-recusive algorithm (using a stack instead of true recursion - Thanks, Rich!) that explores the bits representing pixels orthogonal to the current one. Note that it doesn’t look diagonally - this is why we can use a 1-pixel wide mask. MacRail looked diagonally, and we needed a 2-pixel mask. The algorithm keeps track of which pixel it just came from, so it doesn’t check that one, reducing computation time.

Known Bugs

(1) Setting Preferences colors only applies them to the top window.

(2) Brush and dropper tools don’t work on new windows opened using Cmd-O.

Planned Improvements

(1) Change masking into picture commands, so that it takes zero pixels to separate blobs. Current algorithm makes blobs systematically slightly smaller than they truly are, because some pixels that should be allocated to blobs are used in the mask. The use of "walls" in the algorithm is intended to facilitate this eventually. In order to continue defining a picture, though, the use of opcodes, or custom object stacks, or the picSave CGrafPort member, will be necessary.

(2) Implement interim saving of files, with threshold, colors, masks, etc.

(3) Remember window locations in Preferences.

(4) Explicitly remember current save directory and open directory.

(5) When dragging grayscale in info window, use color table functions to highlight that grayscale value in the image.

(6) Improve Info Window to have number of blobs, and last blobbed grayscale value.

(7) Remember grayscale value in Preferences.

(8) Have cursor become brush shape & size when drawing.

Release History

1.0 7 November 1996

1.1 19 November 1996

1.2 12 December 1996

(Program Notes hiatus)

1.5.1 15 April 2000

Authorship

This program was written by David Hirsch in Metrowerks PowerPlant C++ in November 1996. It supplants MacRail (Image Analyst), Edit and Convert in the Carlson QTA group data flow pathway.