Abstract
Background
Mean linear intercept (MLI) is a method of evaluating lung structure and pathology that is widely used in clinical and research settings. Unfortunately, no widely available software for automation of this process is available, and many clinicians and scientists still perform these measurements manually.
Results
To increase the speed and accuracy of obtaining MLI measurements, we have developed a macro for Fiji is just ImageJ (Fiji) to semi‐automate the acquisition of these measurements. Twenty to 25 images from each of 43 mouse lungs, a total of 1042 images, were analyzed manually and by macro (automated) to validate the accuracy of the MLI macro. No significant difference was recorded between the manual and automated methods in mouse lung tissue of either different age (P14, P21, 8 weeks) or different condition (healthy vs. emphysema). Optimization of MLI macro parameters showed that additional measurements beyond three lines per image did not further improve accuracy. We also provide an Excel macro that summarizes the airspace data for each image and averages all the image data in a given batch of images.
Conclusion
This Fiji macro can be used to automate MLI measurement in histological sections of lung tissue faster and with lower variance.
Keywords: airspace, alveoli, automated, lung, mean linear intercept, MLI
Key Findings
Semi automated tool to measure peripheral lung airspace using the mean linear intercept method Fiji macro to facilitate measurement of the mean linear intercept (MLI) Excel macro that summarizes the airspace data for each image and averages all the image data for a given batch of images.
1. MEAN LINEAR INTERCEPT METHOD TO EVALUATE RESPIRATORY AIRSPACE
Mean linear intercept (MLI) is a measurement strategy used in clinical and research settings to evaluate lung structure. It is particularly useful for measuring the respiratory airspace of the peripheral lung, which includes alveoli and alveolar ducts. 1 MLI is the average distance between airspace septa in the lung. It is often used to evaluate developmental, genetic, and pathological changes in peripheral lung tissue. 2
Currently, MLI measures are analyzed by hand, a process that is time‐consuming and may not be consistent between different analysts. To measure MLI manually, histological images are first binarized and a line is added at a pre‐determined position. The distance between each intersection on the line is then manually measured and recorded into a spreadsheet. Distances less than 10 μm are then excluded before the data is averaged to calculate the MLI. To improve throughput, accuracy, and minimize user bias, we generated a macro in Fiji 3 to semi‐automate this process.
To accurately represent the overall architecture of peripheral lung histology, 20–25 images, distributed evenly throughout the peripheral lung, are captured with a 20x–40x objective. It is important to select representative images that do not contain large airways or blood vessels. However, these features can be difficult to avoid entirely in some cases. Therefore, the automation method includes multiple measurement lines in each image to mitigate error from these features.
2. A FIJI MACRO TO FACILITATE MLI MEASUREMENT
This macro (2025_MLI_BP.ijm) is designed to analyze all the images in a single folder in one batch and place the data on a single Excel sheet. We recommend that the folder contains images from a single lung, lung lobe, or affected lung region. The macro creates three lines in each image and measures the gap between airspace and septa (chord length) along each line. It then records the size of each air space delimited by alveolar or conducting airway septa along that line, excluding MLI chords that intersect the edges of the image field. The macro is set to filter out any measures smaller than 10 μm in length. Each airspace is recorded for each image line and then saved in an excel document called ‘rename me after writing is done’ using the read and write excel plugin in Fiji (Figure 1A). The user calculates the average airspace along each image line and the average airspace for all image lines from a given sample to determine the MLI for that samples (Total Average). An Excel macro (MLI_excel statistics macro.bas) semi‐automates this process (Figure 1B).
FIGURE 1.

Screenshots of Fiji MLI output data. (A) Example output from the Fiji MLI macro. (B) Example results calculation with MLI statistics macro processing.
3. VALIDATION OF THE FIJI MACRO
To validate MLI measured by the Fiji macro (automated), we compared its output to several MLI data sets that were curated manually. Histological sections from the lungs of 43 mice were scanned on a Hamamatsu NanoZoomer HT2.0 slide scanning system (Hamamatsu Photonics K.K., Japan) at 40x magnification and then 20–25 regions of interest (ROIs) distributed throughout the peripheral lung were selected for analysis avoiding large airways and blood vessels where possible using the NDP.View 2 Image viewing software (Hamamatsu Photonics K.K., Japan). In total 1042 images, were measured. The difference between the manual and the automated measurements was minimal (Table 1). For the manual method the original image was made binary, skeletonized, and a grid was overlayed (Figure 2A,B). Then, length measurements between every intersection along a single line were recorded. Similarly, the automated method thresholds the image, draws three evenly spaced lines across the image and measures the chord length (distance between each intersected septa) (Figure 2C). Measurements less than 10 μm in length were excluded from both methods. Overall, the macro had lower variance and a smaller difference in the minimum and maximum measured values in a dataset (Figure 2D). This is likely because it measures three different places in the image. Measuring multiple lines in an image increases the sample size (n = airspaces per image) and decreases the variance per group. In this case a group consists of the 20–25 images taken from the lungs of each mouse. Variance is a measure of how different each value is from the mean of a dataset. 4 Here, variance was measured by taking the sum of each sample (sample = average chord length from a single image) minus the sample mean squared and divided by total number of samples minus 1 (). Measuring only at a single line in an image can result in higher variance due to variable features at any given point in each image. By measuring three lines per image this variability can be mitigated.
TABLE 1.
Comparison of manual and automated MLI measurements.
| Image name a | Manual (μm) | Automated (μm) | Difference | Percent difference |
|---|---|---|---|---|
| 1 | 35.81 | 36.89 | 1.08 | 3.01 |
| 2 | 35.75 | 36.39 | 0.63 | 1.77 |
| 3 | 33.48 | 29.86 | 3.61 | 10.80 |
| 4 | 33.15 | 31.99 | 1.16 | 3.50 |
| Column average | 34.55 | 33.78 | 1.62 | 4.77 |
Example images.
FIGURE 2.

Comparison of manual and automated methods to assess peripheral lung airspace by the MLI method. (A) Example histology image. (B) Skeletonized version of the original image used for manual MLI measurement. The superimposed grid and the line used for airspace measurements (arrow) are shown. (C) Thresholded version of the original image used for automated MLI measurement. Shown are macro‐generated lines placed at the top third, middle, and bottom third of the image (arrows). (D) Variance and range of manual compared to automated measurements.
The macro can be adjusted to measure more than three lines per image by copying a line creation block and changing the calculation for where to draw the line. However, it was observed that increasing the number of lines to five or seven lines measured per image did not significantly change the MLI value (Figure 3).
FIGURE 3.

Comparison of manual MLI measurements to automated MLI measurements using different numbers of intersecting lines. Shown are measurements with 1 (manual), 3, 5, or 7 (automated) intersecting lines. Measuring more than three lines using the macro does not change the accuracy of the measurement.
To determine the versatility of the macro, different ages of lung and different disease states were tested. No significant difference between results measured manually for a pathologic condition (Figure 4A) or different ages (Figure 4B) was observed.
FIGURE 4.

Comparison of manual MLI measurements to automated MLI measurements of normal versus pathologic lungs or at different developmental ages. (A) Manual and automated measurements show no difference in MLI in healthy versus emphysema lung. (B) Manual and automated measurements show no difference in MLI in P14, P21, or 8‐week‐old lung.
4. INSTRUCTIONS FOR USE (MLI ANALYSIS FIJI MACRO)
Download Fiji is just ImageJ (Fiji)
- Install the “ReadandWriteExcel” plugin
- Instructions for this can be found at https://ImageJ.net/plugins/read-and-write-excel
Create a folder on your computer for the output images
Download the macro, 2025_MLI_BP.ijm, from GitHub (https://github.com/Spiritphoenyx/2025_MLI_BP/blob/main/2025_MLI_BP.ijm)
Drag and drop the 2025_MLI_BP.ijm file into the Fiji interface (Figure 5 step 1). This will create a window called *New_.ijm
- Change D to the pixel/μm ratio of images to be analyzed. D is the variable in the first line of the script, (e.g., D = 4.34) (Figure 5 step 2).
- To find the ratio, open an image then go to analyze➔set scale. The ratio will be listed after ‘scale:’
- If an image has no metadata (Scale: <no scale>), the scale will need to be determined prior to using the macro; if it has a scale bar use the ruler tool to measure the scale bar. This will automatically find the distance in pixels. Go to analyze→set scale (Figure 5 step 2B). The distance in pixels should automatically populate. Enter the length of the scale bar into the known distance, set the pixel aspect ratio to 1, and change the unit of length to μm. The ratio will then appear after ‘Scale:’ (e.g., Scale: 4.34)
- Go to Process➔Batch➔Macro and copy the script from the coding interface to the batch process window (Figure 5 step 3)
- In the code window go to edit➔select all➔edit➔copy
Select the input folder (folder with images to be analyzed) and the output folder (#3 above) (Figure 5 step 4)
Set output format to TIFF
- Press process
- This will analyze all the images in the input folder and put all generated images in the output folder. Each output image will consist of a stack of all images generated for each image, including the reference image and each of the generated lines
- This will generate an Excel sheet with the data on your computer desktop called “Rename me after Writing is done”
- Rename the “Rename me after Writing is done” excel sheet that was generated on the desktop and then save it
- All data will be present in this excel sheet labeled by image title_line that was measured (e.g., in Figure 1A)
- You must rename the spreadsheet or remove the data from the spreadsheet prior to running the next group for analysis, or the data will be appended to the existing excel
These data can be further analyzed with the MLI_excel statistics macro (see below).
FIGURE 5.

Visualization of steps used to set up the macro.
5. TROUBLESHOOTING TIPS
If the macro is asked to analyze more than 1000 images into one spreadsheet excel will eventually run out of horizontal room and there will be an error that will derail analysis of further images. If this occurs, force quit Fiji. All data generated before this will not be affected. However, Fiji will keep trying to run the rest of the data and not record it. It will stall until each exception is cleared (one exception will be generated for each remaining image) and it is better to just quit and re‐open Fiji, copy remaining images to a new folder, rename the ‘rename me after writing is done spreadsheet’ so that a new spreadsheet can be generated and then re‐run the rest of the images.
Make sure there is enough space on the computer for the output images. If the computer runs out of space, this will cause an error and will slow down the process considerably.
If the “Rename me after Writing is done” excel spreadsheet is open, the program will throw an exception because it cannot add data to an open file. Close the file and try again.
The set scale function can only be accessed if there is an open image. Do not close the image between measuring the scale bar and going to analyze➔set scale. After ‘Scale:’ is determined, the image can be closed.
Line by line explanation for code function (2025_MLI_BP.ijm):
1. Sets the variable D (for distance) to 4.34. This is the pixels/μm ratio of the image. It will be different for each microscope and magnification. See instructions above for how to personalize this to different images.
2. Tells the image what the scale is. This can be useful if an image has no metadata, because it would not have to change it for each image. If the images already have this data, it is redundant
. 3. Sets the image to a 16‐bit black and white image. Histological images are typically in color and need to be changed to black and white before analysis.
4. Sets the variable “original” to be the original title of the image so that results and output images can be appropriately labeled
. 5/6. Gets the height and width of the image. This allows the script to be used on images of any size
. 7. Creates an image called reference which can be called back to generate the lines for MLI
measurements. 8–10. Creates reference images to allow for edge chord exclusion
. 11. Sets variable S (for size limit) to 10 divided by distance. This tells the macro to measure alveoli sizes only greater than 10 μm.
12. blank
. 13. Creates the top third line
. 14. Creates the top third line that is measured for MLI
. 15–20. Creates artificial edges to exclude edge chords
. 21. Renames the line to the original name of the image so that it can be referred to later if necessary
. 22–24. Makes the image binary
. 25. Inverts black and white in the image so that the negative space (alveoli) can be measured.
26. Sets the measurements wanted. It is set to only measure ‘area’ which is the area of a 1‐pixel line, aka distance divided by the pixel/μm ratio. Any additional measurements can be added here. For example, addition of mean and min/max grey values can be used to determine how accurate it is at identifying the septa. Max measurement should be close to 255. If this measurement is needed, change line 18, 38, and 58 to run (“Set Measurements…”, “area mean min redirect=(redirect image title) decimal=3”).
27. Measures the MLI excluding objects under 10 μm in length
. 28–33. Calculates chord length by multiplying area by the inverse pixel/μm ratio.
34. Copies the data to excel
. 35. Deletes the numbers from the results table so more results can be added
. 36–60. Same as 13–35 but for the mid image line.
61. blank.
62–85. Same as 13–35 but for the bottom third line.
86/87. blank.
88/89. Makes a stack of all the images generated to be referred to later if necessary and renames it the name of the original image_quantified
Macro text (2025_MLI_BP.ijm).
1 D=4.34
2 run (“Set Scale…”, “distance=D known=1 unit=micron”);
3 run(“16‐bit”);
4 original = getTitle();
5 Width = getWidth();
6 Height = getHeight();
7 run(“Duplicate…”, “title=reference”);
8 run(“Duplicate…”, “title=edges1”)
9 run(“Duplicate…”, “title=edges2”)
10 run(“Duplicate…”, “title=edges3”)
11 S=10/D
12/
13 makeRectangle(0, Height/4, Width, 1);
14 run(“Duplicate…”, “title=[topthird line]”);
15 run(“Select All”);
16 run(“Copy”);
17 selectImage(“edges1”);
18 run(“Select All”);
19 run(“Clear”, “slice”);
20 run(“Paste”);
21 rename(original + “_topthird line”)
22 setAutoThreshold(“Default no‐reset”);
23 //run(“Threshold…”);
24 run(“Convert to Mask”);
25 run(“Invert”);
26 run(“Set Measurements…”, “area decimal=3”);
27 run(“Analyze Particles…”, “size=S‐Infinity show=[Overlay Masks] display exclude”);
28 IJ.renameResults(“Results”); // otherwise below does not work…
29 for (row=0; row<nResults; row++) {
30 sum = getResult(“Area”, row) * D;
31 setResult(“Airspace”, row, sum);
32 }
33 updateResults();
34 run(“Read and Write Excel”);
35 Table.deleteRows(0, 1000);
36
37 selectImage(“reference”);
38 makeRectangle(0, Height/2, Width, 1);
39 run(“Duplicate…”, “title=[midimage line]”);
40 run(“Select All”);
41 run(“Copy”);
42 selectImage(“edges2”);
43 run(“Select All”);
44 run(“Clear”, “slice”);
45 run(“Paste”);
46 rename(original + “_midimage line”)
47 setAutoThreshold(“Default no‐reset”);
48 //run(“Threshold…”);
49 run(“Convert to Mask”);
50 run(“Invert”);
51 run(“Set Measurements…”, “area decimal=3”);
52 run(“Analyze Particles…”, “size=S‐Infinity show=[Overlay Masks] display”);
53 IJ.renameResults(“Results”); // otherwise below does not work…
54 for (row=0; row<nResults; row++) {
55 sum = getResult(“Area”, row) * D;
56 setResult(“Airspace”, row, sum);
57 }
58 updateResults();
59 run(“Read and Write Excel”);
60 Table.deleteRows(0, 1000);
61
62 selectImage(“reference”);
63 makeRectangle(0, Height*3/4, Width, 1);
64 run(“Duplicate…”, “title=[bottomthird line]”);
65 run(“Select All”);
66 run(“Copy”);
67 selectImage(“edges3”);
68 run(“Select All”);
69 run(“Clear”, “slice”);
70 run(“Paste”);
71 rename(original + “_bottomthird line”)
72 setAutoThreshold(“Default no‐reset”);
73 //run(“Threshold…”);
74 run(“Convert to Mask”);
75 run(“Invert”);
76 run(“Set Measurements…”, “area decimal=3”);
77 run(“Analyze Particles…”, “size=S‐Infinity show=[Overlay Masks] display”);
78 IJ.renameResults(“Results”); // otherwise below does not work…
79 for (row=0; row<nResults; row++) {
80 sum = getResult(“Area”, row) * D;
81 setResult(“Airspace”, row, sum);
82 }
83 updateResults();
84 run(“Read and Write Excel”);
85 Table.deleteRows(0, 1000);
86
87
88 run(“Images to Stack”, “use”);
89 rename(original + “_quantified”);
Instructions for using MLI statistics macro (MLI_excel statistics macro.bas):
Download the MLI_excel statistics macro.bas (https://github.com/Spiritphoenyx/2025_MLI_BP/blob/main/MLI_excel%20statistics%20macro.bas)
Open the renamed Fiji output Excel file
- Enable the developer tab
- Mac
-
Excel➔Preferences➔Ribbon & Toolbar➔toggle on Developer(Right side of window, customize the ribbon dropdown, scroll down to Developer)
-
- PC
- File➔Options➔Customize Ribbon➔toggle on Developer
Close Ribbon & Toolbar window
-
Open the Visual Basics Editor window
- Click on Tools tab➔click on Macro➔click on Visual Basics Editor
(this opens the Visual Basics Editor window)
- Click on the Microsoft Visual Basics window➔Click on the File tab,
- Click on Import File…
- Import the downloaded MLI_excel_statistics macro.bas file
- Press the play/run button, choose MLIstatistics
MLI statistics macro text (MLI_excel statistics macro.bas).
Range(“A1:A4”).Select
Selection.EntireRow.Insert, CopyOrigin:=xlFormatFromLeftOrAbove
Range(“A1”).Select
ActiveCell.FormulaR1C1 = “Total Average”
Range(“B1”).Select
ActiveCell.FormulaR1C1 = “Total Standard Deviation”
Range(“C1”).Select
ActiveCell.FormulaR1C1 = “Total CV”
Range(“A3”).Select
ActiveCell.FormulaR1C1 = “average”
Range(“B3”).Select
ActiveCell.FormulaR1C1 = “standard deviation”
Range(“C3”).Select
ActiveCell.FormulaR1C1 = “CV”
Range(“A4”).Select
ActiveCell.FormulaR1C1 = “=AVERAGE(R[3]C[2]:R[996]C[2])”
Range(“B4”).Select
ActiveCell.FormulaR1C1 = “=STDEV.S(R[3]C[1]:R[996]C[1])”
Range(“C4”).Select
ActiveCell.FormulaR1C1 = “=RC[‐1]/RC[‐2]*100”
Range(“A3:D4”).Select
Range(“A4”).Activate
Selection.Copy
Rows(“3:4”).Select
ActiveSheet.Paste
Range(“A2”).Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = “=AVERAGEIF(R[2], ““<>”“&0)”
Range(“A2”).Select
Selection.ClearContents
ActiveCell.FormulaR1C1 = “=AVERAGEIF(R[1], ““average””, R[2])”
Range(“A3”).Select
ActiveWindow.SmallScroll ToRight:=0
ActiveWindow.SmallScroll Down:=0
Range(“A2”).Select
ActiveCell.FormulaR1C1 = “=AVERAGEIFS(R[2], R[1], ““average””, R[2], ““>0””)”
Range(“A2”).Select
Selection.Copy
Range(“B2”).Select
ActiveSheet.Paste
Range(“C2”).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = “=AVERAGEIFS(R[2], R[1], ““CV””, R[2], ““>0””)”
Range(“B2”).Select
ActiveCell.FormulaR1C1 = _
“=AVERAGEIFS(R[2], R[1], ““standard deviation””, R[2], ““>0””)”
Range(“B3”).Select
End Sub
6. DISCUSSION
The primary advantage of this method is the increased speed compared to manual measurement. Analyzing large datasets via MLI can take weeks to months if done manually compared to minutes when analyzed with this script. This macro also considers (and excludes) area occupied by septa, whereas manual measurement may or may not take this into account. Because it significantly lessens the labor needed for analysis, more measurements can be taken, potentially increasing accuracy. MLI is often measured on one line per image because it is labor‐intensive, which results in less data to average per image to derive the MLI measurements.
Several other methods of semi‐automation have been reported; however, these methods do not replicate the measurement in comparison to manually performed measurements, 5 use a small number of manually measured lung images for validation, 6 or do not have accessible code. 7 , 8
We hope this MLI Fiji macro and MLI Excel statistics macro can help fill the automation gap for lung MLI measurements.
ACKNOWLEDGMENTS
This work was supported by National Institutes of Health grant R01 HL176901. This work would not have been possible without the ‘Read and Write Excel’ plugin.
DATA AVAILABILITY STATEMENT
Fiji and Excel macros are available for download from GitHub.
REFERENCES
- 1. Knudsen L, Weibel ER, Gundersen HJ, Weinstein FV, Ochs M. Assessment of air space size characteristics by intercept (chord) measurement: an accurate and efficient stereological approach. J Appl Physiol. 1985;108(2):412‐421. doi: 10.1152/japplphysiol.01100.2009 [DOI] [PubMed] [Google Scholar]
- 2. Parameswaran H, Majumdar A, Ito S, Alencar AM, Suki B. Quantitative characterization of airspace enlargement in emphysema. J Appl Physiol (1985). 2006;100(1):186‐193. doi: 10.1152/japplphysiol.00424.2005 [DOI] [PubMed] [Google Scholar]
- 3. Schindelin J, Arganda‐Carreras I, Frise E, et al. Fiji: an open‐source platform for biological‐image analysis. Nat Methods. 2012;9(7):676‐682. doi: 10.1038/nmeth.2019 [DOI] [PMC free article] [PubMed] [Google Scholar]
- 4. Wadhwa RR, Azzam D. Variance. StatPearls. StatPearls Publishing LLC; 2025. [PubMed] [Google Scholar]
- 5. Crowley G, Kwon S, Caraher EJ, et al. Quantitative lung morphology: semi‐automated measurement of mean linear intercept. BMC Pulm Med. 2019;19(1):206. doi: 10.1186/s12890-019-0915-6 [DOI] [PMC free article] [PubMed] [Google Scholar]
- 6. Salaets T, Tack B, Gie A, et al. A semi‐automated method for unbiased alveolar morphometry: validation in a bronchopulmonary dysplasia model. PLoS One. 2020;15(9):e0239562. doi: 10.1371/journal.pone.0239562 [DOI] [PMC free article] [PubMed] [Google Scholar]
- 7. Salsabili S, Lithopoulos M, Sreeraman S, et al. Fully automated estimation of the mean linear intercept in histopathology images of mouse lung tissue. J Med Imaging (Bellingham). 2021;8(2):27501. doi: 10.1117/1.Jmi.8.2.027501 [DOI] [PMC free article] [PubMed] [Google Scholar]
- 8. Politis D, Salsabili S, Chan ADC. An automated tool to assess air space size in histopathology images of lung tissue. 2022 IEEE International Instrumentation and Measurement Technology Conference (I2MTC). Institute of Electrical and Electronics Engineers; 2022:1‐6. doi:10.1109/I2MTC48687.2022.9806556 [Google Scholar]
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
Data Availability Statement
Fiji and Excel macros are available for download from GitHub.
