This project is designed for the analysis, temporal correlation, and further processing of spirometry, ECG, and imaging data acquired during real-time cardiac MRI in combination with an ergometer system.
The goal is to correlate respiratory parameters with MRI image data, integrate them into DICOM files, and enable image-based analysis during end-expiration.
The software was developed for research purposes, particularly for the analysis of cardiac parameters under resting and exercise conditions without the use of breath-hold commands.
- Analysis of spirometry data
- Correlation of spiro and ecg data
- Fine-tuning of the correlation using the respiratory belt signal and the signal intensity curve extracted from a selected ROI in a single slice
- Insertion of respiratory parameters into the DICOM image data
- readout files
- add spiro data into dicom tags
- binning into 25 ecg-phases
- binning into exspiration and inspiration of images
- selection of 25 images, one for each ECG phase at end-expiration, from the MRI data to construct an image sequence of a single cardiac cycle for each slice
The analysis consists of three main scripts.
In the spirometry module, advanced respiratory parameters are calculated from spirometry data for both resting and exercise phases.
This is achieved by detecting peaks and valleys in the respiratory flow signal.
- Spirometry file containing:
- Respiratory flow
- O₂ volume fraction
- CO₂ volume fraction
- Log time
- Excel file containing evaluated spirometry parameters:
- Average tidal volume
- Minute ventilation
- Maximum and minimum O₂ volume fractions
- Maximum and minimum CO₂ volume fractions
- Respiratory rate
- further derived parametrs:
- oxygen uptake (VO₂), carbon dioxide production (VCO₂), respiratory exchange ratio (RER), ventilatory equivalent for oxygen (VE/VO₂)
The ECG data have the same sampling rate and log times as the MRI image data.
By correlating spirometry and ECG signals, an indirect correlation with the image data is established.
The correlation is performed using manually defined time markers that were set at the beginning of the measurement.
- Spirometry file
- ECG file
- Timestamp of the marker
- Indices of the marker in:
- Spirometry data
- ECG data
These indices allow the datasets to be trimmed so that all signals share a common start time.
To verify the temporal correlation, the respiratory belt signal and a signal intensity curve from one image slice are additionally used.
If necessary, the marker indices can be manually adjusted to improve synchronization.
- Spirometry file
- Respiratory belt signal
- Image data
- Adjusted time marker indices after fine-tuning
After successful correlation, respiratory flow and tidal volume are assigned to each image of the real-time MRI sequence and written into the DICOM files.
The images are then filtered as follows:
- Filtering for expiration (negative respiratory flow)
- Filtering for end-expiration
- Classification of images into:
- Two tidal volume groups
- below a defined threshold
- above the threshold
- 25 ECG classes (time after the R-wave)
- Two tidal volume groups
The threshold is defined as a fraction of the average tidal volume (e.g., 30%).
From all images acquired during end-expiration, one representative image per slice and per ECG class is selected:
- Spirometry file
- MRI image data
- Image sequences representing one full cardiac cycle per slice during end-expiration
These image sequences can subsequently be analyzed in Circle and compared with conventional cardiac MRI sequences.
- Enter the start and end time of rest and exercise phase:
hh:mm:ss(e.g.00:00:00) - Enter body weight (kg) and height (cm)
Example:60and180 - Click “Choose Spirofile and Start” and select the spirometry file
If the exact times are not known yet:
If the exact times are not known yet:
- Enter temporary (dummy) times and run the program
- Enter values 1–4 to select an ECG channel to inspect the spirometry signal
- Identify the correct timestamps within the displayed data
- Restart the program and enter the correct times
Click “Start Rest-Analysis” to begin the resting phase analysis.
For each signal:
- A new window opens showing the signal with automatically detected peaks
- Click “Remove Peaks” and remove incorrect peaks by clicking on the red markers
- Click “Add peaks manually” to add missing peaks by clicking into the plot
- Click “Save changes” to save the corrections and close the window
This procedure is repeated four times for:
- Respiratory volume
- O₂ volume fraction (%)
- CO₂ volume fraction (%)
- Respiratory flow
After the fourth window is closed, an Excel file is generated containing all parameters required for further processing.
Repeat the steps from 1.2 by clicking “Start Exercise-Analysis”.
- Select the ECG file and spirometry file
- Choose the ECG channel that provides the best visible timestamp markers
- Click Start
- A new window displaying the ECG signal will open
- Adjust the view using the sliders if necessary
- Activate “Activate Selecting Points”
- Click on the timestamp start in the ECG plot
- Click “Save points and next plot”
- The spirometry signal will be displayed
- Click on the corresponding timestamp start in the spirometry plot
- Click “Save points and next plot”
Spirometry and ECG signals are now plotted together:
- If the correlation is correct, click “Save data”
- If not, restart the program and repeat the procedure
-
Select the DICOM folder containing the real-time images
Expected folder structure: path/Dicom_translated/Echtzeit_Spiroergo_XXXX/date_of_measurement/realtime_images/ -
Select:
-
Slice number for ROI definition
-
timestamp.npy -
indices.npy -
Spirometry file
- Click “1. Plot complete data”
- Spirometry and respiratory belt signals are plotted together
- Visually assess whether a temporal shift is required
- Hover over the plot to read the x-coordinate (in milliseconds)
- Determine the required shift between signals
- Divide the time difference by 8 to convert to timestamp units
- Enter the calculated value below the slider
- Click “1. Plot complete data” again to verify
- Click “2. Look through slice”
- A window showing all images of the selected slice opens
- Click “Select ROI” and select the ROI in the correct order
- Click “Save Signalintensivity curve!”
The following curves are plotted:
- Signal intensity curve (ROI)
- Respiratory belt signal
- Spirometry signal
If necessary, repeat the shift adjustment using the new plot.
Shift direction:
- Move spirometry signal to the right → negative values
- Move spirometry signal to the left → positive values
- Main-path: output directory for processed images
- Dicom path: folder containing real-time DICOM images
- Spirofile: spirometry file
timestamp.npyindices.npy- RR interval (ms): e.g.
1000 - Mean tidal volume (L): value from Excel file generated in Step 1
- Threshold volume: Defines end-expiration condition
- Manuel shift (timestamps): fine-tuning shift from Step 3
- Number of ECG-Phases: number of ECG phases per slice
- Click Start to execute the program
- The output consists of filtered DICOM image sequences categorized by ECG phase and end-expiration
During exercise, breath-hold commands are not practical.
The implemented filtering approach enables the generation of image data comparable to conventional cardiac MRI acquisitions, which are typically performed during breath-hold at end-expiration.
- The software is intended for research use only.
- Manual time markers are essential for accurate correlation.
- The quality of the respiratory belt signal directly affects the fine-tuning process.
Developed as part of a scientific project on real-time cardiac MRI under physical exercise conditions.