Skip to content

Commit

Permalink
plot3d
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsenhariri committed Oct 28, 2023
1 parent 52f5710 commit 0ad19fb
Show file tree
Hide file tree
Showing 24 changed files with 259 additions and 1,550 deletions.
106 changes: 100 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,107 @@ If your OS doesn't have a backend GUI to render Matplotlib, you need to install



plots
## Plotting

1. multiple 2D images
just images, not mask or contour

2. multiple 2D images and masks- layered plot
### 3D plots
1. Basic Usage:
Plot a single image without any mask:

```python
viz.plot3d('path/to/image.nii')
```

2. Plotting Multiple Images:
If you have multiple images to plot:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
viz.plot3d(images)
```

3. Displaying Images with Masks:
To visualize images along with their corresponding masks:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
viz.plot3d(images, masks=masks)
```

4. Using Custom Colors:
To specify custom colors for the masks:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
colors = ['red', 'green']
viz.plot3d(images, masks=masks, colors=colors)
```

5. Displaying Titles:
For adding titles to the plotted images:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
colors = ['red', 'green']
titles = ['Image 1', 'Image 2']
viz.plot3d(images, masks=masks, colors=colors, titles=titles)
```

6. Specifying Display Plane:
You can visualize the images in different planes:

```python
viz.plot3d('path/to/image.nii', plane="sagittal")
```

7. Saving the Plot:
To save the plot to a specified location:

```python
viz.plot3d('path/to/image.nii', save_path='path/to/save_directory/')
```

8. Specifying Rows and Columns:
To organize multiple images into a specific number of rows and columns:

Specify Rows:
```python
images = ['path/to/image1.nii', 'path/to/image2.nii', 'path/to/image3.nii']
viz.plot3d(images, rows=2)
```

This will generate a 2x2 grid, with the third image in the first cell of the second row.

Specify Columns:
```python
images = ['path/to/image1.nii', 'path/to/image2.nii', 'path/to/image3.nii']
viz.plot3d(images, columns=2)
```

This will also generate a 2x2 grid similar to the previous example.

Specifying Both Rows and Columns:
For more control, you can specify both rows and columns:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii', 'path/to/image3.nii', 'path/to/image4.nii']
viz.plot3d(images, rows=2, columns=2)
```
This will arrange the images in a 2x2 grid with each cell having one image.

9. Combining Multiple Options:
You can also combine multiple options for a comprehensive view:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
titles = ["First Image with Mask", "Second Image with Mask"]
mask_colors = ["#FF0000", "#00FF00"]
viz.plot3d(images, masks=masks, mask_colors=mask_colors, titles=titles, save_path='path/to/save_directory/')
```


## 2D plots
Expand Down Expand Up @@ -118,7 +212,7 @@ inpute:
- an array of images

```python
plot3d.images()
viz.plot3d.images()
```

2. 3D images and masks- layered plot with slider
Expand All @@ -128,7 +222,7 @@ inpute:
- an array of masks

```python
plot3d.images_masks()
viz.plot3d.images_masks()
```


Expand Down
102 changes: 102 additions & 0 deletions api/plot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Plotting

## 3D plots
1. Basic Usage:
Plot a single image without any mask:

```python
viz.plot3d('path/to/image.nii')
```

2. Plotting Multiple Images:
If you have multiple images to plot:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
viz.plot3d(images)
```

3. Displaying Images with Masks:
To visualize images along with their corresponding masks:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
viz.plot3d(images, masks=masks)
```

4. Using Custom Colors:
To specify custom colors for the masks:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
colors = ['red', 'green']
viz.plot3d(images, masks=masks, colors=colors)
```

5. Displaying Titles:
For adding titles to the plotted images:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
colors = ['red', 'green']
titles = ['Image 1', 'Image 2']
viz.plot3d(images, masks=masks, colors=colors, titles=titles)
```

6. Specifying Display Plane:
You can visualize the images in different planes:

```python
viz.plot3d('path/to/image.nii', plane="sagittal")
```

7. Saving the Plot:
To save the plot to a specified location:

```python
viz.plot3d('path/to/image.nii', save_path='path/to/save_directory/')
```

8. Specifying Rows and Columns:
To organize multiple images into a specific number of rows and columns:

Specify Rows:
```python
images = ['path/to/image1.nii', 'path/to/image2.nii', 'path/to/image3.nii']
viz.plot3d(images, rows=2)
```

This will generate a 2x2 grid, with the third image in the first cell of the second row.

Specify Columns:
```python
images = ['path/to/image1.nii', 'path/to/image2.nii', 'path/to/image3.nii']
viz.plot3d(images, columns=2)
```

This will also generate a 2x2 grid similar to the previous example.

Specifying Both Rows and Columns:
For more control, you can specify both rows and columns:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii', 'path/to/image3.nii', 'path/to/image4.nii']
viz.plot3d(images, rows=2, columns=2)
```
This will arrange the images in a 2x2 grid with each cell having one image.

9. Combining Multiple Options:
You can also combine multiple options for a comprehensive view:

```python
images = ['path/to/image1.nii', 'path/to/image2.nii']
masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
titles = ["First Image with Mask", "Second Image with Mask"]
mask_colors = ["#FF0000", "#00FF00"]
viz.plot3d(images, masks=masks, mask_colors=mask_colors, titles=titles, save_path='path/to/save_directory/')
```


7 changes: 0 additions & 7 deletions api/plot/plot2Dfrom3DMostVlueMask.py

This file was deleted.

35 changes: 0 additions & 35 deletions api/plot/plot2d_images.py

This file was deleted.

3 changes: 0 additions & 3 deletions api/plot/plot2d_layered_image_mask.py

This file was deleted.

26 changes: 0 additions & 26 deletions api/plot/plot2d_masks.py

This file was deleted.

52 changes: 52 additions & 0 deletions api/plot/plot3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import medviz as viz

viz.plot3d("/storage/sync/git/mohsen/medviz/test_local/dataset/plots/1-1.nii")

viz.plot3d(
images=[
"/storage/sync/git/mohsen/medviz/test_local/dataset/plots/1-1.nii",
"/storage/sync/git/mohsen/medviz/test_local/dataset/plots/rt.dcm",
],
masks=[
"/storage/sync/git/mohsen/medviz/test_local/dataset/plots/1-1-label.nii",
None,
],
rows=1,
columns=2,
)

viz.plot3d(
images=[
"/storage/sync/git/mohsen/medviz/test_local/dataset/plots/1-1.nii",
"/storage/sync/git/mohsen/medviz/test_local/dataset/plots/rt.dcm",
],
titles=["First ", "Second"],
rows=1,
columns=2,
)

viz.plot3d(
images=[
"/storage/sync/git/mohsen/medviz/test_local/dataset/plots/349090_CTE_AX_Res.nii",
]
)

viz.plot3d(
images="/storage/sync/git/mohsen/medviz/test_local/dataset/plots/1-1.nii",
masks="/storage/sync/git/mohsen/medviz/test_local/dataset/plots/1-1-label.nii",
plane="coronal",
)

viz.plot3d(
images=[
"/storage/sync/git/mohsen/medviz/test_local/dataset/plots/1-1.nii",
"/storage/sync/git/mohsen/medviz/test_local/dataset/plots/rt.dcm",
],
masks=[
"/storage/sync/git/mohsen/medviz/test_local/dataset/plots/1-1-label.nii",
None,
],
titles=["Image 1", "Image 2"],
rows=1,
columns=2,
)
13 changes: 0 additions & 13 deletions api/plot/plot3d_images.py

This file was deleted.

19 changes: 0 additions & 19 deletions api/plot/plot3d_masks.py

This file was deleted.

Loading

0 comments on commit 0ad19fb

Please sign in to comment.