Thermal Time Constant CNN-Based Spectrometry for Biomedical Applications

This paper presents a novel method based on a convolutional neural network to recover thermal time constants from a temperature–time curve after thermal excitation. The thermal time constants are then used to detect the pathological states of the skin. The thermal system is modeled as a Foster Network consisting of R-C thermal elements. Each component is represented by a time constant and an amplitude that can be retrieved using the deep learning system. The presented method was verified on artificially generated training data and then tested on real, measured thermographic signals from a patient suffering from psoriasis. The results show proper estimation both in time constants and in temperature evaluation over time. The error of the recovered time constants is below 1% for noiseless input data, and it does not exceed 5% for noisy signals.


Introduction
Time-constant spectrometry is a method of reducing the dimensionality of data and signals describing time-varying dynamic processes. This technique can be used for various engineering and medical applications. Initially, this method was successfully applied for dynamic object identification, mainly in the fields of automation and control [1][2][3][4][5][6][7][8] and electrical and electronic engineering [9][10][11][12]. Thermal time-constant spectrometry is a method that effectively reduces the dimensions of the mathematical representation of a problem. It approximates a large dataset in the time and frequency domains by using a series with only a few components. This technique has already been employed in the modeling of long energetic lines to predict their performance [12]. The distribution of time constants finds application in communication system modeling, utilizing the immittance concept [4]. Additionally, time-constant spectrometry can simplify the modeling of a complex electrical network in dynamic states, aiding in the analysis and prediction of its behavior [2]. Recently, time-constant spectrometry has also been used for biomedical applications where the skin temperature is monitored by infrared (IR) thermography [13,14]. In the heat transfer domain, thermal systems can be modeled as the R-C Foster Network that are directly corresponding to the time-constant distribution [9,10,[13][14][15][16][17]. R-C networks are used for thermal object characterization. Such a network is a chain of thermal resistance and capacitance connections. Each element of the ladder is the parallel connection of thermal resistances and thermal capacitances, while all cells are connected in series. Such modeling is the result of a multilayer structure where each of the branches corresponds to each of the layers.
It has to be underlined that the process of time-constant identification of a dynamic system is a kind of inverse problem that is, in general, ill-conditioned. In particular, it is a very severe problem in the heat transfer domain because the non-orthogonal set of functions approximates the temperature changes in the dynamic processes.
There are a few existing methods being used for dynamic system identification based on data processing in either the time or frequency domain. In electronics for thermal -Section 2: Materials and Methods-presents the proposed approach for the timeconstant spectrometry method based on CNN. It includes a description of the proposed structure of the CNN network, the dataset, and the training and validation processes. -Section 3: Results-is divided into subsections: Section 3.1-presents the results of network validation for artificially generated data.
Sensors 2023, 23, 6658 3 of 12 Section 3.2-presents the results for artificially generated data with different levels of noise added. Section 3.3-presents the network verification for real measurements of the patient suffering from psoriasis-for healthy and unhealthy parts of the skin.
-Section 4-discusses the results, concludes the paper, and lists some possible future work.

Materials and Methods
Time-constant spectrometry requires solving the ill-conditioned inverse problem. In this research, a regressive convolutional neural network is proposed for this purpose. The problem is to reconstruct the thermal time-constant distribution from the temperature changes over time, measured using a high-speed thermal imaging camera. Temperature curves can be approximated by the sum of a few exponential components, each representing a thermal time constant [30]. Tests show that a four-time-constant approximation gives satisfactory results with a low value of error between the original and predicted data. This number of time constants was chosen for the training procedure.
Several convolutional neural networks with and without residual layers were tested. In addition, different numbers of feature layers, filters used, and kernel sizes were implemented, and their effectiveness was verified. The software was developed in the Python environment using the TensorFlow and Keras libraries [31]. After several attempts, the network shown in Figure 1 was selected. − Section 4-discusses the results, concludes the paper, and lists some possible future work.

Materials and Methods
Time-constant spectrometry requires solving the ill-conditioned inverse problem. In this research, a regressive convolutional neural network is proposed for this purpose. The problem is to reconstruct the thermal time-constant distribution from the temperature changes over time, measured using a high-speed thermal imaging camera. Temperature curves can be approximated by the sum of a few exponential components, each representing a thermal time constant [30]. Tests show that a four-time-constant approximation gives satisfactory results with a low value of error between the original and predicted data. This number of time constants was chosen for the training procedure.
Several convolutional neural networks with and without residual layers were tested. In addition, different numbers of feature layers, filters used, and kernel sizes were implemented, and their effectiveness was verified. The software was developed in the Python environment using the TensorFlow and Keras libraries [31]. After several attempts, the network shown in Figure 1 was selected. The network consists of nine layers. The first and last layers are dense. They transform input and output into lower-and higher-dimensional representations, respectively. The convolutional layers in between use 32 filters with a kernel size of 3 × 3 and apply the sigmoid activation function.
The convolutional layers perform the 2D convolution operations on the input data, extracting features using the 32 filters. The 'padding' parameter is set to 'same' to preserve the spatial dimensions of the output feature maps. The last convolutional layer has a single filter and produces a single-channel output.
This output is then connected to a Flatten layer, which reshapes it into a 1D vector with 1024 elements. The flattened data are passed through a dense layer with 8 neurons, applying a linear transformation followed by the sigmoid activation function. This layer is responsible for generating the final output of the network, consisting of 4 thermal time constants and their amplitudes.
Transfer learning was applied in this research. This means that the input data used for training the CNN network consists of curves that are generated artificially as the sum of four exponential components with known values of the amplitudes of the thermal time constants (Equation (1)). The thermal time constants and their amplitudes are randomly The network consists of nine layers. The first and last layers are dense. They transform input and output into lower-and higher-dimensional representations, respectively. The convolutional layers in between use 32 filters with a kernel size of 3 × 3 and apply the sigmoid activation function.
The convolutional layers perform the 2D convolution operations on the input data, extracting features using the 32 filters. The 'padding' parameter is set to 'same' to preserve the spatial dimensions of the output feature maps. The last convolutional layer has a single filter and produces a single-channel output.
This output is then connected to a Flatten layer, which reshapes it into a 1D vector with 1024 elements. The flattened data are passed through a dense layer with 8 neurons, applying a linear transformation followed by the sigmoid activation function. This layer is responsible for generating the final output of the network, consisting of 4 thermal time constants and their amplitudes.
Transfer learning was applied in this research. This means that the input data used for training the CNN network consists of curves that are generated artificially as the sum of four exponential components with known values of the amplitudes of the thermal time constants (Equation (1)). The thermal time constants and their amplitudes are randomly generated within the [0, 1] range, as shown in Table 1. In the presented research, each curve is composed of four exponential components.  The CNN model is designed to fit temperature rise measurements over time that are recorded by the IR camera at a frequency of 50 Hz for approximately 6 min. Each measurement consists of approximately 18,000 samples. Training the CNN network with thousands of such large data vectors can be time-consuming and requires significant memory and computing power. Furthermore, the crucial part of the temperature rise curve with the most important information about the time constants is at the beginning. To recover the dynamic behavior of the thermal system, the temperature curves over time are non-uniformly resampled, with denser sampling at the beginning and sparser sampling in the quasi-steady state region. To speed up the learning process, each temperature curve is represented by 1024 non-uniformly distributed samples only.
For training and validation, the ranges of the parameter values τ i , T i are normalized, i.e., τ i ∈ [0, 1] s, T i ∈ [0, 1] • C. To ensure data consistency during the test, the temperature evolution computationally generated in any time interval is scaled to [0, 1] s. A similar operation is performed for the temperature curves of the measured signals. Finally, both the thermal time constants and their amplitudes were scaled up using the same scaling coefficients. All these normalization operations essentially help in the CNN learning process.
The main parameters of the proposed network are listed in Table 1.
The learning process uses a set of 10,000 training and 1000 validation data points, respectively. The input data consist of temperature curves over time calculated using the randomly generated time constants and their amplitudes. The entire training procedure takes 5000 epochs.
An example of the decay of the loss function values during training and validation is presented in Figure 2.
The trained network was tested on 1000 smooth curves, 1000 noisy curves, and 2 temperature measurements over time. The proposed method was also verified on a psoriasis patient, where both healthy and diseased parts of his skin were analyzed.
The loss function defined in the developed CNN network uses a weighted sum of the mean squared error of τ i and T i . The research results show that due to the greater impact of time constants compared to thermal amplitudes on the evolution of temperature in time, the network approximates τ i better than T i . Therefore, the effect of time constants on the loss function is arbitrarily reduced by defining the weighted loss function, as shown in Table 1.
The proposed CNN architecture is a compromise between its computational complexity and its performance. The loss function in Figure 2 confirms that the network still has the potential to learn, and we do not observe any signs of overlearning. It appears that there is room for larger datasets to further reduce the overall error of the network. The concept of the ResNet network with long connections accelerates learning and protects against gradient vanishing. Additionally, more advanced augmentation techniques can be applied.  The trained network was tested on 1000 smooth curves, 1000 noisy curves, and 2 temperature measurements over time. The proposed method was also verified on a psoriasis patient, where both healthy and diseased parts of his skin were analyzed.
The loss function defined in the developed CNN network uses a weighted sum of the mean squared error of τi and Ti. The research results show that due to the greater impact of time constants compared to thermal amplitudes on the evolution of temperature in time, the network approximates τi better than Ti. Therefore, the effect of time constants on the loss function is arbitrarily reduced by defining the weighted loss function, as shown in Table 1.
The proposed CNN architecture is a compromise between its computational complexity and its performance. The loss function in Figure 2 confirms that the network still has the potential to learn, and we do not observe any signs of overlearning. It appears that there is room for larger datasets to further reduce the overall error of the network. The concept of the ResNet network with long connections accelerates learning and protects against gradient vanishing. Additionally, more advanced augmentation techniques can be applied.

Network Validation for Artificially Generated Data
The training and validation data consist of the sum of exponential functions with four components. Time constants and amplitudes are randomly generated to produce these curves. The mean squared errors for 1000 samples show the deviation of the original and predicted parameters (τi and Ti). Additionally, the temperature curves over time are calculated for scaled data ranging from 0 to 1 to verify the effectiveness of the data processing. The results are presented in Table 2.

Network Validation for Artificially Generated Data
The training and validation data consist of the sum of exponential functions with four components. Time constants and amplitudes are randomly generated to produce these curves. The mean squared errors for 1000 samples show the deviation of the original and predicted parameters (τ i and T i ). Additionally, the temperature curves over time are calculated for scaled data ranging from 0 to 1 to verify the effectiveness of the data processing. The results are presented in Table 2.  The temperature changes in time after upscaling to a 6 min of acquisition interval are presented in Figure 4. The temperature changes in time after upscaling to a 6 min of acquisition interval are presented in Figure 4.  The temperature changes in time after upscaling to a 6 min of acquisition interval are presented in Figure 4.

Network Validation for Noisy Data
When using active thermography in medical applications, one must determine the temperature rise over time in a specific region of interest, typically a small spot. This task is challenging due to patient motion caused not only by controlled movements but also by physiological activities such as breathing and heartbeat. Therefore, motion correction techniques need to be applied [13,14]. This is a demanding task due to the low thermal contrast of IR images and the small size of the region of interest that needs to be recovered in each frame. Additionally, if the region of interest is located on the leg or arm, the rotation of these body parts can deform the spot and introduce errors in the temperature readings. Consequently, this can result in noise in the temperature curve over time.
The proposed method for extracting thermal time constants and their amplitudes was also tested on noisy data. A Gaussian noise with a zero mean and various variance values was added to the generated data. Mean squared errors were estimated for each test, which was performed on 1000 samples. The results are presented in Table 3. Table 3. Mean squared errors estimated between original and predicted data for thermal time constants, amplitudes and temperature rise over time at different levels of added noise.

Network Validation for Noisy Data
When using active thermography in medical applications, one must determine the temperature rise over time in a specific region of interest, typically a small spot. This task is challenging due to patient motion caused not only by controlled movements but also by physiological activities such as breathing and heartbeat. Therefore, motion correction techniques need to be applied [13,14]. This is a demanding task due to the low thermal contrast of IR images and the small size of the region of interest that needs to be recovered in each frame. Additionally, if the region of interest is located on the leg or arm, the rotation of these body parts can deform the spot and introduce errors in the temperature readings. Consequently, this can result in noise in the temperature curve over time.
The proposed method for extracting thermal time constants and their amplitudes was also tested on noisy data. A Gaussian noise with a zero mean and various variance values was added to the generated data. Mean squared errors were estimated for each test, which was performed on 1000 samples. The results are presented in Table 3. Obviously, the errors increase with higher values of the noise variance, but they do not exceed the levels of 5% and 9% even for the highest tested noise, both for time constants and their amplitudes, respectively (Table 3). This confirms that the proposed method is effective and can be used for real measurements that are often disturbed by noise.
The exemplary results of time constants and the amplitude distributions recovered for the noisy signals with the highest and lowest variance are presented in Figure 5, while the function of temperature in time is shown in Figure 6. The dense sampling at the beginning results in more frequent noise in this part of the curve. This simulates a more challenging problem to solve, leading to higher errors in such cases. Obviously, the errors increase with higher values of the noise variance, but they do not exceed the levels of 5% and 9% even for the highest tested noise, both for time constants and their amplitudes, respectively (Table 3). This confirms that the proposed method is effective and can be used for real measurements that are often disturbed by noise.
The exemplary results of time constants and the amplitude distributions recovered for the noisy signals with the highest and lowest variance are presented in Figure 5, while the function of temperature in time is shown in Figure 6. The dense sampling at the beginning results in more frequent noise in this part of the curve. This simulates a more challenging problem to solve, leading to higher errors in such cases.
The visualization of the results for the lowest (a) and highest (b) values of the noise variances is presented in Figure 5. The level of noise added to input data for the variances 0.0001 and 0.005 is clearly visible in Figure 6.

Results for a Real Data
The presented method could also be used for real measurement data, especially to determine the thermal time constants for living tissues. This would help to distinguish differences in skin reactions between healthy and unhealthy skin. Exemplary tests were made for the measurements carried out on a patient with psoriasis (see Figure 7). The visualization of the results for the lowest (a) and highest (b) values of the noise variances is presented in Figure 5.
The level of noise added to input data for the variances 0.0001 and 0.005 is clearly visible in Figure 6.

Results for a Real Data
The presented method could also be used for real measurement data, especially to determine the thermal time constants for living tissues. This would help to distinguish differences in skin reactions between healthy and unhealthy skin. Exemplary tests were made for the measurements carried out on a patient with psoriasis (see Figure 7).

Results for a Real Data
The presented method could also be used for real measurement data, especially to determine the thermal time constants for living tissues. This would help to distinguish differences in skin reactions between healthy and unhealthy skin. Exemplary tests were made for the measurements carried out on a patient with psoriasis (see Figure 7). The thermographic examination was performed dynamically using so-called thermal stress. The skin on the patient's leg was cooled down by metal blocks with a high thermal capacity by applying them to the patient's skin for 5 s. Then the temperature rise over time was recorded for two regions of interest: one corresponding to healthy skin and the other to the psoriasis area. The size of the marked ROIs is 5 × 5 pixels. The temperature drop after cooling was approximately 5-6 °C. The measurement was performed for about 6 min to reach a quasi-steady state.
A CEDIP Titanium camera with a cooled detector of 640 × 512 pixels was used to carry out the research. The use of this type of camera was necessary due to the continuity of the signal recording, unlike cheaper and smaller microbolometer cameras. The sequence of thermograms was recorded at a frequency of 50 Hz. The speed of recording was conditioned by the rapid reaction of the skin immediately after the source of thermal stimulation was removed. The thermographic examination was performed dynamically using so-called thermal stress. The skin on the patient's leg was cooled down by metal blocks with a high thermal capacity by applying them to the patient's skin for 5 s. Then the temperature rise over time was recorded for two regions of interest: one corresponding to healthy skin and the other to the psoriasis area. The size of the marked ROIs is 5 × 5 pixels. The temperature drop after cooling was approximately 5-6 • C. The measurement was performed for about 6 min to reach a quasi-steady state.
A CEDIP Titanium camera with a cooled detector of 640 × 512 pixels was used to carry out the research. The use of this type of camera was necessary due to the continuity of the signal recording, unlike cheaper and smaller microbolometer cameras. The sequence of thermograms was recorded at a frequency of 50 Hz. The speed of recording was conditioned by the rapid reaction of the skin immediately after the source of thermal stimulation was removed.
The research was carried out in accordance with the guidelines for conducting thermovision research in medicine developed by Prof. Ring from the University of Glamorgan [32]. Both the camera, the room, and the patient had to be properly prepared. The tests were performed in an air-conditioned room with a constant temperature of 20 • C. Before starting the measurements, the camera was switched on for about 15 min to achieve thermal stabilization. The tests were performed in the morning, before any hospital procedures. Before the examination, the patient had the examined part of the skin exposed for about 15 min.
To compensate for patient movement, a motion correction technique based on crosscorrelation was employed [13]. To enhance the quality of motion compensation, a piece of aluminum foil with a low-emissivity value was attached to the skin as a reference region, which is clearly visible in the thermovision images. A detailed description of the experiment can be found in [13]. Despite the movement correction, the temperature curve is still noisy. Figure 7 displays the visual and thermal images of the patient with psoriasis. The regions of interest for the unhealthy (top) and healthy (bottom) parts of the skin are cooled down and marked on the thermal image. The distance and size of the region of interest (ROI) can influence the temperature value [33]. However, in the presented approach, this factor is not as significant since two ROIs are used for comparison and they are positioned close to each other, ensuring that the camera distance is the same for both measurements. Furthermore, the absolute temperature itself is not crucial; rather, the dynamic reaction of the skin and the difference in obtained time constants for both cases are more important. The primary concern lies in reducing the noise in the obtained signal, which is mainly caused by the movement of the patient, resulting in changes in the ROI's location. Noise minimization is mainly achieved through movement correction of the marked ROIs. The healthy and unhealthy parts of the patient's skin for the ROIs were selected to be close to each other in order to cool down and register both regions at the same time. The results-the values of predicted time constants and their amplitudes-are presented in Figure 8, while the measurements for healthy and unhealthy (affected by psoriasis) parts of the skin and their approximations are shown in Figure 9.
close to each other, ensuring that the camera distance is the same for both measurements. Furthermore, the absolute temperature itself is not crucial; rather, the dynamic reaction of the skin and the difference in obtained time constants for both cases are more important. The primary concern lies in reducing the noise in the obtained signal, which is mainly caused by the movement of the patient, resulting in changes in the ROI's location. Noise minimization is mainly achieved through movement correction of the marked ROIs. The healthy and unhealthy parts of the patient's skin for the ROIs were selected to be close to each other in order to cool down and register both regions at the same time.
The results-the values of predicted time constants and their amplitudes-are presented in Figure 8, while the measurements for healthy and unhealthy (affected by psoriasis) parts of the skin and their approximations are shown in Figure 9. Finally, the recovered distribution of time constants and their amplitudes are presented in Table 4. As expected, the inflammation area of the skin is responding slowly. The additional thermal inertia is observed there due to the change in vascularization.  The distribution of recovered time constants seems to be accurate. In skin tissue measurements, the range of time constants should differ, as it does in this case. The lowest time constants fall within the range of seconds, while the longest time-constant values reach the level of hundreds of seconds. Such a range distribution is natural and aligns with the fast initial response of the curve and the eventual steady state at the end [30].
The correctness of the obtained values was confirmed by the results already published in the literature. In [30], burned skin was modeled as a two-time-constant approximation. The levels of time constants obtained were in the range of tens of seconds for the first and hundreds of seconds for the second.
Time constants are different for healthy and unhealthy parts of the skin. The proposed method could be utilized to differentiate between pathological and physiological tissue states, which would aid in the diagnosis and treatment of skin illnesses like psoriasis.

Discussion and Conclusions
The article presents a novel CNN-based method for recovering thermal time constants from a temperature-time curve after thermal excitation. The training procedure involved the generation of temperature-time curves and the validation of the results with and without noise. The trained network was then tested using real measurements from a patient suffering from psoriasis.
The presented approach shows a good approximation of the input functions both for the validation data generated artificially with and without noise as well as for data obtained from thermographic temperature measurements over time. The accuracy of the time constants is further supported by the low values of the mean squared error temperature rise in time, which are 0.00316479 for healthy skin and 0.00337056 for unhealthy skin. According to the proposed scaling and normalization of all data to the range [0, 1], as mentioned above, the obtained relative error of the presented method is less than 10%. Finally, the recovered distribution of time constants and their amplitudes are presented in Table 4. As expected, the inflammation area of the skin is responding slowly. The additional thermal inertia is observed there due to the change in vascularization. The distribution of recovered time constants seems to be accurate. In skin tissue measurements, the range of time constants should differ, as it does in this case. The lowest time constants fall within the range of seconds, while the longest time-constant values reach the level of hundreds of seconds. Such a range distribution is natural and aligns with the fast initial response of the curve and the eventual steady state at the end [30].
The correctness of the obtained values was confirmed by the results already published in the literature. In [30], burned skin was modeled as a two-time-constant approximation.
The levels of time constants obtained were in the range of tens of seconds for the first and hundreds of seconds for the second.
Time constants are different for healthy and unhealthy parts of the skin. The proposed method could be utilized to differentiate between pathological and physiological tissue states, which would aid in the diagnosis and treatment of skin illnesses like psoriasis.

Discussion and Conclusions
The article presents a novel CNN-based method for recovering thermal time constants from a temperature-time curve after thermal excitation. The training procedure involved the generation of temperature-time curves and the validation of the results with and without noise. The trained network was then tested using real measurements from a patient suffering from psoriasis.
The presented approach shows a good approximation of the input functions both for the validation data generated artificially with and without noise as well as for data obtained from thermographic temperature measurements over time. The accuracy of the time constants is further supported by the low values of the mean squared error temperature rise in time, which are 0.00316479 for healthy skin and 0.00337056 for unhealthy skin. According to the proposed scaling and normalization of all data to the range [0, 1], as mentioned above, the obtained relative error of the presented method is less than 10%. This indicates that the predicted values are close to the actual measurements, confirming the accuracy of the results.
The CNN training dataset uses scaled inputs, which makes the approximation problem more general. The input data may vary in size and duration, but they are always normalized to the same range. In order to reduce the size of the input data and shorten the learning phase, non-uniform sampling was used. Finally, rescaling the output results with time and temperature allows for the proper distribution of thermal time constants. The proposed CNN uses the weighted loss function for time constants and their amplitudes. Since the influence of the amplitudes of the time constants on the final results is weaker, their contribution to the training was increased.
The results appear to be promising. The regression CNN network shows potential in thermal time-constant spectroscopy, particularly for biomedical thermographic signals that are often noisy and disturbed. The approximation error is sufficiently small to accurately reproduce the original time constants that can be used to distinguish between physiological and pathological tissue states. In addition, compared to other optimization methods, the presented approach consistently gives satisfactory results and avoids the problem of obtaining negative values for τi, which can occur when using non-constrained optimization methods such as fminsearch [34]. Despite the ill-conditioned nature of the dynamic thermal system, the CNN works well and provides satisfactory results for input signal parameters varying over wide ranges.
Several improvements could be made, such as testing more complex CNN networks or pre-defined ones such as ResNet, AlexNet, etc. Including noisy data used in the training procedure can also be beneficial. The main challenge lies in determining the number of time constants that appear in the thermal process. The presented approach assumes an approximation of four time constants, but this may not always be sufficient. It is important to collect more measurements to confirm the correctness of the proposed approach and compare it with other methods using the same dataset.
The problem of time-constant spectrometry, especially for thermal processes, is very difficult. This is due to the fact that the exponential functions used to represent the temperature evolution in time are not orthogonal function series. The aim of this paper was to confirm that the CNN approximation can be useful to deal with this problem. The verification of the correctness of using this approach can be performed using other methods that are related to less ill-conditioned optimization problems, such as electromagnetic and electrical network identifications, as in [12]. In addition, novel approaches to CNN network correctness verification can also be applied [35][36][37][38].