(alias softwarepatents, computer-embedded patents).
ffii.org Foundation for a Free Information Infrastructure

MicroscopePictureStitching (MiPiSti)

author: Robert Gloeckner, language C++(STL) Tcl/Tk, OS independent, licence GPL2 or newer, see GNU.org for details.

picturepuzzle Suppose you want to analyse an object with your microscope which is much too big for one photo. Several programs offer to arrange charts to one overall picture. But very often those programs are not accurate enough (they may change scaling / orientation) and configuration is limited. These programs are not specialized for processing microscope pictures. That was the reason for me to develop my own microscope picture stitching program :-)

MiPiSti is designed for this purpose, but it can be used with all flat pictures (like scannings). The idea is (already working with bmp-files) that you have a sequence of (pairwise) overlapping pictures (see figure 1).

MiPiSti works in 2 steps. In the first mipisti calculates the offset position of each picture and its successor in the sequence of pictures. In the second step those offsets are used to put all pictures into one overall picture. It is planned, that image correction (lens errors (dust...) inhomogeneous illumination) will be done in this step as well (see task-tracker for details).

Basic functions work stable. The command line program ("bmp" or "fast") can calculate offsets and stitch a sequence of bmp-files as well as putting an scaling into the picture. There are scripts available to do automatic stitching.
A first GUI is finished. You'll find executables, sources, examples, etc. in the download-area.
See BUG- and Task-tracker for current limitations.
I've used this program to stitch/merge more than 500 particular pictures of 640x400x24 RGB, without problems.

Main page on GNA.org:

Main Page of MiPiSti: downloads, public area (support), browse CVS, submit patches, watch tasks ...
Filelist/Downloads - Daily Snapshot
Ask Questions
Submit a Bug
Open Tasks and coming features ;0)
Browse CVS


editing the filelist

Text-editor for editing the filelist (stitchlist) of bmps.
Save the filelist. After that press finish.

parameter form

Input form for parameters (see command-line-parameters).
method {0 1 2} which method for comparing pixels, default 0.
min-area: how many point minimum overlap of 2 pictures.
first_n: how many points to compare (more means slower but more accurate).
goto_q: quality minimum (for goto). Quality is the absolute distance between best and second best relative position (d>1) + signal-noise ratio per point (1 second_n: how many points to compare (refine, more points lead to better quality but take linearly more time).
second_q: quality up to which no refine is done.
zoom_factor: picture zoom factor (integer).
resulting_q: how fine is manually adjusting done. used for local refine later.
transp_sim_x/y: distance between transparent pixels in x/y-direction. 1 1 would is 100% transparency, 1 2 or 2 1 -> 50%, 2 2 -> 25% ...
OK: saves parameters to "mipisti.conf".

a first gui

This is the GUI #1, it is working fine (for me).
OK take the actual coordinates.
Skip discard picture2 take next one, picture1 will not change.
configure change parameters (see above).
old value discard changes in coordinates, reset to old values.
goto q take original values if quality is better than goto_q in configuration. stop at pair with less quality. this increases effectivity of the gui, because you only correct picture-pairs with less quality factor (see above).
finish take original values for rest of pairs.

scaling application

This is the scaling application.

How To Use:

Normally you start with adjust, which calls bmp/fast in background. If the resulting picture is not good enough you can use readjust to do corrections.
adjust.tcl (GUI#1)
Needs a compiled "fast[.exe]" and Tcl/Tk.
A GUI as a frontend for the command-line program and to correct stitching errors.
1. Give path to directory including pictures to stitch.
2. In the text-editor: delete all filenames you do NOT want to stitch.
2a. Save the list of pictures you want to stitch (e.g. stitchlist.txt). Press finish.
3. Give parameters and command line options (see howto use the command line program).
3a. The zoom-factor is used for resizing pictures to fit the screen.
3b. The resulting q-factor is used for the last local refine (after your manual adjustment).
3c. The transp-sim-x/y parameters are for simulating transparency. Setting them to 1 1 means fully transparent (each point invisible), 1 2 or 2 1 is 50% transparency (skipping one x or y point) and 2 2 means 25% transparency (slow).
4. The command line program ("fast") will be started, you can see the progress.
5. Now you can correct the pairwise stitching. You can move the second picture with the mouse, via keyboard or via the buttons. If a picture's quality is bad (or if it is a dublette), you can skip it, so that the next picture has to be arranged with tha actual picture. After doing so (or leaving it the way it is perfect), press OK to correct the next pair-stitching. If you press "Goto Q" you will go to a picture-pair with a quality-factor bigger than goto_q, which you can specify pressing configure.
6. You are asked for a filename to store the (corrected) positions to (mergelist).
7. After the correction, "fast" will be called again, to do a last local refine and to merge all particular pictures to a big one.

readjust.tcl (GUI#1)
Needs a compiled "fast[.exe]" and Tcl/Tk.
If the merged picture has some errors, you can correct them with this program. You are asked for a file like step 5 of adjust (mergelist). Then it works as adjust from step 3 on.

scale.tcl / scalewrap[.exe] (GUI)
Needs a compiled "fast[.exe]" and Tcl/Tk.
A program for putting a scale into a (bmp)picture. In the top part you can enter the gauge you were using. Below that is a form in which you can enter a standard gauge for the microscope you are using. Below that you can choose 4 positions for the scale.

MiPiSti.scr filepath
Better use adjust.tcl or readjust.tcl
will create a list of files, invokes emacs for you to edit the list and then stitches using 25, 250, 1000, 2500 point for global refine and 10000, 25000 points for local refine (assuming pictures of 640x400). After that the picture is merged to filepath.bmp. This scripts is slowly but usable.
du -a | cut -f 2 >bmplist.txt
Better use adjust.tcl or readjust.tcl
to create a list of files, delete all the files you don't want to stitch
ATTENTION: a # in front of a filename means, that its coordinates will be
calculated and used, but the picture will not be put into the overallpicture

Command-Line-Program (bmp/fast)

Better use adjust.tcl or readjust.tcl
bmp -v 1 -n 5 -min-area 20000 -method 0 -load-BMP-list bmplist.txt -stitch merge.txt
-h gives a short help
-v {0 (1) 2 3} makes the program more or less verbose
-n {(5) number} number of points to calculate stitch positions
-min-area minimum {number} set the minimum overlapping-area
-method {0,1,2} selects the differenciation method, 0 absolute, 1 quadratic, 2 fast
-load-bmp-list {filename} loads a list of filenames into the calculation sequence
-stitch {filename} calculates the offsets and stores this information into a file
bmp -v 1 -n 10 -min-area 10000 -method 0 -load-merge-list mergelist.txt -refine 10 -save-merge-list mergelist.txt
-refine qualitiyfactor will recalculate stitching offset for pairs of pictures if quality is too bad
-lrefine qualityfactor will recalculate stitching offset only nearby old position
bmp -load-merge-list mergelist.txt -merge merge.bmp
-load-merge-list {filename} read offset informations from file
-merge {bmp-filename} merges/stitchs the pictures to a big one
bmp -load-merge-list {listfile} -printmerge {fontfile} {outputbmp} -printmerge merges the pics and then writes the # on each middleposition
bmp -scaling test.bmp font1.txt 1 300 "100?m"
-scaling {file} {fontfile} {position} {pixels} {text} puts a scale into a bmp {pixels} width, {position}: 0 right buttom, 1 right top, 2 left top, 3 left buttom, {text}: uppercase letters m n (? is greek my), outputfile is {file}.scale.bmp


compiling the sources
for Linux/Unix ...
make fast
for evil Windows
make fast.exe


See BUG/TASK-tracker for details...
1 The program only works with uncompressed 8/24 bit RGB bitmap files (workaround: use convert).
Maximum number of points to compare (-n) with method 1: 10000.
I have done no man/info files (help appreciated).

Roberts project-page

Main Page of MiPiSti downloads, public area (support), browse CVS, submit patches, watch tasks ...