osbm commited on
Commit
50e082d
β€’
1 Parent(s): 44af5b8

add script

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. README.md +1 -1
  3. app.py +58 -0
  4. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .venv
README.md CHANGED
@@ -3,7 +3,7 @@ title: Kspace Reconstruction Masks
3
  emoji: πŸ†
4
  colorFrom: red
5
  colorTo: gray
6
- sdk: streamlit
7
  sdk_version: 1.36.0
8
  app_file: app.py
9
  pinned: false
 
3
  emoji: πŸ†
4
  colorFrom: red
5
  colorTo: gray
6
+ sdk: gradio
7
  sdk_version: 1.36.0
8
  app_file: app.py
9
  pinned: false
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from fastmri.data.subsample import create_mask_for_mask_type
4
+ from fastmri.data.transforms import apply_mask, to_tensor, center_crop
5
+ from pytorch_msssim import ssim
6
+
7
+
8
+
9
+ # st.title('FastMRI Kspace Reconstruction Masks')
10
+ # st.write('This app allows you to visualize the masks and their effects on the kspace data.')
11
+
12
+
13
+ def main_func(
14
+ mask_name: str,
15
+ mask_center_fractions: int,
16
+ accelerations: int,
17
+ seed: int,
18
+ input_image: str,
19
+ ):
20
+
21
+ file_dict = {
22
+ "knee 1": "knee_singlecoil_train/file1000002.h5",
23
+ "knee 2": "knee_singlecoil_train/file1000003.h5",
24
+ "brain 1": "brain_axial_train/file1000002.h5",
25
+ "prostate 1": "prostate_t1_tse_train/file1000002.h5",
26
+ "prostate 2": "prostate_t2_tse_train/file1000002.h5",
27
+ }
28
+ input_file = file_dict[input_image]
29
+
30
+ mask_func = create_mask_for_mask_type(
31
+ mask_name, center_fractions=[mask_center_fractions], accelerations=[accelerations]
32
+ )
33
+ mask =
34
+ masked_kspace, mask = mask(input_image, return_mask=True)
35
+ return masked_kspace, mask
36
+
37
+ demo = gr.Interface(
38
+ fn=main_func,
39
+ inputs=[
40
+ gr.inputs.Radio(['random', 'equispaced'], label="Mask Type"),
41
+ gr.inputs.Slider(minimum=0.04, maximum=0.4, default=0.08, label="Center Fraction"),
42
+ gr.inputs.Number(default=4, label="Acceleration"),
43
+ gr.inputs.Number(default=0, label="Seed"),
44
+ gr.inputs.Radio(["knee 1", "knee 2", "brain 1", "prostate 1", "prostate 2"], label="Input Image")
45
+ ],
46
+ outputs=[
47
+ gr.outputs.Image(type="mask", label="Mask"),
48
+ gr.outputs.Image(type="kspace", label="Masked Kspace"),
49
+ gr.outputs.Image(type="kspace", label="Reconstructed Image"),
50
+ gr.outputs.Image(type="kspace", label="Original Image"),
51
+
52
+ gr.outputs.Dataframe()
53
+ ],
54
+ title="FastMRI Kspace Reconstruction Masks",
55
+ description="This app allows you to visualize the masks and their effects on the kspace data."
56
+ )
57
+
58
+ demo.launch()
requirements.txt CHANGED
@@ -1 +1,5 @@
1
  fastmri
 
 
 
 
 
1
  fastmri
2
+ scikit-image
3
+ pandas
4
+ numpy
5
+ torch