|
1 | | -## Image Orientation Guidelines |
2 | | - |
3 | | -MedImages.jl is optimized for images in **LPS (Left-Posterior-Superior)** orientation for consistent processing and analysis. If your medical images are in a different orientation, we recommend converting them to LPS before using MedImages.jl. |
4 | | - |
5 | | -### Quick Orientation Converter |
6 | | - |
7 | | -To help you convert your images to LPS orientation, we provide a convenient script that handles both NIfTI files and DICOM series. |
8 | | - |
9 | | -#### Setup Instructions |
10 | | - |
11 | | -**Note:** Ensure you are not in a virtual environment and have Python 3 installed on your system. |
12 | | - |
13 | | -##### For Windows and macOS |
14 | | -```julia |
15 | | -using Pkg |
16 | | -Pkg.add("PyCall") |
17 | | -Pkg.add("ArgParse") |
18 | | - |
19 | | -using Downloads |
20 | | -Downloads.download("https://gist.githubusercontent.com/divital-coder/6d2dc6868ee5f8427cf719f54213227d/raw/a3b50aa734c662e0a4e57be6e29f69fc22921d03/reorient_to_lps.jl", "./reorient_to_lps.jl") |
21 | | -python_path = Sys.which("python") |
22 | | -if isnothing(python_path) |
23 | | - error("Python not found in PATH, please install python or add it to your PATH") |
24 | | -else |
25 | | - ENV["PYTHON"] = python_path |
26 | | -end |
27 | | -run(`pip install SimpleITK`) |
28 | | -Pkg.build("PyCall") |
29 | | -``` |
30 | | - |
31 | | -##### For Arch Linux |
32 | | -```julia |
33 | | -using Pkg |
34 | | -Pkg.add("PyCall") |
35 | | -Pkg.add("ArgParse") |
36 | | - |
37 | | -using Downloads |
38 | | -Downloads.download("https://gist.githubusercontent.com/divital-coder/6d2dc6868ee5f8427cf719f54213227d/raw/a3b50aa734c662e0a4e57be6e29f69fc22921d03/reorient_to_lps.jl", "./reorient_to_lps.jl") |
39 | | -python_path = Sys.which("python") |
40 | | -if isnothing(python_path) |
41 | | - error("Python not found in PATH, please install python or add it to your PATH") |
42 | | -else |
43 | | - ENV["PYTHON"] = python_path |
44 | | -end |
45 | | -run(`yay -S python-simpleitk`) |
46 | | -Pkg.build("PyCall") |
47 | | -``` |
48 | | - |
49 | | -#### Usage Examples |
50 | | - |
51 | | -##### Convert a NIfTI File |
52 | | -```bash |
53 | | -julia reorient_to_lps.jl input_image.nii.gz output_lps.nii.gz |
54 | | -``` |
55 | | - |
56 | | -##### Convert a DICOM Series |
57 | | -```bash |
58 | | -julia reorient_to_lps.jl /path/to/dicom/folder/ output_lps.nii.gz |
59 | | -``` |
60 | | - |
61 | | -##### Additional Options |
62 | | -```bash |
63 | | -# Enable verbose output |
64 | | -julia reorient_to_lps.jl brain.nii.gz brain_lps.nii.gz --verbose |
65 | | - |
66 | | -# Force overwrite existing files |
67 | | -julia reorient_to_lps.jl brain.nii.gz brain_lps.nii.gz --force |
68 | | -``` |
69 | | - |
70 | | -### Converting Back to DICOM Format |
71 | | - |
72 | | -**Important:** The orientation converter outputs NIfTI files only. If you need your processed images back in DICOM format, you can use the [`ITKIOWrapper.jl`](https://github.com/JuliaHealth/ITKIOWrapper.jl) package for conversion. |
73 | | - |
74 | | -#### Installing ITKIOWrapper.jl |
75 | | - |
76 | | -```julia |
77 | | -using Pkg |
78 | | -Pkg.add("ITKIOWrapper") |
79 | | -``` |
80 | | - |
81 | | -#### Converting NIfTI to DICOM Series |
82 | | - |
83 | | -After processing your LPS-oriented NIfTI file with MedImages.jl, convert it back to DICOM: |
84 | | - |
85 | | -```julia |
86 | | -using ITKIOWrapper |
87 | | - |
88 | | -# Convert processed NIfTI back to DICOM series |
89 | | -# This creates a directory with DICOM files |
90 | | -dicom_nifti_conversion("processed_lps_image.nii.gz", "./output_dicom_series", true) |
91 | | -``` |
92 | | - |
93 | | -#### Complete Workflow Example |
94 | | - |
95 | | -Here's a typical workflow for DICOM users: |
96 | | - |
97 | | -```julia |
98 | | -using MedImages, ITKIOWrapper |
99 | | - |
100 | | -# 1. Convert original DICOM to LPS-oriented NIfTI (using the orientation script) |
101 | | -# julia reorient_to_lps.jl /path/to/original/dicom/ lps_oriented.nii.gz |
102 | | - |
103 | | -# 2. Process with MedImages.jl |
104 | | -medimage = MedImages.load_image("lps_oriented.nii.gz") |
105 | | -# ... perform your analysis and modifications ... |
106 | | - |
107 | | -# 3. Save processed image (if modified) |
108 | | -# save_image(modified_medimage, "processed_image.nii.gz") |
109 | | - |
110 | | -# 4. Convert back to DICOM series if needed |
111 | | -dicom_nifti_conversion("processed_image.nii.gz", "./final_dicom_series", true) |
112 | | -``` |
113 | | - |
114 | | -#### Advanced DICOM Conversion Options |
115 | | - |
116 | | -For more control over the DICOM output, you can also create images programmatically: |
117 | | - |
118 | | -```julia |
119 | | -using ITKIOWrapper |
120 | | - |
121 | | -# Load your processed NIfTI image |
122 | | -img = load_image("processed_lps_image.nii.gz") |
123 | | -metadata = load_spatial_metadata(img) |
124 | | -voxel_data = load_voxel_data(img, metadata) |
125 | | - |
126 | | -# Save as DICOM series with full control |
127 | | -save_image(voxel_data, metadata, "./custom_dicom_output", true) |
128 | | -``` |
129 | | - |
130 | | -### Summary |
131 | | - |
132 | | -1. **Input DICOM** → Convert to LPS NIfTI using the orientation script |
133 | | -2. **Process** → Use MedImages.jl for analysis and modifications |
134 | | -3. **Output DICOM** → Use ITKIOWrapper.jl to convert back to DICOM format |
135 | | - |
136 | | -Once your images are in LPS orientation, you can use them seamlessly with MedImages.jl for optimal performance and compatibility, and easily convert between NIfTI and DICOM formats as needed for your workflow. |
0 commit comments