Git Product home page Git Product logo

microscopy-tools's Introduction

microscopy-tools

Tools for microscopy and image focus stacking.

  • Tools already useful, in active development:
    • imfuse: Fuse focus stackshot images with ImageMagick. (Terminal)
    • stackprepare: Batch processing of image stack for contrast, crop, gamma etc.
  • Tools considered to be (mostly) stable and ready for use:
    • stackalign: Align image stack with the help of focus-stack and ImageMagick.
    • imgruler: Draw a ruler or micrometer into an image. (Terminal)
  • Tools awaiting further development, currently less useful:
    • camcfg: Terminal dialog frontend for camera configuration. (Terminal)
  • Deprecated, stored for partial code reuse:
    • stackfuser: Align, prepare and fuse focus stack images. (GUI)
    • stackshooter: Shoot focus stackshots with stepper motor and camera. (GUI)

stackfuser and stackshooter need some further development and documentation before they can be recommended for general use. Especially they need a new GUI backend because the currently used kaptain GUI is outdated and does not run on up-to-date systems.

imfuse

Combines focus stackshot images to an overall sharp image.

Dependencies:

  • imagemagick version 7 (command magick)
  • geeqie and feh (optional image viewers)
  • exiftool (optional to preserve exif meta data)
  • PetteriAimonen/focus-stack (optional for option --align)
  • enfuse (optional, needed for some options)

Much thanks to the developers and supporters of ImageMagick!

stackalign

Aligns image stack.

Dependencies:

The core work is done by focus-stack, this tool helps to crop the images to the usable common area.

stackprepare

Batch processing of image stack for contrast, crop, gamma etc.

Dependencies:

  • imagemagick

imgruler

Draws a ruler into an image. Intended to draw micrometers into micoscopic captures. Contains a calibration instruction in english and german.

Runs on Linux, macOS and (in Cygwin) on MS Windows. Considered to be ready for general use.

Dependencies:

  • imagemagick

camcfg

dialog frontend for gphoto2 camera configuration. Reads possible configurations of a camera and provides a dialog in terminal to choose desired settings. Beta stage, already useable.

  • camcfg shows all available configurations.
  • camcfg ENTRY shows configuration of entry ENTRY. Example: camcfg iso

Dependencies:

  • dialog
  • gphoto2

stackfuser

GUI frontend for image foto stacking with enfuse.

Deprecated, will be replaced by multiple single tools.

Provides:

  • Image preprocessing with imagemagick to enhance contrast and sharpness.
  • Image alignment with ffmpeg/vidstab or align_image_stack.
  • Generating multiple overall sharp images from stackshot with enfuse. Further combining of these results with imagemagick.
  • Animated videos of focus stackshots.

Dependencies, most essentiell:

  • align_image_stack (hugin tools)
  • enfuse
  • geeqie
  • imagemagick
  • imfuse
  • kaptain
  • viewnior

Dependencies, also recommended:

stackshooter

GUI for foto stacking with a stepper motor controlled by an Arduino and a camera connected on USB. Note: The user must be in group dialout to access the Arduino.

Deprecated, will be replaced.

Features:

  • Camera control with gphoto2 for preview videos and tethered shooting.
  • Stepper motor control for focus adjustment.
  • Automated focus stackshots combining camera and stepper motor.

pololu_a4988.ino is my code to control my stepper motor driver with an Arduino. The control commands send by stackshooter to Arduino can be customized in stackshooter configuration dialog.

Dependencies:

  • ffmpeg
  • geeqie
  • gphoto2
  • align_image_stack (hugin tools)
  • kaptain
  • xinput
  • xdotool

Example

Image of some flower pollen. Generated with stackshooter and stackfuser. Technic: Microscope from Hund/Wetzlar with a stepper motor and an arduino. Camera: Canon EOS 1000D. Stackshot result of 240 single captures with slightly different focus:

screenshot

Iconified excerpt of source stackshot:

screenshot

Animated video:

screenshot

Related tools

Free and Open Source

  • CombineZP: Stacker for MS Windows. Works with wine on Linux, too. Good but unfortunately not maintained.
  • enfuse: Enfuse blends differently exposed images of the same scene into a nice output image. Command line tool, used by stackfuser.
  • Entangle: Entangle provides a graphical interface for "tethered shooting", aka taking photographs with a digital camera completely controlled from the computer.
  • PetteriAimonen/focus-stack: A cross-platform tool for focus stacking images based on wavelet algorithms.
  • pulsar123/Macro-scripts: A set of BASH scripts and C++ programs representing a complete workflow for processing macro focus stacking photographs.
  • gphoto2: The gphoto2 library allows access and control of various digital camera models. Command line tool, used by stackshooter and camcfg.
  • hugin: Hugin is a panorama photo stitching program for several overlapping photos taken from the same location, transforming the photos to one larger image.
  • ImageMagick: ImageMagick is a powerful software suite to create, edit, and compose bitmap images. Command line tool, used by almost all tools in this repo.
  • mfkter: GUI for enfuse. Replaces former MacroFusion.
  • RawTherapee: RawTherapee is an advanced program for developing raw photos and for processing non-raw photos.
  • ImageMagick scripts:

Closed Source freeware

  • Picolay: Stacker for MS Windows. Works with wine on Linux, too.
  • stacky: Stacker for MS Windows. Works with wine on Linux, too.

Closed Source commercial

  • Helicon Focus: 30 days trial version. Available for Mac and Windows.
  • ZereneStacker: 30 days trial version. Available for Linux, Mac and Windows.

microscopy-tools's People

Contributors

mviereck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

vuongvmu

microscopy-tools's Issues

imfuse: finding good parameters for focus stacking

This issue is opened to test, discuss, improve, ... the results of imfuse.
Many parameters are possible, many parameters can have arguments and some parameters can be combined reasonable and other not.
Some hints can be found here: https://github.com/mviereck/microscopy-tools/tree/master/fusesets

Suggestion for a workflow:

  1. take photos
  2. align them (e.g. align_image_stack)
  3. fuse them (imfuse)
  4. convert tif to jpg (magick) (optional)
  5. transfer exif data (exiftool) (if exif data is in the aligned images, imfuse do that for you)

imfuse: possible --background

imfuse provides a lot of possible backgrounds.
From imfuse --help:

 --background BG      Specify a background to paint on. Default: mean
                      BG can be an image name or one out of:
                        enfuse
                        saturation
                        magick -list color
                        magick -list evaluate (compare --evaluate)
                        magick -list compose  (compare --compose)
                      Well to combine with --soft. Useable with --threshold.
                      Some recommendations: enfuse saturation mean max min
                      colorize colorize2 pinlight pinlight2
                      Interesting: interpolate overlay pegtoplight reflect2

Only some of them are really useable as background images. Others are interesting on themselves. Some are totally useless.
The script demo-imfuse-backgrounds generates a set of interesting results.

@holgerd001 Would you like to test this?

imfuse: Error while flattening images

Idea:
Making many fused images with different parameters.

Preconditions:

  • set of aligned and resized photos (here pc20-aligned_c80_C_m_order_00??.tif)
  • imfuse v0.6.4.0-beta

Starting imfuse:
~> imfuse --verbose --diffstat=r3,mean pc20-aligned_c80_C_m_order_00??.tif

Response:
imfuse note: Setting --output=/mnt/Daten/holger/Fotos/stacks/20210204_Fliege_Kopf_Mikroskopobj/imfuse.diffstat=r3-mean-mean_bg=mean.eb7c3e.tif
...
Error while flattening images_20210208.zip
...
magick: insufficient image data in file `/mnt/Daten/holger/Fotos/stacks/20210204_Fliege_Kopf_Mikroskopobj/cache.imfuse/montage-diffstat.2dc748.tif' @ error/tiff.c/ReadTIFFImage/1774.
imfuse ERROR: Error while flattening images

hints:
That works:
imfuse --verbose --diffstat=r3,max pc20-aligned_c80_C_m_order_00??.tif
imfuse --verbose --diffstat=r3,grad pc20-aligned_c80_C_m_order_00??.tif

imfuse: effects of --finalalpha arguments

imfuse provides option --soft --alpha --finalalpha to generate semi-transparent results that are put on a background image.
Low contrast areas are close to invisible, high contrast areas are close to opaque.
The transparency mask, or alpha channel in imagemagick terms, can be adjustet with --alpha=A%xB%.

EDIT: changed formerly option --soft to --alpha due to some conceptional changes of the function.
I've changed this post accordingly.

From imfuse --help:

--alpha [=LEVEL]     Generate transparent image using the contrast mask as 
                      alpha channel (=transparency channel).
                      The semitransparent result is composed over a background.
                      Good method to reduce noise in low contrast areas.
                      Default background is 'enfuse'. Others are worth a test.
                      Can take an argument as one or two percent values.
                      Simplified: If only one value is given, positive values 
                      make the image more transparent and negative values make
                      it less transparent.
                      Advanced usage: Two percent values A%xB% are applied
                      as '+level A%xB%' on the transparency alpha channel.
                      This allows to adjust transparency of low contrast areas 
                      with A% and high contrast areas with B%. 
                      Negative values and higher than 100% are possible.
                      Try script 'demo-alphalevel' to understand the effects.

The script demo-alphalevel helps to demonstrate the effect of different parameters.
It generates a table with two gradient images in the left colums, and the alpha cannel and the result image in the right colums.

The gradients are just added to get an idea of the +level effect to the alpha channel. In the alpha channel black areas are full transparent, white areas are full opaque.

The first line shows gradients, alpha channel and image with default --alpha=0x100, i.e. no change.
The following lines show the effect with different parameter sets.

gradient+level

mask file remaining

After imfuse --dog=s0.3 --finalblur=w10,s1 --less=6 --cutblur=0.5 imfuse.dog=s0.3-s0.48_less6_cutblur0.5_finalblur=w10-s1.2783bf.tif was generated.
And a mask file was remaining in the same directory: fb_maskmax.tif

Versions:
imfuse v0.6.4.1-beta
ImageMagick 7.0.10-53

The issue is reproducible.

imfuse: exif meta data transfer

imfuse provides a new option --exif [=IMAGE] for exif meta data transfer to the result.

Instead of always transferring the exif data from the first input image as discussed and developed in #2, it is now needed to specify option --exif explicitly for this behaviour.

Optionally it is possible to provide an image name as argument; if given, the exif meta data from that image will be transferred.

The Orientation tag is removed because it can cause issues in image processing.

Beginner guide for dummies?

Hi,
[EN]
I want to try imfuse, but tbh: I don't know where to start. Can I use your scripts with the portable imagemagick (never used before) version?
May it be possible to get a beginner guide, that explaines the workflow step by step? My first tests resulted in never ending messages, that told me basically I did everything wrong ;)

[Ger]
Ich würde gerne imfuse ausprobieren, habe aber ehrlich gesagt nicht verstanden, was ich wie genau machen muss. Ich habe hier die portable Version von Imagemagick, aber wo trage ich die Pfade dazu jetzt ein, oder muss ich alles zusammen kopieren? Gäbe es die Möglichkeit eine kurze Schritt-für-schritt-Anleitung in das Wiki einzutragen?
Die ersten Versuche ergaben nur eine nicht endende Terminal-Ausgabe, die mir gesagt hat, dass ich eigentlich alles falsch gemacht habe :D

Danke :)

Error: Zeile 455: Partimagelist ist nicht gesetzt.

Hi,
I tried imfuse for the first time with a stack of 7 images. -> It works.
Then I tried with a stack of 73 Images:
imfuse aborted and I got the message "Zeile 455: Partimagelist ist nicht gesetzt."

Both times i started with "imfuse -o imfu_diff.tif --cache --diffstat aligned_C_m_c100_order_00??.tif" (or similar).

Greetings from snowy part of Germany
Holger

imfuse: magick: unable to open image

Hi,
I'm back again. Unfortunately with an error:

magick: unable to open image '/mnt/Daten/holger/Fotos/stacks/20210417_Ameise3_4_Mikroskopobjektiv_nonplan/byrawtherapee/cache.imfuse/soft-levelU_diffstat.d517e4.tif': Datei oder Verzeichnis nicht gefunden @ error/blob.c/OpenBlob/3537.

I started imfuse with: imfuse --soft --diffstat aligned_C_c16_corr08_g11_m_order_00??.tif -v --cache

After 9 minutes I got the error message above. The error is reproducible.

Sorry for being absent for that long time. But, as you see, I'm using imfuse again.

Greetings, Holger

talk

Hi,
many weeks ago I ordered a microscopy lens (10x) for taking photos with. Because of corona it tooks such a long time. Now it is delivered and I have taken some photos. At first the quality was moderate. It was difficult to keep the object and the camera steady. A normal tripod is not solid enough. It's good for a 4x microscopy lens but not for a 10x. Additional my macro slide is not as accurate as needed. Especially the driving jumps sometimes. So the focal plane jumps to.

The solution was an old turning lathe. I mounted the camera on it (on the cross slide). Now the camera is very solid mounted and I can move it for- or backwards for a fractional amount.

I found a half rotten fly. I.a. it has a big hole in one of its eyes. I took a photo of the eye with an insight into it.
D5056480_D5056571_Fliegenauge_30_70

Greetings Holger

Discussion about movement detection

Hello mviereck, and thank you for the friendly discussion over at enblend/enfuse.
Honestly, I think you have helped me out a lot already with the idea of comparing the min/max conversions of my time-series to get an overview of movement. Since you suggested continuing the discussion over here though, I'm starting a thread - maybe you have further ideas.

To get a bit deeper into what I'm doing: I'm working with MEA (Motion Energy Analysis) in human interaction. In order to extract motion energy out of videos of people interacting with MEA, one needs to define regions of interest (ROIs). Since those regions can be split up into different body sections (e.g. upper body, lower body, head) and have to be defined for the whole duration of a video, I need to get an overview of where these body parts move to throughout the interactions and then define them as precisely as possible.

Now, you already know that my first attempt was with using Enfuse, and my preferred solution there is with the option --hard-mask. Your suggested solution with ImageMagick's min/max comparison works very well as well and shows movement better than the Enfuse-solution.

That might actually be enough to solve the problem for me. I'll test this with a few videos and see where it gets me. Thanks again for your help and if you have any further suggestions, I'll be glad to test them.

imfuse: ERROR: Error while cutting images

imfuse v0.6.0-beta
If I used resized images, I got the message "ERROR: Error while cutting images".

  1. aligning images with align_image_stack -C -v -c40 --use-given-order

  2. imfuse -o imfu_diffr2clo2x2_soft25_less5.tif --cache --diffstat=r2,close2x2 --soft=25 --less=5 aligned_C_m_c40_order_00??.tif
    --> it works

  3. resizing files: for file in aligned_C_m_c40_order_00*.tif; do convert $file -resize 20% pc20-$file; done

  4. checking files with gwenview: no problems visible

  5. imfuse -o imfu_diffr2clo2x2_soft25_less5.tif --cache --diffstat=r2,close2x2 --soft=25 --less=5 pc20-aligned_C_m_c40_order_00??.tif causes error:
    --soft '25' --lessthanmax '5' --output '/mnt/Daten/holger/Fotos/stacks/20210203_Motte4_Kopf_Mikroskopobj/cache.imfuse/imfuseimfuse.diffstat=r2-close2x2-median-mean_soft25_less5_bg=enfuse.151832.tif' --
    magick: insufficient image data in file `/mnt/Daten/holger/Fotos/stacks/20210203_Motte4_Kopf_Mikroskopobj/cache.imfuse/montage-diffstat-soft25-less5.98d67c.tif' @ error/tiff.c/ReadTIFFImage/1774.
    imfuse ERROR: Error while cutting images

  6. using enfuse: enfuse -o xD2030892_pc20-aligned_C_m_c40_order_grayl-star.tif --exposure-weight=0 --saturation-weight=0 --contrast-weight=1 --hard-mask --gray-projector=l-star
    --> it works

Greetings
Holger

imfuse: foreground - background (ant)

Hello,
in the last weeks I have taken some stacks of insects. One of the problems I got is that foreground and background objects are not precise separated. As you can see here at this ant. The feeler should be in front of the eye.
xD4174364_aligned_C_c16_corr08_g11_order_grayl-star_25pc

This image is done by enfuse. Do you have a suggestion how to get a better result with imfuse?

Greetings Holger

imfuse: Finding good parameters: fly on yellow background

Here I show the progress of finding a good parameter set for a stack provided by @holgerd001. Much thanks for the stack!

quick result with enfuse

First try: Generating an enfuse result

imfuse --background=enfuse

imfuse bg=enfuse 6e8354

I've marked and numerated some points of interest:
POI

  • (1) A hair behind the eye appears in front of it
  • (2) Dark areas of the eyes appear a bit too bright
  • (3) The leg in background looks well
  • (4) Between leg and eye the bokeh is somewhat wrong: yellow instead of leg
  • (5) Yet another blurry bokeh area

Try a mask: --dog, --log or --wavelet

Good mask options for macro stacks in general are --log, --dog and --wavelet. Now I use --dog.

imfuse --dog

imfuse dog=s0 3-s0 48 b8a0e0
Visible artefacts:

  • (1) hair in front of eye
  • (2) eyes darker than with enfuse, but with some noise
  • (3) noise in the leg / bad bokeh

fix hair in front of eye: --less --close

Fix the hair in the eye (1) with --less --close

imfuse --dog --less --close

imfuse dog=s0 3-s0 48-close2x2_less60 341de2

  • (1) hair is behind eye, well done
  • (2) less noise in darke area of eyes
  • (3) bad noisy bokeh at the leg

low contrast area detection: --threshold=50

Now its up to look for the bokeh.
Low contrast areas that might cause artefacts are below 50% contrast.
To get an idea of the location of low contrast areas I use --threshold=50

imfuse --dog --threshold=50 --background=red

imfuse dog=s0 3-s0 48_threshold50_bg=red ae1be7

blur bokeh with --finalblur

Option --finalblur, currently with default --finalblur=w50,s2, blurs the bokeh.

imfuse --dog --less --close --finalblur

imfuse dog=s0 3-s0 48-close2x2_less60_finalblur=w50-s2 11f708
Overall a good result, but the leg (3) looks somewhat incomplete

A high blur sigma improves the leg (3) / bokeh appearance, but causes light artefacts in the eyes (2):

imfuse --dog --less --close --finalblur=w50,s5

imfuse dog=s0 3-s0 48-close2x2_less60_finalblur=w50-s5 1963c2

Reducing the percent value of finalblur helps, we have luck that the black area in the eyes (2) has a bit more contrast than the leg (3):

imfuse --dog --less --close --finalblur=w47,s5

imfuse dog=s0 3-s0 48-close2x2_less60_finalblur=w47-s5 c0be55

I'd say this is a good result.

light balance with --fakehdr

As a final tweak some light balance with --fakehdr:

imfuse --dog --less --close --finalblur=w47,s5 --fakehdr=40

imfuse dog=s0 3-s0 48-close2x2_hdr40_less60_finalblur=w47-s5 5d39f4

imfuse: cachfile remaining

After > imfuse --verbose --background=saturation pc20-aligned_c80_C_m_order_00??.tif
imfuse.bg=saturation.a9a27d.tif was generated.
And a cache file was remaining in the same directory:
cache.imfuseimfuse.saturation_bg=mean.d43748.tif

imfuse v0.6.4.0-beta

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.