Claude/cest parametric maps 011 c uq f5g293k w zt zi y ld2 pm#1
Open
chetz09 wants to merge 13 commits intocest-sources:masterfrom
Open
Claude/cest parametric maps 011 c uq f5g293k w zt zi y ld2 pm#1chetz09 wants to merge 13 commits intocest-sources:masterfrom
chetz09 wants to merge 13 commits intocest-sources:masterfrom
Conversation
…detection This commit adds a complete CEST analysis pipeline that automates the entire workflow for analyzing 24-tube CEST phantoms with multiple correction methods. New files: 1. phantom_CEST_analysis_B0corr.m - CEST analysis with B0 correction only - Automatic tube detection (24 tubes) using algorithm from phantom_t1.m - B0 field correction for frequency shifts - %CEST calculation (MTR asymmetry) for multiple offsets - Parametric map generation and visualization - CSV export of results 2. phantom_CEST_analysis_FULL.m - Complete analysis with T1/T2/B1/B0 corrections - All features from B0-only version - T1 relaxation correction - T2 relaxation correction - B1 inhomogeneity correction - Kex (exchange rate) estimation using simplified BM model - Comprehensive parametric maps including Kex maps - Enhanced CSV output with all correction parameters 3. CEST_ANALYSIS_GUIDE.md - Comprehensive user guide - Step-by-step instructions for both analysis scripts - Data organization guidelines - Output file descriptions - Troubleshooting tips - Expected CEST values reference table - Customization options 4. t2fitting_new.m - Compatibility wrapper for T2 fitting - Alias function for t2fitting.m - Required by phantom_T2.m Key Features: - Automatic detection of 24 tubes (no manual ROI drawing needed) - Circular ordering of tubes relative to phantom center - Support for multiple CEST offsets (1.9, 2.0, 3.25, 3.5, 4.3, 5.6 ppm) - Flexible correction options (B0 only or full T1/T2/B1/B0) - Comprehensive visualization with parametric maps and heatmaps - CSV export with tube labels and statistical measures - Compatible with existing BM_sim_fit framework Phantom Configuration (24 tubes): - Iopamidol: 20mM & 50mM at pH 6.2, 6.8, 7.4 (6 tubes) - Creatine: 20mM & 50mM at pH 6.2, 6.8, 7.4 (6 tubes) - Taurine: 20mM & 50mM at pH 6.2, 6.8, 7.4 (6 tubes) - PLL: 0.1% at pH 6.2, 6.8, 7.4 (3 tubes) - PBS: pH 6.2, 6.4, 6.8 (3 tubes) This pipeline significantly streamlines CEST phantom analysis by eliminating manual ROI drawing and providing comprehensive correction capabilities.
… WASSR B0 correction Key changes: 1. Replaced generic ppm offset prompts with predefined frequency offsets in Hz - WASSR images: indices 4-14 (11 images) with ±240 Hz range - CEST images: indices 15-63 (49 images) with ±896 Hz range - S0 reference image: index 2 - Automatic Hz to ppm conversion at 3T (127.7 MHz) 2. Added WASSR-based B0 field map calculation - Automatically calculates B0 map from WASSR data (water saturation shift) - Finds minimum signal in WASSR spectrum for each voxel - Applies Gaussian smoothing to reduce noise - Option to use WASSR, external B0 map, or skip B0 correction 3. Updated data loading workflow - Loads all 63 DICOM images (includes WASSR + CEST + S0) - Extracts WASSR volume for B0 calculation - Extracts CEST volume for Z-spectrum analysis - Uses predefined S0 image at index 2 for phantom detection 4. Fixed step numbering throughout both scripts - B0corr version: Steps 1-11 - FULL version: Steps 1-13 Files modified: - phantom_CEST_analysis_B0corr.m: Added WASSR B0 correction option - phantom_CEST_analysis_FULL.m: Added WASSR B0 correction with full T1/T2/B1 support These changes eliminate the need for manual ppm offset entry and leverage the WASSR data already present in the DICOM dataset for accurate B0 correction.
… offset field names MATLAB struct field names cannot contain periods (dots). Updated field name generation to replace decimal points with underscores. Changes: - Changed 'CEST_2.00ppm_mean' → 'CEST_2_00_ppm_mean' - Updated all field name references in: * Results structure initialization * Tube statistics extraction loop * Parametric map generation * Summary heatmap generation Applies to both: - phantom_CEST_analysis_B0corr.m - phantom_CEST_analysis_FULL.m This fixes the error: Invalid field name: 'CEST_2.00ppm_mean'
Replaces Lorentzian fitting approach with Bloch-McConnell simulation for
more accurate CEST parameter extraction.
New Files:
1. phantom_CEST_BMC_analysis.m
- BMC-based CEST analysis for all 24 tubes
- WASSR-based B0 correction (voxel-wise)
- Automatic tube detection with numbering verification
- Kex (exchange rate) extraction from CEST effects
- Concentration estimation per tube
- Chemical-specific %CEST measurements (1.9, 3.5, 4.3 ppm)
- Parametric maps: Kex, %CEST at multiple offsets, B0
- Pauses to verify tube numbering matches user's phantom layout
2. reorder_tubes_to_match_layout.m
- Interactive helper for manual tube reordering
- Matches automatic detection to user-specific phantom layout
- Supports three input methods: interactive, array, or file
- Visualizes before/after reordering
- Saves corrected tube masks
3. BMC_ANALYSIS_README.md
- Complete usage guide
- Tube layout reference table (tubes 1-24)
- Output file descriptions
- Troubleshooting tips
- Kex calculation methodology
- Advanced usage with multiZfit integration
Key Differences from Lorentzian Approach:
❌ Removed: Multi-pool Lorentzian fitting, single-tube analysis
✅ Added: BMC-based Kex extraction, 24-tube batch processing,
tube numbering verification, concentration estimation
Tube Layout (from user's shots.png):
- Tubes 1-3: Iopamidol 20mM pH 6.2, 6.8, 7.4
- Tubes 4-6: Iopamidol 50mM pH 6.2, 6.8, 7.4
- Tubes 7-9: Creatine 20mM pH 6.2, 6.8, 7.4
- Tubes 10-12: Creatine 50mM pH 6.2, 6.8, 7.4
- Tubes 13-15: Taurine 20mM pH 6.2, 6.8, 7.4
- Tubes 16-18: Taurine 50mM pH 6.2, 6.8, 7.4
- Tubes 19-21: PLL 0.1% pH 6.2, 6.8, 7.4
- Tubes 22-24: PBS (blank) pH 6.2, 6.8, 7.4
Output Files:
- BMC_CEST_results.csv: Kex, concentration, %CEST per tube
- BMC_parametric_maps.png: All maps in one figure
- DETECTED_tube_numbering.png: Verification image
- BMC_tubeMasks.mat: Reusable tube masks
- BMC_CEST_workspace.mat: Complete workspace
Changed phantom_CEST_BMC_analysis.m to use manual ROI drawing instead of automatic tube detection. This ensures exact tube numbering matches user's phantom layout (shots.png). Changes: - Replaced Steps 4-5 (automatic detection) with Step 4 (manual ROI drawing) - Interactive ROI drawing for all 24 tubes in sequential order - Three drawing methods: circle, polygon, or freehand - Real-time preview with previously drawn tubes displayed - Shows tube number and chemical name for each ROI - Auto-saves backup every 6 tubes - Validation checks for ROI size - Quality checks for overlaps - Generates overview image (MANUAL_tube_numbering.png) Updated BMC_ANALYSIS_README.md: - Updated Quick Start Guide with manual ROI workflow - Revised troubleshooting section for manual drawing issues - Noted that reorder_tubes_to_match_layout.m is no longer needed - Added step-by-step ROI drawing instructions Benefits: - Guaranteed correct tube numbering (user controls order) - No need for tube reordering scripts - More accurate ROI placement - User can reference shots.png while drawing - Progress saves prevent data loss
Added Step 4 to detect phantom outline before manual ROI drawing. The phantom outline is needed in Step 6 to mask B0 correction to phantom region only (avoids correcting background noise). Changes: - Added Step 4: Detect Phantom Outline * Automatic detection of outer phantom boundary * Uses Otsu thresholding and morphological operations * Visualizes detected outline * Used only for masking, not for tube detection - Updated step numbering: * Step 4: Detect Phantom Outline (NEW) * Step 5: Manual ROI Drawing (was Step 4) * Step 6: Apply B0 Correction (unchanged, now has phantom_outline) * Steps 7-9: Unchanged This fixes the error: 'Undefined function or variable phantom_outline' in Step 6 B0 correction loop.
Modified Step 5 to check for existing BMC_tubeMasks.mat file and load it automatically, skipping the manual ROI drawing step. Changes: - Step 5 now titled: "Load or Draw Tube Masks" - Checks if BMC_tubeMasks.mat exists in current directory - If found, prompts user to choose: * "Load existing masks" - loads saved masks, skips drawing * "Redraw all tubes" - proceeds with manual drawing - If not found, proceeds directly to manual drawing Loading existing masks: - Loads tubeMasks, tube_labels, tube_info from .mat file - Validates dimensions match current DICOM data - Warns if number of tubes != 24 - Visualizes loaded masks with tube numbers - Saves verification image: LOADED_tube_numbering.png Benefits: - Saves time on repeated analyses with same phantom - No need to redraw ROIs for each run - Maintains consistency across multiple analyses - Still allows redrawing if needed User workflow: 1. First run: Draw all 24 tubes manually (saves BMC_tubeMasks.mat) 2. Subsequent runs: Script finds saved file, loads automatically 3. Option to redraw if phantom position changed
…tion - Added CEST measurements at 5.5 ppm (Iopamidol second peak) - Added CEST measurements at 2.7 ppm (PLL amine protons) - Added CEST measurements at 2.8 ppm (Taurine) - Generated Z-spectra plots for all 24 tubes with measured points - Generated MTR asymmetry plots for all 24 tubes - Updated parametric maps to include all 6 CEST offsets (1.9, 2.7, 2.8, 3.5, 4.3, 5.5 ppm) - Expanded results structure to include new CEST offset measurements - Enhanced CSV export with all new offset columns - Added chemical shift markers to Z-spectra and MTRasym plots - Saved Z-spectra and MTRasym data in workspace for further analysis
New scripts:
1. verify_CEST_offsets_from_DICOM.m
- Extracts frequency offsets from GE 3T scanner DICOM headers
- Attempts multiple methods to find offset information (standard tags, private tags, protocol names)
- Classifies images as WASSR vs CEST based on offset magnitude
- Generates visualization and exports suggested MATLAB code arrays
- Exports detailed CSV with all extracted offsets
2. compare_Zspec_fitting_methods.m
- Compares 6 different Z-spectra fitting approaches:
* Spline interpolation (baseline)
* Single Lorentzian fit
* Multi-peak Lorentzian (2, 3, 4 peaks)
* Polynomial baseline + Multi-Lorentzian
- Calculates goodness-of-fit metrics (R², RMSE, AIC)
- Generates side-by-side comparison plots
- Creates heatmap of fitting quality metrics
- Recommends best fitting method based on statistical criteria
- Exports summary statistics and full results
These tools help verify acquisition parameters and select optimal
fitting methods for accurate CEST quantification.
New script: validate_current_offsets.m - Validates current offset arrays by checking physical features - Tests if water saturation appears at 0 ppm (WASSR validation) - Checks Z-spectrum symmetry (CEST validation) - Detects CEST peaks and verifies positions - Provides visual validation with 6-panel diagnostic plot - Exports validation report with pass/fail status - Suggests offset corrections if errors detected This is more reliable than DICOM header extraction for GE scanners, where offset information is often in proprietary private tags. Addresses issue where verify_CEST_offsets_from_DICOM.m showed incorrect 127 Hz for all offsets due to GE private tag format.
Updated validate_current_offsets.m to include the corrected offset arrays (+48 Hz shift applied) so users can see what the corrected values should be after running validation. Note: Main analysis scripts NOT updated yet - user will apply corrections manually when ready.
New diagnostic script: diagnose_CEST_structure.m - Interactive tool to determine correct DICOM file structure - Identifies S0, WASSR, and CEST image indices - Counts actual number of images in each category - Generates recommended configuration with correct array sizes - Prevents "array bounds exceeded" errors by ensuring offset arrays match actual number of images - Creates visual diagram of image ordering - Exports configuration file for easy copy-paste This addresses the common error where users have mismatched offset array lengths vs actual image counts, causing index out of bounds errors. Example fix: If user has 52 CEST images but 54 offset values, script identifies the mismatch and provides corrected arrays.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.