Skip to content

Commit

Permalink
Merge pull request #14 from Elaniobro/master
Browse files Browse the repository at this point in the history
Update README.md and fix Pathing
  • Loading branch information
demisjohn authored Jun 13, 2021
2 parents ecf7d16 + 205be23 commit 939cc4d
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# add the path to this script, so we can find the user-settings
libpth = os.path.split( os.path.split( sys.path[0] )[0] )[0] # path to Fiji folder
#print libpth
libpth = os.path.join(libpth, 'plugins', 'Scripts', 'Analyze', 'Microscope Measurement Tools')
libpth = os.path.join(libpth, 'plugins', 'Analyze', 'Microscope Measurement Tools')


try:
Expand Down
12 changes: 6 additions & 6 deletions Analyze/Microscope Measurement Tools/Draw_Measurement_-_Line.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# add the path to this script, so we can find the user-settings
libpth = os.path.split( os.path.split( sys.path[0] )[0] )[0] # split-off the "/jars/lib" part
#print libpth
libpth = os.path.join(libpth, 'plugins', 'Scripts', 'Analyze', 'Microscope Measurement Tools')
libpth = os.path.join(libpth, 'plugins', 'Analyze', 'Microscope Measurement Tools')
# hard-coded path, within the Fiji directory.

try:
Expand Down Expand Up @@ -100,11 +100,11 @@ def run():


'''Draw text annotation'''
unit = imp.getCalibration().getUnit().encode('utf8') # get the unit as UTF-8 (for \mu)
print "Draw_Meas(): Unit (raw) = `", unit,"`", type(unit),
if unit[0] == u'\xc2': unit=unit[1:] # strip weird char at start of \mu
unit = imp.getCalibration().getUnit().encode('utf-8') # get the unit as UTF-8 (for \mu)
if len(unit) == 3 : unit=unit[1:] # strip weird char at start of \mu
print "Draw_Meas(): Unit (raw) = `", unit,"`", type(unit),


# format of measurement text (eg. 3 decimal points):
lenstr = "%0.3f" % roi.getLength() + " %s" % (unit) # string to print as length
print "DrawMeas(): Line length= %s" % lenstr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,21 @@
Microscope scaling/pixel-size calibration settings.
"""

# The names of the microscope calibrations (shows up as the radio button/drop-down names):
# The names of the microscope calibrations (shows up as the radio button names):
names = [
'FluoroScope 5x',
'FluoroScope 20x',
'FluoroScope 50x',
'FluoroScope 100x',
'FluoroScope 150x',
'Olympus DUV 100x',
'Swift 4x',
'Swift 10x',
'Swift 40x',
'Swift 100x',
]


# The 'pixel-per-unit' obtained from the "Set Scale..." dialog, for each named calibration above:
# The 'pixel-per-unit' obtained from the "Set Scale..." Dialog, for each named calibration above:
cals = [
0.9058, # FluoroScope 5x to 150x
1.81,
4.525,
9.0667,
13.5333,
54.6875, # Olympus DUV
0.9058,
1.81,
12.5455,
25.4707,
]
# This is just 1/pixel_width, in case you were wondering.

Expand Down Expand Up @@ -77,21 +73,21 @@
Settings for the script "Draw Measurement - Line
Colors are specified as:
[R, G, B, transparency] values, from 0->1.0.
Leave last value as 1 for completely opaque.
[R, G, B, transparency] values, from 0->1.0.
Leave last value as 1 for completely opaque.
Eg. opaque red would be [1,0,0, 1]
and half-transparent blue would be [0,0,1, 0.5]
opaque black is [0,0,0, 1]
opaque white is [1,1,1, 1]
"""

linethickness = 5.0 # in pixels
linecolor = [ 0, 0.7, 0, 1.0]
textsize = 30 # text height in pixels, I think
textcolor = [ 0, 0.8, 0, 1.0]
textbackgroundcolor = [ 0, 0, 0, 0.6] # background color behind text.
#textbackgroundcolor = None # set to None for no background - uncomment this line
texttoleft = True # put text on left or right side of last point?
linethickness = 5.0 # in pixels
linecolor = [ 0, 0.7, 0, 1.0]
textsize = 50 # text height in pixels, I think
textcolor = [ 0, 0, 0, 1.0]
textbackgroundcolor = [ 1, 1, 1, 0.4] # background color behind text.
#textbackgroundcolor = None # set to None for no background - uncomment this line
texttoleft = True # put text on left or right side of last point?



Expand All @@ -110,13 +106,13 @@
def run():
''' If someone tries to run this file by itself, warn them of their error. Unfortunately, since I was too lazy to make Microscope_Calibrations a full plugin (rather than a script), this accompanying settings file will show up in the Scripts menu.'''
from ij.gui import GenericDialog

gd = GenericDialog("Microscope_Calibrations_user_settings.py")
gd.addMessage("This file is only for setting the microscope calibrations and settings for the plugins 'Microscope Measurement Tools'.\nNothing is done when this settings file is run by itself.\nPlease open this file in a text editor instead, to edit the calibrations.\n \n" + \
"The file should reside in a path like the following\n" + \
"Fiji.app/plugins/Scripts/Analyze/Microscope Measurement Tools/Microscope_Calibrations_user_settings.py\n " + "\n" + \
"Changes to the settings file are not automatically picked up by Fiji. The workaround is to\n 1) Quit Fiji.\n 2) Delete the '$py.class' file 'Microscope_Calibrations_user_settings$py.class'\n 3) Open Fiji. Make sure the new settings show up in 'Choose Microscope Calibration'." )

gd.showDialog()
#end run()

Expand Down
91 changes: 67 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,97 @@ Microscope Measurement plugin for [FIJI](http://fiji.sc).

This set of [FIJI](http://fiji.sc) plugins provides a quick way to save distance/length calibrations for various microscopes/objectives in a simple text file, and then draw calibrated distances onto your images.

You can then choose any of your prior calibrations to be applied to an open image (or all open images), as so:
You can then choose any of your prior calibrations to be applied to an open image (or all open images), as so:

![Choose Calibration window][MMT-Choose-Cal-Pic]


The "Draw Measurement" plugin then allows you to draw a line with the calibrated measurement length, as so:
The "Draw Measurement" plugin then allows you to draw a line with the calibrated measurement length, as so:

![Annotation with Line][MMT-Annot-Line-Pic]

[MMT-Choose-Cal-Pic]: http://fiji.sc/_images/c/cd/Microscope_Meas_Tools_-_Choose_Calibration_01.png
[MMT-Annot-Line-Pic]: http://fiji.sc/_images/f/f4/Microscope_Meas_Tools_-_Draw_Meas_Line.png

# Installation
Download and install the [scientific image analysis program FIJI](http://fiji.sc).

Download the most recent [Microscope Tools Release from Github](https://github.com/demisjohn/Microscope-Measurement-Tools/releases).
For the *UCSB Fork*, [download the forked repo](https://github.com/demisjohn/Microscope-Measurement-Tools-UCSB/archive/master.zip).

View the [Instructions PDF on Github](https://github.com/demisjohn/Microscope-Measurement-Tools/blob/master/Microscope%20Meas.%20-%20Calibration%20instructions.pdf) for the Installation & Calibration procedure.

# Usage
## 🏗️ Installation
1. Download and install the [scientific image analysis program FIJI](http://fiji.sc)
1. Download the most recent [Microscope Tools Release from Github](https://github.com/Elaniobro/Microscope-Measurement-Tools/releases/tag/v2.4)
1. Extract/Unzip the file you downloaded from Github called: `Microscope-Measurment-tools`
1. Move the folder into the FIJI plugins directory on your MacOS
<img src="https://github.com/Elaniobro/Microscope-Measurement-Tools/blob/master/img/pkg_contents.png?raw=true" width="600"/>



## ⚖️ Calibration
1. Take photos of a known measurment sample with your microscope, at each magnification you want to calibrate
1. Open FIJI
1. Open an image file taken at the desired maginification with a measurment marker. e.g. Open a photo of your micrometer slide taken with your 40x objective
1. Zoom in on the photo to view the micrometer scale
1. Draw a line `ROI` (Region Of Interest) along the calibration measurment feature. e.g. along the micrometer
<img src="https://github.com/Elaniobro/Microscope-Measurement-Tools/blob/master/img/roi.png?raw=true" width="600"/>
1. Navigate to and select `Analyze > Set Scale`
1. The "Distance in Pixels" will already be set by your line ROI
1. Type in the "Known Distance" from your measurement feature, mine is 5μm
<img src="https://github.com/Elaniobro/Microscope-Measurement-Tools/blob/master/img/set_scale.png?raw=true" width="600"/>
1. Record the resulting "Scale" value, e.g. 31.1716 pixel/unit, where unit is cm, mm, μm, etc..
1. The "Scale" value will be used in your `Microscope_Calibrations_user_settings.py` file, so recored both a name and the scale value. e.g:
```
Swift 350T 4x: 0.9058 px/μm
Swift 350T 10x: 1.81 px/μm
Swift 350T 40X: 12.5455 px/μm
Swift 350T 100X: 31.1716 px/μm
```
**_these are just dummy values_**
1. Open up `/Applications/Fiji.app/plugins/Analyze/Microscope Measurement Tools/Microscope_Calibrations_user_settings.py` in your IDE (Integrated Deelopment Environment)
1. Edit the `names` list to reflect the name of each calibration on line 21:
```
names = [
'Swift 350T 4x',
'Swift 350T 10x',
'Swift 350T 40x',
'Swift 350T 100x',
]
```
1. Edit the `cals` list to reflect the corresponding `pixel-per-unit` calibration for each setting, from your previous records, on line 30:
```
cals = [
0.9058,
1.81,
12.5455,
31.1716,
]
```
1. Quit FIJI
1. Re-start the FIJI application. This will allow the application to register the changes you made to the plugin
**note** _for any subsquent changes, you will have to save the file, quit the application and re-open it to see the changes_
1. Open an image
1. Run `Analyze > Microscope Measurment Tools > Choose Microscope Calibration` and see a pop-up window that shows the new names and calibration values you set in `Microscope_Calibrations_user_settings.py`.
<img src="https://raw.githubusercontent.com/Elaniobro/Microscope-Measurement-Tools/master/img/microscope_calibrations.png" width="600"/>
1. You may also apply the same scale and scale bar to all images you have open, but selecting the checkboxes. Doing so will open another pop-up, where you can see how the scale will look. In the example below, the bar is set to 10μm, white text and placed in the lower right corner
<img src="https://raw.githubusercontent.com/Elaniobro/Microscope-Measurement-Tools/master/img/scale_bar.png" width="600"/>
## 📈 Usage
Three files are included, which will show up in your FIJI "Analyze" menu:
+ **Choose_Microscope_Calibration.py**
+ *Opens the "Choose Calibration" window, for setting the measurement scale to a preconfigured value.*
+ **Draw_Measurement_-_Line.py**
+ *Converts a Line ROI into a drawn annotation with the measurement length indicated.*
+ **Microscope_Calibrations_user_settings.py**
+ *User-editable Settings file that contains your pre-configured scale calibrations, along with settings for drawing annotations (background/text color etc.)*
+ Please see the Instructions PDF for detailed instructions on setting up your settings file with Calibrations.
## Calibrating your microscope
View the [Instructions PDF on Github](https://github.com/demisjohn/Microscope-Measurement-Tools/blob/master/Microscope%20Meas.%20-%20Calibration%20instructions.pdf) for the Calibration procedure.
View the [How-To Calibrate an Ocular Micrometer](https://www.youtube.com/watch?v=HaqgCtA-ioI&t=738s)
## Making + Drawing measurements
Select the Menu Item `Analyze > Microscope Measurement Tools > Choose Microscope Calibration`, and select your microscope/objective from the resulting list. The pixel scale will be applied.
## 📐 Making + Drawing measurements
Select the Menu Item `Plugins > Analyze > Microscope Measurement Tools > Choose Microscope Calibration`, and select your microscope/objective from the resulting list. The pixel scale will be applied.
You can now drag a Line (or other type of ROI) on any feature, and the FIJI toolbar will show you the measurement dynamically. Other FIJI functions can now also be used for calibrated measurements (areas etc.).
To draw this measurement on your image, drag the Line to the desired location, and select the menu item `Analyze > Microscope Measurement Tools > Draw Measurement - Line`
To draw this measurement on your image, drag the Line to the desired location, and select the menu item `Plugins > Analyze > Microscope Measurement Tools > Draw Measurement - Line`
## Custom Calibration Functions
## 🔧 Custom Calibration Functions
A custom function can be added to the list of available calibrations (as opposed to a static scale value). A sub-folder is included showing an example of how to do this. The example is for a JEOL SEM (scanning electron microscope), and the example function will determine the scale of the SEM image by parsing an accompanying text file.
See the files in the sub-folder "*MScopeCals - custom function example*" for more info, and move both of the `*.py` files into the main *Microscope Measurement Tools* folder to see how they can be used. An example SEM image and TXT file from a JEOM 7600F SEM are included.

# Contact

Feel free to add Issues/Feature Requests, or even better, Fork the `git` repository and submit your own updates (see this [how-to](http://kbroman.org/github_tutorial/pages/fork.html))!

June 2019, Demis D. John
Binary file added img/microscope_calibrations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/pkg_contents.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/roi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/scale_bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/set_scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 939cc4d

Please sign in to comment.