## 2 Materials and Methods
### Image Processing and Analysis for Identification of Excess Lung Fluid in MR Lung Density Images
#### 2.4.2 Images Are Thresholded to Identify Excess Lung Fluid (Step 2)  
As described previously, MR density imaging captures the distribution of fluid in the lung by detecting the presence of water. In healthy lungs, water is detected in blood, lung tissue, and/or large blood vessels. In CF lungs, water is detected in not only healthy tissue but also in mucus and abnormal lung structures. Thus, images from healthy subjects comprise our control group, and the density of lung fluid in each ROI from this group is used to determine the presence of excess lung fluid. Each of the 18 ROIs are considered separately, as normal fluid and/or other anatomical structures do not occur uniformly across all ROIs [26]. The median of the pixel intensities within each ROI is computed using density images from the control group only. Intensities falling below two standard deviations of the control group's median in each ROI represent normal lung fluid. These values become the threshold barriers for each ROI and are used to remove noise from the images by reassigning pixels below these barriers to an intensity value of 0. The remaining pixels represent excess lung fluid and are reassigned with an intensity value of 1. This step concludes with binarized images of each ROI displaying only excess fluid.  
Figure 3: Graphical representation of image processing technique. (**A**) Input MR density image of a sagittal slice of the lung. (**B**) Input image mask identifying 9 ROIs of the lung. (**C**) The resulting image from step 1 after the MR density image is divided into 9 ROIs using the mask. (**D**) Resulting images of the excess fluid in each lung ROI from the thresholding procedure in step 2. (**E**) 8-connected components are identified and labeled using unique integers. (**F**) The resulting image after step 3 displays the labeled connected components. The output of the image processing procedure is the area and location of each connected component calculated in step 4.  
2.4.3. Identification of Connected Components (Step 3)  
The third step in the image processing technique identifies connected components representing a collection of excess fluid. A collection of excess fluid may also be thought of as a cluster of excess fluid present in the image shown by white pixels, as in Figure 3D.  
The image processing technique searches for an unlabeled pixel in the density image \(I\) and uses a flood-fill algorithm to label collections of pixels, which are groups of pixels that are 8-connected (i.e., their edges or corners touch) (Figure 3E). A flood-fill algorithm, sometimes called seed-fill, is a basic algorithm used in a variety of image processing applications and is described in its basic form in [28] and can be implemented using MATLAB version R2021b's built-in functions _bwconncomp_ and _bwlabel_. We label each connected component in the density image \(I\) uniquely using an integer and construct a new image \(L\) that contains the labeled connected components in the ROI. This step is repeated until all pixels have been labeled and the result is an image \(L\) that contains all the connected components and their respective labels (Figure 3F).  
2.4.4. Quantification of Excess Fluid Collections (Step 4)  
The image processing technique concludes by calculating the pixel area of each connected component and recording the location (ROI) in which it was found. The area of each labeled connected component is defined as the total number of pixels within that label. At this stage, we can easily identify each collection of excess fluid and its respective pixel area in each ROI by the unique labels generated in step 3. The output is the pixel area of each labeled connected component per ROI.