Image Analysis of Dynamic Brain Activity Based on Gray Distance Compensation

: Assessing time-dependent changes in brain activity is of crucial importance in neuroscience. Here, we propose a novel image processing method to automatically identify active regions and assess time-dependent changes in ﬂuorescence arising from genetically encoded indicators of activity. First, potential active regions and the corresponding active centers were extracted based on gray distance compensation. Then potential active regions were aligned through frames and, if meeting pre-determined intensity criteria, were accepted as active regions and the ﬂuorescence changes were quantiﬁed. We validated this method with independent in vivo imaging datasets collected from transgenic mice that express the genetically encoded calcium indicator GCaMP3. Our studies indicate that the incorporation of this gray distance compensation-based algorithm substantially improves the accuracy and efﬁciency of detecting and quantifying cellular activity in the intact brain. can resolve cellular activity in the intact brain of mice that express the genetically encoded calcium indicator GCaMP3. Here, we show that by performing gray transformation and distance compensation, information about the activity of individual astrocytes in the cortex can be more precisely extracted, enabling the automatic detection and quantification of dynamic changes in the fluorescence of these cells, and the calcium signals they reflect, as mice engage in different behaviors.


Introduction
Functional brain imaging provides a means to reveal the relationship between activity in discrete neuronal and glial cell populations and animal behavior. With the development of genetically encoded indicators that change their fluorescence in response to cytosolic concentration of signaling intermediates, such as calcium, pH and cAMP (cyclic adenosine monophosphate), there is an unprecedented opportunity for studying cellular activity in a variety of physiological and pathological contexts. By assessing intensity changes in serial images acquired during different behaviors, activity patterns in the brain accompanying specific behaviors can be defined [1][2][3]. However, most studies have been performed on animals that are restrained beneath a microscope, limiting the extent of behaviors that can be assessed. Fiber-optic technology [4] has many advantages for in vivo studies of brain activity: it can be miniaturized, it is flexible, and it can carry information over long distances with minimal signal loss, allowing high resolution information to be obtained from the brains of genetically modified animal models engaged in specific behaviors. We recently reported the development of a fiber bundle-based fluorescence microscope that can image cellular activity in freely moving animals for long periods of time [5]. Dynamic changes in intracellular calcium levels in astrocytes, indicative of neuromodulatory signaling [3,6,7], are typically assessed by measuring the intensity change over time in user-defined regions of interest. Although this cursory analysis provides general information about activity patterns, it can lead to the inaccurate detection of active regions, it is time consuming to select regions, and is susceptible to user bias.
To increase throughput and improve reproducibility, we developed an automated analysis method for detection of fluorescence intensity changes in serial images. This approach involves three discrete steps to detect and assess intensity profiles for individual cells: (a) The weak emission from the activated cells are enhanced; then (b) the regions of maximum intensity are detected and the activity regions in serial frames are matched; and finally (c) intensity changes of serial frames are calculated and mapped to the active regions. We show that this approach greatly facilitates the measurement of cellular activity acquired in vivo using a fiber optic imaging device.

Automated Detection of Cellular Activity
The fiber optic brain imaging system prototype, as previously described [5], consists of a 473-nm laser, a fiber bundle, a charge-coupled device (CCD) camera (GS2-FW-14S5M, Point Gray, San Diego, CA, USA), and custom-designed micro-objective lenses. The expanded 473-nm laser beam is coupled into the fiber bundle, then the light out of the fiber distal tip projects onto the brain tissue and the fluorescent light emitted from cells in the brain is collected by the same fiber, reflected off a dichroic mirror, and detected by the CCD camera. Transgenic mice that express the calcium indicator GCaMP3 in astrocytes (GLAST-CreER;R26-lsl-GCaMP3) [3] were used for this study. All experiments were performed in strict accordance with protocols approved by the Animal Care and Use Committee at Johns Hopkins University.
The automated activity region detection method consists of two main steps, as shown in Figure 1. In step 1, serial brain images are enhanced to extract cellular activity areas based on gray transformation and distance compensation. Cellular activity centers are located and matched within frames in step 2.
Appl. Sci. 2017, 7, 858 2 of 7 cursory analysis provides general information about activity patterns, it can lead to the inaccurate detection of active regions, it is time consuming to select regions, and is susceptible to user bias. To increase throughput and improve reproducibility, we developed an automated analysis method for detection of fluorescence intensity changes in serial images. This approach involves three discrete steps to detect and assess intensity profiles for individual cells: (a) The weak emission from the activated cells are enhanced; then (b) the regions of maximum intensity are detected and the activity regions in serial frames are matched; and finally (c) intensity changes of serial frames are calculated and mapped to the active regions. We show that this approach greatly facilitates the measurement of cellular activity acquired in vivo using a fiber optic imaging device.

Automated Detection of Cellular Activity
The fiber optic brain imaging system prototype, as previously described [5], consists of a 473nm laser, a fiber bundle, a charge-coupled device (CCD) camera (GS2-FW-14S5M, Point Gray，San Diego, CA, USA), and custom-designed micro-objective lenses. The expanded 473-nm laser beam is coupled into the fiber bundle, then the light out of the fiber distal tip projects onto the brain tissue and the fluorescent light emitted from cells in the brain is collected by the same fiber, reflected off a dichroic mirror, and detected by the CCD camera. Transgenic mice that express the calcium indicator GCaMP3 in astrocytes (GLAST-CreER;R26-lsl-GCaMP3) [3] were used for this study. All experiments were performed in strict accordance with protocols approved by the Animal Care and Use Committee at Johns Hopkins University.
The automated activity region detection method consists of two main steps, as shown in Figure  1. In step 1, serial brain images are enhanced to extract cellular activity areas based on gray transformation and distance compensation. Cellular activity centers are located and matched within frames in step 2.

Detection of Active Regions
As astrocytes respond to the release of neuromodulators such as norepinephrine through a rise of calcium [3,6,7], regions where the cells express GCaMP3 exhibit distinct time-varying changes in fluorescence, defined as "active regions". As GCaMP3 was expressed by only a subset of cells [3], it is possible to delineate the boundaries of active regions that provide valid signals. With a bench-top two-photon microscope, the boundaries of these cells could be identified and served as a standard for analysis development.
With this fiber-optic imaging system, the excitation as well as emission of fluorescence from the GCaMP3-expressing astrocytes are significantly absorbed and scattered by brain tissue, resulting in images with the most pixel intensities falling within the middle level of the gray scale. Because our ability to discriminate fluorescence changes decreases when the image intensity is in the middle level [8], active regions were often not obvious and did not have distinct boundaries. To facilitate the identification of active regions, the gray level in individual frames were transformed by Equation (1), where f is the pixel gray value in the image, and R(f) is the transformed resolving level.

Detection of Active Regions
As astrocytes respond to the release of neuromodulators such as norepinephrine through a rise of calcium [3,6,7], regions where the cells express GCaMP3 exhibit distinct time-varying changes in fluorescence, defined as "active regions". As GCaMP3 was expressed by only a subset of cells [3], it is possible to delineate the boundaries of active regions that provide valid signals. With a bench-top two-photon microscope, the boundaries of these cells could be identified and served as a standard for analysis development.
With this fiber-optic imaging system, the excitation as well as emission of fluorescence from the GCaMP3-expressing astrocytes are significantly absorbed and scattered by brain tissue, resulting in images with the most pixel intensities falling within the middle level of the gray scale. Because our ability to discriminate fluorescence changes decreases when the image intensity is in the middle level [8], active regions were often not obvious and did not have distinct boundaries. To facilitate the identification of active regions, the gray level in individual frames were transformed by Equation (1), where f is the pixel gray value in the image, and R(f ) is the transformed resolving level.
Appl. Sci. 2017, 7, 858 After gray transformation, the higher and lower gray levels are stretched and the middle gray is compressed, so most active areas with higher gray levels, the putative active regions, are enhanced and share the same resolving level. Then, the post-transformation images were binarized. Since intensity level varies among frames, Equation (2) gives rise to a binarization threshold f H that is specific to each frame, by taking into account the image maximum gray f max and its transformed resolving level R(f max ), as follows: r is a coefficient, set to 5~10, with its value inverse to the mean intensity of each frame. In short, by plugging in the term of the r × R(f max ), Equation (2) factors in the brightness of individual images when determining the binarization threshold f H .
White regions in the binarized image ( Figure 2b) should denote active astrocytes; however, when compared to the two-photon standard, some regions were inappropriately categorized as active, presumably because of light scattering from nearby active cells. To eliminate this influence, a gray distance compensation is proposed [9,10]. This concept is based on the fact that the farther the tissue is to the activity center, the weaker the influence of the scattering light is to it, as described by Equation (3): where f c is the gray value after the distance compensation, f is the pixel gray value of the raw brain image, and Dist(g) is the minimum Euclidean distance to the activity center. c is a compensation coefficient correlated with the extent of light scattered from an active cell; c is at 1 when the scattering is minimal.
After gray transformation, the higher and lower gray levels are stretched and the middle gray is compressed, so most active areas with higher gray levels, the putative active regions, are enhanced and share the same resolving level. Then, the post-transformation images were binarized. Since intensity level varies among frames, Equation (2) gives rise to a binarization threshold fH that is specific to each frame, by taking into account the image maximum gray fmax and its transformed resolving level R(fmax), as follows: r is a coefficient, set to 5~10, with its value inverse to the mean intensity of each frame. In short, by plugging in the term of the r × R(fmax), Equation (2) factors in the brightness of individual images when determining the binarization threshold fH.
White regions in the binarized image ( Figure 2b) should denote active astrocytes; however, when compared to the two-photon standard, some regions were inappropriately categorized as active, presumably because of light scattering from nearby active cells. To eliminate this influence, a gray distance compensation is proposed [9,10]. This concept is based on the fact that the farther the tissue is to the activity center, the weaker the influence of the scattering light is to it, as described by Equation (3): where fc is the gray value after the distance compensation, f is the pixel gray value of the raw brain image, and Dist(g) is the minimum Euclidean distance to the activity center. c is a compensation coefficient correlated with the extent of light scattered from an active cell; c is at 1 when the scattering is minimal. Once active regions were determined, activity centers were defined as the highest intensity points in these regions. To perform the distance compensation, for every pixel binarized as 1, Euclidean distances to each individual activity center are first calculated. The smallest of these was Once active regions were determined, activity centers were defined as the highest intensity points in these regions. To perform the distance compensation, for every pixel binarized as 1, Euclidean distances to each individual activity center are first calculated. The smallest of these was then designated as Dist(g) and processed through Equation (3). As a result, the gray value of each pixel was selectively compensated with respect to its nearest activity center. Figure 2 illustrates how these manipulations enable the detection of active cells. The maximum relative intensity f max of the raw image is 81 A.U. (arbitrary units), the resolving level R(f max ) was 7, the average intensity was 14 A.U., r was 5, c was 1.2, and the threshold f H was 46 A.U. The results of gray distance compensation is shown in Figure 2c. Fifteen activity centers (or, centers of individual astrocytes) were detected and their dynamics assessed after the gray distance compensation. The margins of these active regions match the boundaries that were defined by the two-photon standard.

Activity Center Tracing in Serial Images
During imaging there can be time-dependent changes in signal that occur independent of cellular activity, due to, for example, the inherent-honeycomb pattern noise of the fiber bundles [11] and changes in tissue absorption characteristics over time. To limit these cellular activity-independent effects on center-tracing, an offset of 15-20 pixels between potentially-matching centers was tolerated from frame to frame. Several active regions were first selected from an image that was used as a reference frame for the rest of the time series. This tolerance of offset within a time series morphs the activity centers of each frame into matching activity areas among frames. These activity regions were then refined by selecting pixels with a mean gray distance larger than the mean of the full frame intensity. Figure 3 displays the extracted activity areas. The first row is a short four-frame series of fluorescence changes exhibited by GCaMP3-expressing astrocytes in the imaging field. The second row is the extracted activity centers for each corresponding frame, marked with red dots. This demonstrates that, in the same brain region, there can be 17, 15, 17, and 20 activity centers detected. With the offset-tolerance approach (offset: 20), Figure 4a shows the 12 matched activity centers among these four frames. The matched activity centers are marked with different colors and shapes. Figure 4b is a zoom-in view of the highlighted region-of-interest in Figure 4a.
Appl. Sci. 2017, 7, 858 4 of 7 then designated as Dist(g) and processed through Equation (3). As a result, the gray value of each pixel was selectively compensated with respect to its nearest activity center. Figure 2 illustrates how these manipulations enable the detection of active cells. The maximum relative intensity fmax of the raw image is 81 A.U. (arbitrary units), the resolving level R(fmax) was 7, the average intensity was 14 A.U., r was 5, c was 1.2, and the threshold fH was 46 A.U. The results of gray distance compensation is shown in Figure 2c. Fifteen activity centers (or, centers of individual astrocytes) were detected and their dynamics assessed after the gray distance compensation. The margins of these active regions match the boundaries that were defined by the two-photon standard.

Activity Center Tracing in Serial Images
During imaging there can be time-dependent changes in signal that occur independent of cellular activity, due to, for example, the inherent-honeycomb pattern noise of the fiber bundles [11] and changes in tissue absorption characteristics over time. To limit these cellular activityindependent effects on center-tracing, an offset of 15-20 pixels between potentially-matching centers was tolerated from frame to frame. Several active regions were first selected from an image that was used as a reference frame for the rest of the time series. This tolerance of offset within a time series morphs the activity centers of each frame into matching activity areas among frames. These activity regions were then refined by selecting pixels with a mean gray distance larger than the mean of the full frame intensity. Figure 3 displays the extracted activity areas. The first row is a short four-frame series of fluorescence changes exhibited by GCaMP3-expressing astrocytes in the imaging field. The second row is the extracted activity centers for each corresponding frame, marked with red dots. This demonstrates that, in the same brain region, there can be 17, 15, 17, and 20 activity centers detected. With the offset-tolerance approach (offset: 20), Figure 4a shows the 12 matched activity centers among these four frames. The matched activity centers are marked with different colors and shapes. Figure  4b is a zoom-in view of the highlighted region-of-interest in Figure 4a.

Performance of Analysis Routine on Distinct Imaging Datasets
Two time-lapsed image series were processed and analyzed. Both series were acquired at 2 Hz, with Set 1 having 40 frames (duration: 20 s) and Set 2 having 660 frames (duration: 330 s). The active regions were detected automatically based on the method given in Section 2. Table 1 shows the number of frames that were analyzed and matched for selected active regions. The offset values were 17 pixels for Set 1 and 15 pixels for Set 2. It should be noted that active regions do not match for some frames due, presumably, to decreases in intensity resulting from brain motion.  Figure 5 plots the change of fluorescence intensity versus frame for five of the active regions found in Set 1. For each plot, the X-axis is the lapsed time and the Y-axis is the mean intensity of the 15 by 15 pixels square around the activity center. The discrete dots denote the mean intensity of the active region in each frame; the blue lines are the polynomial fitted curve to each data point (generated with MATLAB curve fitting tools). The plots illustrate that these defined activity areas exhibit distinct intensity changes with similar time-locked characteristics. Figure 6 shows the fluorescence intensity change over frames for four of the active regions in Set 2. To illustrate relative activity patterns for the four cells at different times, Set 2 is subdivided into two sections: with 50-150 s corresponding to the time of "high" cellular activities and 200-250 s to "low" cellular activities. Although the four regions share similar kinetics of intensity change, there exists a significant difference in the magnitude of change. For example, compare the intensity rise from 55 to 75 for cell 3 and from 90 to 120 for cell 4. These differences in regional fluorescence changes highlight the heterogeneous nature of astrocyte responses in the intact brain and show that this analysis method can aid in identifying and extracting information about astrocyte activity in different physiological contexts.  Figure 4a. Markers of four types denote the active centers found in each of the four images (red dots for the 1 st image; green circles for the 2 nd ; magenta crosses for the 3 rd ; blue asterisks for the 4 th ).

Performance of Analysis Routine on Distinct Imaging Datasets
Two time-lapsed image series were processed and analyzed. Both series were acquired at 2 Hz, with Set 1 having 40 frames (duration: 20 s) and Set 2 having 660 frames (duration: 330 s). The active regions were detected automatically based on the method given in Section 2. Table 1 shows the number of frames that were analyzed and matched for selected active regions. The offset values were 17 pixels for Set 1 and 15 pixels for Set 2. It should be noted that active regions do not match for some frames due, presumably, to decreases in intensity resulting from brain motion.  Figure 5 plots the change of fluorescence intensity versus frame for five of the active regions found in Set 1. For each plot, the X-axis is the lapsed time and the Y-axis is the mean intensity of the 15 by 15 pixels square around the activity center. The discrete dots denote the mean intensity of the active region in each frame; the blue lines are the polynomial fitted curve to each data point (generated with MATLAB curve fitting tools). The plots illustrate that these defined activity areas exhibit distinct intensity changes with similar time-locked characteristics. Figure 6 shows the fluorescence intensity change over frames for four of the active regions in Set 2. To illustrate relative activity patterns for the four cells at different times, Set 2 is subdivided into two sections: with 50-150 s corresponding to the time of "high" cellular activities and 200-250 s to "low" cellular activities. Although the four regions share similar kinetics of intensity change, there exists a significant difference in the magnitude of change. For example, compare the intensity rise from 55 to 75 for cell 3 and from 90 to 120 for cell 4. These differences in regional fluorescence changes highlight the heterogeneous nature of astrocyte responses in the intact brain and show that this analysis method can aid in identifying and extracting information about astrocyte activity in different physiological contexts.  The four active regions are marked in the brain image. The upper row shows the four active regions with "high" activity periods and the lower row plots the "low" activity periods. All plots have the same coordinate axes.

Discussion
A major challenge for brain imaging is to accurately assess the activity of individual cells when animals are engaged in distinct behaviors. Our previous studies describe a fiber optic imaging device that can resolve cellular activity in the intact brain of mice that express the genetically encoded calcium indicator GCaMP3. Here, we show that by performing gray transformation and distance compensation, information about the activity of individual astrocytes in the cortex can be more precisely extracted, enabling the automatic detection and quantification of dynamic changes in the fluorescence of these cells, and the calcium signals they reflect, as mice engage in different behaviors.  The four active regions are marked in the brain image. The upper row shows the four active regions with "high" activity periods and the lower row plots the "low" activity periods. All plots have the same coordinate axes.

Discussion
A major challenge for brain imaging is to accurately assess the activity of individual cells when animals are engaged in distinct behaviors. Our previous studies describe a fiber optic imaging device that can resolve cellular activity in the intact brain of mice that express the genetically encoded calcium indicator GCaMP3. Here, we show that by performing gray transformation and distance compensation, information about the activity of individual astrocytes in the cortex can be more precisely extracted, enabling the automatic detection and quantification of dynamic changes in the fluorescence of these cells, and the calcium signals they reflect, as mice engage in different behaviors. The four active regions are marked in the brain image. The upper row shows the four active regions with "high" activity periods and the lower row plots the "low" activity periods. All plots have the same coordinate axes.

Discussion
A major challenge for brain imaging is to accurately assess the activity of individual cells when animals are engaged in distinct behaviors. Our previous studies describe a fiber optic imaging device that can resolve cellular activity in the intact brain of mice that express the genetically encoded calcium indicator GCaMP3. Here, we show that by performing gray transformation and distance compensation, information about the activity of individual astrocytes in the cortex can be more precisely extracted, enabling the automatic detection and quantification of dynamic changes in the fluorescence of these cells, and the calcium signals they reflect, as mice engage in different behaviors.

Conclusions
Relating cellular activity in the brain to animal behavior requires long-term monitoring of the brain circuits and accurate methods to assess activity patterns. Due to the epifluorescence nature of these long-term imaging systems, fluorescence images acquired are often weak and the boundaries between cells difficult to define due to high photon scattering. As a result, performing data analysis on these imaging datasets is challenging and particularly sensitive to user-dependent bias. To achieve better efficiency and accuracy in processing long-term epifluorescence datasets, we proposed an automatic processing method. First, in-frame active centers were identified based on gray transformation and distance compensation. Then, the inter-frame activity regions were matched and traced through time, if reaching the offset-tolerance and a mean gray criteria. The intensity change of the individual activity area versus time was plotted for two independent time-lapse in vivo imaging datasets. We expect that this method of analysis will facilitate automatic processing of large image sequences, such as sleep-wake studies that undergo multiple light-dark cycles, and help define the distinct activity patterns of different cell types in behaviorally relevant contexts.