Autoscaleit has been written by David Harris-Birtill.
Loads in a set of images (developed for TEM images) within a directory, calculating the length, width and aspect ratio of rod like structures for every image in a directory, plotting a histogram for the length, width and aspect ratio.
How to use AutoScaleIt:
- Before running this program, move all the data you want to analyse into a folder with only those dm3 data files in (this code assumes only dm3 files are in this directory)
- Run this script (type: auto_scale_it_v1p4 into matlab when in this directory)
- Select your data folder
- Select the folder you would like to have the figures saved to
- Let it run (normally takes approx. 3 secs per image, therefore 20 images takes 1 min)
- Et voila… the histograms will be plotted and displayed on your screen and automatically saved to the specified folder.
Note: This currently only works on DM3 file formats (which include pixel size information in). However, the program could easily be modified to include other image formats. Preferably the image format should include pixel size information in a header.
Description of step-by-step analysis of each image within this program:
The image is loaded in and the scale factors loaded (also converts scale to always be in nm (converts µm to nm))
The image is then thresholded, settng all values above a level to equal that level
The gradient of the thresholded image is taken in each direction, and the absolute of these matrices are made (flipping -ve to +ve)
The sum of the gradient maps is taken; this provides high intensity at the edges of objects all around the object
This gradient map is converted into a binary image (0&1)
An edge detection algorithm (Roberts method) is used on this binary map to find the edges of the objects
A watershed algorithm is used to segment the image into many objects
The length, width, area and eccentricity of these objects is measured
The length and widths are converted from pixels to nm using the loaded scale factors
For each object, the length and width are recorded if the below criteria for are satisfied for that object:
The eccentricity is greater than 0.7 (this means it won’t look at spheres – only rods)
The area is greater than 30 pixels (removes noise objects)
The width is greater than 5 nm (removes noise objects)
The width is less than 25 nm (removes very wide objects)
The length is greater than 15nm (removes unwanted tiny objects)
The length is less than 70nm (removes unwanted aggregations)
The object does not touch the image border
Then the aspect ratio is calculated by dividing the length by the width
Every image in the directory is loaded and analysed in this way, and the values are recorded by appending arrays (creating a long table which includes all values for every image in one long list).
Then histograms are plotted for the length, width and aspect ratio using the data from every image in the folder these histograms are saved into the folder specified by the user at run time
I’ve made this program open source to help others – feel free to use it and modify it, but please cite this program and its author wherever you use it. I’m always keen to hear feedback and how you’ve used it, so please do leave comments and feedback on this site.
Written by David Harris-Birtill
Written on 17/04/2013, last amended on 13/05/2013
David Harris-Birtill (2019). Autoscaleit (https://www.mathworks.com/matlabcentral/fileexchange/43516-autoscaleit), MATLAB Central File Exchange. Retrieved .
Updated description for clarity