Skip to content

Commit

Permalink
Merge pull request #13 from OmooLab/feature/dev
Browse files Browse the repository at this point in the history
Feature/dev
  • Loading branch information
icrdr authored May 14, 2024
2 parents 2c80c9e + d380cf7 commit e929013
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 33 deletions.
8 changes: 7 additions & 1 deletion bioxelnodes/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def rgb2gray(image):

return sitk.Cast(I, sitk.sitkFloat32)

def x2gray(image):
return sitk.VectorIndexSelectionCast(image, 0, sitk.sitkUInt16)

class ImportVolumeDataDialog(bpy.types.Operator):
bl_idname = "bioxelnodes.import_volume_data_dialog"
Expand Down Expand Up @@ -225,7 +227,11 @@ def execute(self, context):
bioxel_size, image_shape, orig_spacing)

if self.read_as == "labels":
image = sitk.Cast(image, sitk.sitkUInt16)
if "vector" in image.GetPixelIDTypeAsString():
print("Convet to Grayscale...")
image = x2gray(image)
else:
image = sitk.Cast(image, sitk.sitkUInt16)
default_value = 0
elif self.read_as == "scalar":
if "vector" in image.GetPixelIDTypeAsString():
Expand Down
Binary file added docs/assets/as-labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/as-scalar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added docs/assets/before-sharing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/dependency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
Binary file added docs/assets/import-dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/import-others.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/assets/import_dialog.png
Binary file not shown.
Binary file added docs/assets/resample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added docs/assets/to-mesh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 43 additions & 3 deletions docs/features.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
# Import Volume Data
# Features & Options

# Convert to Mesh
## Import Volume Data as Biovels

# Export Volume Data
File > Import > Volume Data as Biovels

### Resample

![alt text](assets/resample.png)

Sometimes the original data is too big, or the spacing in the original data is not reasonable, you can modify the `Bioxel Size` and `Original Spacing` to adjust the Shape of the Bixoels.

A bioxel is like a pixel, the larger the `Bioxel Size`, the lower the resolution of the image, Original Spacing will be read from the original data record, but sometimes the image doesn't have original spacing, you may need to input it manually to get the correct shape.

### Read as

#### as Scalar

![alt text](assets/as-scalar.png)

In some cases the environment value is higher than the value of the target object, you can check `Invert Scalar` to adjust the value for better result.

#### as Labels

![alt text](assets/as-labels.png)

Many AI segmentation task datasets, provide segmentation data, which are often an integer value representing a layer of segmentation labels. You can set the Label Index to determine exactly which labels to load.

#### as Vector (Not implemented)

#### as Color (Not implemented)

### Others

![alt text](assets/import-others.png)

## Convert Bioxels to Mesh

In 3D view, select bioxels and right-click, Bioxels > Bioxels To Mesh

![alt text](assets/to-mesh.png)

## Export Biovels as VDB

File > Export > Biovels as VDB
57 changes: 30 additions & 27 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,62 @@

Currently only support Blender 4.0 or above, make sure you have the correct version of Blender.

### Add-on Installation
## Add-on Installation

Download the latest version https://github.com/OmooLab/BioxelNodes/releases/latest
In Blender, `Edit - Preferences - Add-ons - Install`, select the `BioxelNodes_{version}.zip` you just downloaded.
In Blender, Edit > Preferences > Add-ons > Install, select the `BioxelNodes_{version}.zip` you just downloaded.

### Dependency Installation

The add-on requires a third-party python dependency called SimpleITK, click the Install SimpleITK button below to install the dependency. After clicking, blender may get stuck, it is downloading and installing, just wait for a moment. After the Installation, **restart blender once**.
The add-on requires a third-party python dependency called SimpleITK, click `Install SimpleITK` button below to install the dependency. After clicking, blender may get stuck, it is downloading and installing, just wait for a moment. After that, click `Reboot Blender` button.

![dependency](assets/dependency.png)

This step may have failed due to network factors, just click "Set PyPI Mirror" to change the mirror.

### Basic Usage
## Prepare Your Data

First you need to have your volumetric data ready. If not, you can access open research data from list below:

First you need to have your volumetric data ready. If not, you can access open research data from [Dryad](https://datadryad.org) (Dryad publishes data exclusively under a [Creative Commons Public Domain License](https://creativecommons.org/public-domain/cc0/))
| Source | Object |
| ------------------------------------------------------------------------------------ | ------------------ |
| [Dryad](https://datadryad.org) | Open Research Data |
| [OpenOrganelle](https://openorganelle.janelia.org/datasets) | Cells |
| [Embodi3D](https://www.embodi3d.com/files/category/37-medical-scans/) | Medical Images |
| [Github](https://github.com/sfikas/medical-imaging-datasets) | Medical Images |
| [NIHR](https://nhsx.github.io/open-source-imaging-data-sets/) | Medical Images |
| [Medical Segmentation Decathlon](http://medicaldecathlon.com/) | Medical Images |
| [Allen Cell Explorer](https://www.allencell.org/3d-cell-viewer.html) | Cells |
| [Visible Human Project](https://www.nlm.nih.gov/research/visible/visible_human.html) | Medical Images |

Note: Make sure one folder contains only one sequence, multiple sequences need to be manually split into different folders first.
## Import Volume Data

In Blender, `File - Import - Volume Data as Bioxels`, select **one** of the .dcm files and click on "Volume Data as Bioxels" (you can also drag one of the .dcm files directly into the 3D viewport to trigger the import, but this is limited to .dcm format files)
File > Import > Volume Data as Bioxels, select **one** of the .dcm files and click on "Volume Data as Bioxels" (you can also drag one of the .dcm files directly into the 3D viewport to trigger the import)

![importing](assets/importing.png)

It may take a while to read data. After finishing reading, it will pop up a dialog box

![import dialog](assets/import_dialog.png)
![import dialog](assets/import-dialog.png)

Ignore the options, just click OK!

After importing, the necessary nodes are automatically added, the reconstruction and shader are created, and then turned on the cycles rendering to directly see the result.
After importing, the necessary nodes are automatically added, the reconstruction and shader are created. Click select Bioxels Object, and open the Geometry Nodes panel, change the "Threshold" in segment node.

![result](assets/result.png)
![segment node](assets/segment-node.png)

Click select Bioxels Object, and open the Geometry Nodes panel to see the following node graph:
and then turned on the cycles rendering to directly see the result.

![segment node](assets/segment_node.png)
![result](assets/result.png)

You can change the "Threshold" to modify the reconstruction model, or change the "Color", "Density" to modify the shader effect. All the parameters are straightforward, you can understand them by changing the values.

The node, that named "Segment", is a preset node that combines the steps of 3D reconstruction process and shading process. In general, you need to add one of the segmentation node to reconstruction first, and followed by one of the shader node to set the shader. As you can see in the following figure:

![general graph](assets/general_graph.png)

Currently there are 3 types of nodes

- Segmentation nodes, responsible for splitting the volume into a reconstructed model (we call them "Segment").
- Shader nodes, responsible for giving shader to the Segment.
- Slicer nodes, responsible for partially cutting the Segment.
## Share Your File

For example:
The VDB cache and the Bioxel nodes are not reachable to computers if you don't save them. If you need to give your blender file to someone else, you will need to perform the following steps:

![general graph example](assets/general_graph_example.png)
1. Save your blender file
2. Click Scene > Bioxels > Save All Bioxels in the Properties panel.
3. Click Scene > Custom Nodes > Save All Custom Nodes under the Properties panel.

You can add a "Bake" node between segmentation node and shader node, if the reconstruction process consumes too much computing time. But be sure, you are selecting the volume object, not the container object.
![before sharin](assets/before-sharing.png)

![bake node](assets/bake_node.png)
After that, both the VDB cache and the Bioxel nodes are stored in relative locations. When you share a file with someone, pack the entire directory so that the resources are not lost. The other person will be able to load correctly, regardless of whether they have BioxelNodes installed.
2 changes: 1 addition & 1 deletion docs/misc.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Future Features

- Support more volumetric data formats (.nii, .map, .txm...)
- Support more volumetric data formats (.map, .txm...)
- Generate sections
- More segmentation methods, e.g. AI segmentation.
- Even better shader for volumetric rendering
Expand Down
19 changes: 19 additions & 0 deletions docs/nodes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Geometry Nodes

The node, that named "Segment", is a preset node that combines the steps of 3D reconstruction process and shading process. In general, you need to add one of the segmentation node to reconstruction first, and followed by one of the shader node to set the shader. As you can see in the following figure:

![general graph](assets/general-graph.png)

Currently there are 3 types of nodes

- Segmentation nodes, responsible for splitting the volume into a reconstructed model (we call them "Segment").
- Shader nodes, responsible for giving shader to the Segment.
- Slicer nodes, responsible for partially cutting the Segment.

For example:

![general graph example](assets/general-graph-example.png)

You can add a "Bake" node between segmentation node and shader node, if the reconstruction process consumes too much computing time. But be sure, you are selecting the volume object, not the container object.

![bake node](assets/bake-node.png)
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nav:
- BioxelNodes:
- index.md
- Getting Started: getting-started.md
- Features: features.md
- Features & Options: features.md
- Geometry Nodes: nodes.md
- Future Features: misc.md

Expand Down

0 comments on commit e929013

Please sign in to comment.