Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 3D_UNet
  • 3d_watershed
  • conv_zarr_tiff_folders
  • convert_tiff_folders
  • layered_surface_segmentation
  • main
  • memmap_txrm
  • notebook_update
  • notebooks
  • notebooksv1
  • optimize_scaleZYXdask
  • save_files_function
  • scaleZYX_mean
  • test
  • threshold-exploration
  • tr_val_te_splits
  • v0.2.0
  • v0.3.0
  • v0.3.1
  • v0.3.2
  • v0.3.3
  • v0.3.9
  • v0.4.0
  • v0.4.1
24 results

Target

Select target project
  • QIM/tools/qim3d
1 result
Select Git revision
  • 3D_UNet
  • 3d_watershed
  • conv_zarr_tiff_folders
  • convert_tiff_folders
  • layered_surface_segmentation
  • main
  • memmap_txrm
  • notebook_update
  • notebooks
  • notebooksv1
  • optimize_scaleZYXdask
  • save_files_function
  • scaleZYX_mean
  • test
  • threshold-exploration
  • tr_val_te_splits
  • v0.2.0
  • v0.3.0
  • v0.3.1
  • v0.3.2
  • v0.3.3
  • v0.3.9
  • v0.4.0
  • v0.4.1
24 results
Show changes

Commits on Source 8

Showing
with 266 additions and 131 deletions
recursive-include qim3d/img_examples *
recursive-include qim3d/examples *
recursive-include qim3d/css *
# QIM3D (Quantitative Imaging in 3D)
# Qim3D (Quantitative Imaging in 3D)
The `qim3d` library is designed to make it easier to work with 3D imaging data in Python. It offers a range of features, including data loading and manipulation, image processing and filtering, visualization of 3D data, and analysis of imaging results.
The `qim3d` (kɪm θriː diː) library is designed to make it easier to work with 3D imaging data in Python. It offers a range of features, including data loading and manipulation, image processing and filtering, visualization of 3D data, and analysis of imaging results.
You can easily load and process 3D image data from various file formats, apply filters and transformations to the data, visualize the results using interactive plots and 3D rendering, and perform quantitative analysis on the images.
......
File added
docs/assets/screenshots/Troubleshooting-Windows_build_tools.png

55 KiB

# ![qim3d logo](assets/qim3d-logo.svg){ width="256" }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<audio id="audio" src="assets/qim3d.mp3"></audio>
<script>
document.addEventListener("DOMContentLoaded", function() {
const audio = document.getElementById("audio");
const playButton = document.getElementById("playButton");
playButton.addEventListener("click", function() {
const icon = playButton.querySelector("i");
if (audio.paused) {
audio.play();
icon.classList.remove("fa-circle-play");
icon.classList.add("fa-circle-pause");
} else {
audio.pause();
icon.classList.remove("fa-circle-pause");
icon.classList.add("fa-circle-play");
}
});
audio.addEventListener("ended", function() {
const icon = playButton.querySelector("i");
icon.classList.remove("fa-circle-pause");
icon.classList.add("fa-circle-play");
});
});
</script>
# ![qim3d logo](assets/qim3d-logo.svg){ width="25%" }
[![PyPI version](https://badge.fury.io/py/qim3d.svg)](https://badge.fury.io/py/qim3d)
[![Downloads](https://static.pepy.tech/badge/qim3d)](https://pepy.tech/project/qim3d)
The **`qim3d`** (kɪm θriː diː <button id="playButton"><i class="fa-regular fa-circle-play"></i></button>) library is designed for **Quantitative Imaging in 3D** using Python. It offers a range of features, including data loading and manipulation, image processing and filtering, data visualization, and analysis of imaging results.
The `qim3d` library is designed to make it easier to work with 3D imaging data in Python. It offers a range of features, including data loading and manipulation, image processing and filtering, visualization of 3D data, and analysis of imaging results.
You can easily load and process 3D image data from various file formats, apply filters and transformations to the data, visualize the results using interactive plots and 3D rendering, and perform quantitative analysis on the images.
You can easily load and process 3D image data from various file formats, apply filters and transformations to the data, visualize the results using interactive plots and 3D volumetric rendering.
Whether you are working with medical imaging data, materials science data, or any other type of 3D imaging data, `qim3d` provides a convenient and powerful set of tools to help you analyze and understand your data.
!!! Example
!!! Example "Interactive volume slicer"
```python
import qim3d
import qim3d.processing.filters as filters
# Get data
vol = qim3d.examples.fly_150x256x256
vol = qim3d.examples.bone_128x128x128
qim3d.viz.slicer(vol)
```
![viz slicer](assets/screenshots/viz-slicer.gif)
# Show original
qim3d.viz.slices(vol, show=True)
!!! Example "Synthetic data generation"
```python
import qim3d
# Create filter pipeline
pipeline = filters.Pipeline(
filters.Median(size=5),
filters.Gaussian(sigma=3))
# Generate synthetic collection of blobs
num_objects = 15
synthetic_collection, labels = qim3d.generate.collection(num_objects = num_objects)
# Apply pipeline
filtered_vol = pipeline(vol)
# Visualize synthetic collection
qim3d.viz.vol(synthetic_collection)
```
<iframe src="https://platform.qim.dk/k3d/synthetic_collection_default.html" width="100%" height="500" frameborder="0"></iframe>
!!! Example "Structure tensor"
```python
import qim3d
# Show filtered
qim3d.viz.slices(filtered_vol)
vol = qim3d.examples.NT_128x128x128
val, vec = qim3d.processing.structure_tensor(vol, visualize = True, axis = 2)
```
![Data explorer GUI](assets/screenshots/qim3d-filters_example.png)
![structure tensor](assets/screenshots/structure_tensor_visualization.gif)
## Installation
Creating a `conda` environment is not required but recommended.
### Create environment
Creating a `conda` environment is not required but recommended.
??? info "Miniconda installation and setup"
[Miniconda](https://docs.anaconda.com/free/miniconda/index.html) is a free minimal installer for conda.
Here are some quick command line instructions to help you set up the latest Miniconda installer promptly. For graphical installers (.exe and .pkg) and instructions on hash checking, please refer to [Installing Miniconda](https://docs.anaconda.com/free/miniconda/miniconda-install/).
Here are some quick instructions to help you set up the latest Miniconda installer for your system:
=== "Windows"
These three commands quickly and quietly install the latest 64-bit version of the installer and then clean up after themselves. To install a different version or architecture of Miniconda for Windows, change the name of the `.exe` installer in the `curl` command.
```bash
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -o miniconda.exe
start /wait "" miniconda.exe /S
del miniconda.exe
```
After installing, open the “Anaconda Prompt (miniconda3)” program to use Miniconda3. For the Powershell version, use “Anaconda Powershell Prompt (miniconda3)”.
The easiest way to install Miniconda on Windows is through the graphical interface installer. Follow these steps:
1. Download the installer [here](https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe).
2. Run the installer and follow the on-screen instructions.
3. When the installation finishes, open `Anaconda Prompt (miniconda3)` from the Start menu.
=== "macOS"
These four commands quickly and quietly install the latest M1 macOS version of the installer and then clean up after themselves. To install a different version or architecture of Miniconda for macOS, change the name of the `.sh` installer in the `curl` command.
```bash
mkdir -p ~/miniconda3
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
```
The easiest way to install Miniconda on macOS is through the graphical interface installer. Follow these steps:
After installing, initialize your newly-installed Miniconda. The following commands initialize for bash and zsh shells:
1. Download the correct installer for your processor version. If you are unsure about your version, check [here](https://support.apple.com/en-us/116943).
- For Intel processors, download [x86](https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.pkg)
- For Apple Silicon (M1/M2/M3 etc) processors, download [arm64](https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.pkg)
```bash
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh
```
2. Run the installer and follow the on-screen instructions.
=== "Linux"
These four commands quickly and quietly install the latest 64-bit version of the installer and then clean up after themselves. To install a different version or architecture of Miniconda for Linux, change the name of the `.sh` installer in the `wget` command.
......@@ -90,39 +118,77 @@ Creating a `conda` environment is not required but recommended.
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh
```
Once you have `conda` installed, create a new enviroment:
Once you have `conda` installed, open your terminal and create a new enviroment:
```
conda create -n qim3d python=3.11
```
After the environment is created, activate it by running:
```
conda activate qim3d
```
Remember, if you chose to create an environment to install `qim3d`, it needs to be activated each time before using the library.
### Install using `pip`
The latest stable version can be simply installed using `pip`. Open your terminal and run:
pip install qim3d
### Install using `pip`
!!! note
The base installation of `qim3d` does not include deep-learning dependencies, keeping the library lighter for scenarios where they are unnecessary. If you need to use deep-learning features, you can install the additional dependencies by running: **`pip install qim3d['deep-learning']`**
### Troubleshooting
Here are some solutions for commonly found issues during installation and usage of `qim3d`.
The latest stable version can be simply installed using `pip`:
#### Failed building
Some Windows users could face an build error during installation.
??? Bug "ERROR: Failed building wheel for noise"
```
pip install qim3d
Building wheels for collected packages: noise, outputformat, asciitree, ffmpy
Building wheel for noise (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [14 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-311
creating build\lib.win-amd64-cpython-311\noise
copying perlin.py -> build\lib.win-amd64-cpython-311\noise
copying shader.py -> build\lib.win-amd64-cpython-311\noise
copying shader_noise.py -> build\lib.win-amd64-cpython-311\noise
copying test.py -> build\lib.win-amd64-cpython-311\noise
copying __init__.py -> build\lib.win-amd64-cpython-311\noise
running build_ext
building 'noise._simplex' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for noise
```
!!! note
Installing `qim3d` may take a bit of time due to its dependencies. Thank you for your patience!
This issue occurs because the system lacks the necessary tools to compile the library requirements. To resolve this, follow these steps:
### Upgrade
- Go to the [Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) page and click on "Download build tools."
- Run the installer and ensure that `Desktop development with C++` is checked. ![Windows build tools](assets/screenshots/Troubleshooting-Windows_build_tools.png)
- Restart your computer
- Activate your conda enviroment and run `pip install qim3d` again
#### Get the latest version
The library is under constant development, so make sure to keep your installation updated:
```
pip install --upgrade qim3d
```
## Collaboration
Contributions to `qim3d` are welcome!
If you find a bug, have a feature request, or would like to contribute code, please open an issue or submit a pull request.
......@@ -139,13 +205,13 @@ Below is a list of contributors to the project, arranged in chronological order
| Author | Commits | First commit |
|:--------------------------|----------:|-------------:|
| Felipe Delestro | 170 | 2023-05-12 |
| Felipe Delestro | 195 | 2023-05-12 |
| Stefan Engelmann Jensen | 29 | 2023-06-29 |
| Oskar Kristoffersen | 15 | 2023-07-05 |
| Christian Kento Rasmussen | 19 | 2024-02-01 |
| Christian Kento Rasmussen | 22 | 2024-02-01 |
| Alessia Saccardo | 7 | 2024-02-19 |
| David Grundfest | 4 | 2024-04-12 |
| Anna Bøgevang Ekner | 3 | 2024-04-18 |
| David Grundfest | 8 | 2024-04-12 |
| Anna Bøgevang Ekner | 5 | 2024-04-18 |
## Support
......
......@@ -9,4 +9,3 @@ Currently, it is possible to directly load `tiff`, `h5`, `nii`,`txm`, `vol` and
- load
- save
- Downloader
\ No newline at end of file
- ImgExamples
\ No newline at end of file
# Adding notebooks
Jupyter notebooks can be added to this directory, but following this guidelines:
Jupyter notebooks can be added to this directory, but following these guidelines:
- File size should be kept under 5MB
- Make a clean run of the notebook before saving and pushing
- Add descriptions of the intent and processes happening
......
......@@ -7,9 +7,22 @@ Below, you'll find details about the version history of `qim3d`.
As the library is still in its early development stages, **there may be breaking changes** before `v1.0` without prior deprecation warnings. Therefore, it's advisable to review the release history for more information if you encounter any issues.
And remember to keep your pip installation [up to date](/qim3d/#upgrade) so that you have the latest features!
And remember to keep your pip installation [up to date](/qim3d/#get-the-latest-version) so that you have the latest features!
### v0.4.1 (30/07/2024)
- Fixed issue with example volumes not being loaded
### v0.4.0 (29/07/2024)
- Refactored imports to use lazy loading
- Namespace `utils` reserved for internal tools only
- All deep-learning related functions moved to `models`
- Running `pip install qim3d` does not install DL requirements. For those, use `pip install qim3d['deep-learning']`
### v0.3.9 (24/07/2024)
- Loading and saving for Zarr files
- File convertion using the CLI, including Zarr
- Refactoring for the GUIs
......@@ -18,14 +31,17 @@ And remember to keep your pip installation [up to date](/qim3d/#upgrade) so that
- Introduction of `qim3d.generate.collection` 🎉 ![Introduction of `qim3d.generate.collection`](assets/screenshots/releases/qim3d-generate_collection.gif)
### v0.3.8 (20/06/2024)
- Minor refactoring and bug fixes
### v0.3.7 (17/06/2024)
- Performance improvements when importing
- Refactoring for blob detection ![Refactoring for blob detection](assets/screenshots/releases/qim3d-blob_detection_refactoring.gif)
### v0.3.6 (30/05/2024)
- Refactoring for performance improvement
- Welcome message for the CLI
- Introduction of `qim3d.processing.fade_mask` 🎉 ![Introduction of `qim3d.processing.fade_mask`](assets/screenshots/releases/qim3d-fade_viz.gif)
......@@ -33,6 +49,7 @@ And remember to keep your pip installation [up to date](/qim3d/#upgrade) so that
### v0.3.5 (27/05/2024)
- Added runtime and memory usage in the documentation
- Introduction of `qim3d.utils.generate_volume` 🎉 ![Introduction of `qim3d.utils.generate_volume`](assets/screenshots/releases/qim3d-synthetic_volume.gif)
- CLI refactoring, adding welcome message to the user ![CLI refactoring](assets/screenshots/releases/qim3d-CLI_welcome_message.png)
......@@ -40,6 +57,7 @@ And remember to keep your pip installation [up to date](/qim3d/#upgrade) so that
### v0.3.4 (22/05/2024)
- Documentation for `qim3d.viz.plot_cc`
- Fixed issue with Annotation tool and recent Gradio versions
- New colormap: `qim3d.viz.colormaps.qim`, showcasing the Qim colors!
......@@ -52,6 +70,7 @@ And remember to keep your pip installation [up to date](/qim3d/#upgrade) so that
- Aspect ratio issue for k3d fixed
### v0.3.3 (11/04/2024)
- Introduction of `qim3d.viz.slicer` (and also `qim3d.viz.orthogonal` ) 🎉
- Introduction of `qim3d.gui.annotation_tool` 🎉
- Introduction of `qim3d.processing.Blob` for blob detection 🎉
......
......@@ -22,10 +22,17 @@ code {
.md-content h3 {
margin-top: 2em !important;
margin-top: 2.5em !important;
font-size: 1.5em !important;
}
.md-content h4 {
margin-top: 2em !important;
margin-bottom: -0.5em !important;
font-size: 1.1em !important;
}
.md-search__form {
border-radius: 8px;
}
......@@ -101,3 +108,9 @@ code {
.md-typeset .example>.admonition-title:after, .md-typeset .example>summary:after {
color: #ff9900;
}
#playButton {
cursor: pointer;
margin-top: 0.05em;
vertical-align: middle;
}
......@@ -13,7 +13,6 @@ nav:
- Data Generation: generate.md
- Processing: processing.md
- Visualization: viz.md
- Utils: utils.md
- GUIs: gui.md
- ML Models: models.md
- CLI: cli.md
......
......@@ -8,17 +8,43 @@ Documentation available at https://platform.qim.dk/qim3d/
"""
__version__ = "0.3.9"
__version__ = "0.4.1"
from . import io
from . import gui
from . import viz
from . import utils
from . import processing
from . import generate
# commented out to avoid torch import
# from . import models
import importlib as _importlib
examples = io.ImgExamples()
io.logger.set_level_info()
class _LazyLoader:
"""Lazy loader to load submodules only when they are accessed"""
def __init__(self, module_name):
self.module_name = module_name
self.module = None
def _load(self):
if self.module is None:
self.module = _importlib.import_module(self.module_name)
return self.module
def __getattr__(self, item):
module = self._load()
return getattr(module, item)
# List of submodules
_submodules = [
"examples",
"generate",
"gui",
"io",
"models",
"processing",
"tests",
"utils",
"viz",
"cli",
]
# Creating lazy loaders for each submodule
for submodule in _submodules:
globals()[submodule] = _LazyLoader(f"qim3d.{submodule}")
import argparse
import webbrowser
import outputformat as ouf
from qim3d.gui import annotation_tool, data_explorer, iso3d, local_thickness
from qim3d.io.loading import DataLoader
from qim3d.utils import image_preview
from qim3d import __version__ as version
import qim3d.io
import qim3d
QIM_TITLE = ouf.rainbow(
f"\n _ _____ __ \n ____ _(_)___ ___ |__ /____/ / \n / __ `/ / __ `__ \ /_ </ __ / \n/ /_/ / / / / / / /__/ / /_/ / \n\__, /_/_/ /_/ /_/____/\__,_/ \n /_/ v{version}\n\n",
f"\n _ _____ __ \n ____ _(_)___ ___ |__ /____/ / \n / __ `/ / __ `__ \ /_ </ __ / \n/ /_/ / / / / / / /__/ / /_/ / \n\__, /_/_/ /_/ /_/____/\__,_/ \n /_/ v{qim3d.__version__}\n\n",
return_str=True,
cmap="hot",
)
def parse_tuple(arg):
# Remove parentheses if they are included and split by comma
return tuple(map(int, arg.strip('()').split(',')))
return tuple(map(int, arg.strip("()").split(",")))
def main():
parser = argparse.ArgumentParser(description="Qim3d command-line interface.")
......@@ -43,9 +40,9 @@ def main():
"--no-browser", action="store_true", help="Do not launch browser."
)
# K3D
# Viz
viz_parser = subparsers.add_parser("viz", help="Volumetric visualization.")
viz_parser.add_argument("--source", default=False, help="Path to the image file")
viz_parser.add_argument("filename", default=False, help="Path to the image file")
viz_parser.add_argument(
"--destination", default="k3d.html", help="Path to save html file."
)
......@@ -117,22 +114,27 @@ def main():
args = parser.parse_args()
if args.subcommand == "gui":
arghost = args.host
inbrowser = not args.no_browser # Should automatically open in browser
interface = None
if args.data_explorer:
interface_class = data_explorer.Interface
interface_class = qim3d.gui.data_explorer.Interface
elif args.iso3d:
interface_class = iso3d.Interface
interface_class = qim3d.gui.iso3d.Interface
elif args.annotation_tool:
interface_class = annotation_tool.Interface
interface_class = qim3d.gui.annotation_tool.Interface
elif args.local_thickness:
interface_class = local_thickness.Interface
interface_class = qim3d.gui.local_thickness.Interface
else:
print("Please select a tool by choosing one of the following flags:\n\t--data-explorer\n\t--iso3d\n\t--annotation-tool\n\t--local-thickness")
print(
"Please select a tool by choosing one of the following flags:\n\t--data-explorer\n\t--iso3d\n\t--annotation-tool\n\t--local-thickness"
)
return
interface = interface_class() # called here if we add another arguments to initialize
interface = (
interface_class()
) # called here if we add another arguments to initialize
if args.platform:
interface.run_interface(host=arghost)
......@@ -140,12 +142,9 @@ def main():
interface.launch(inbrowser=inbrowser, force_light_mode=False)
elif args.subcommand == "viz":
if not args.source:
print("Please specify a source file using the argument --source")
return
# Load the data
print(f"Loading data from {args.source}")
volume = qim3d.io.load(str(args.source))
print(f"Loading data from {args.filename}")
volume = qim3d.io.load(str(args.filename))
print(f"Done, volume shape: {volume.shape}")
# Make k3d plot
......@@ -158,9 +157,10 @@ def main():
webbrowser.open_new_tab(args.destination)
elif args.subcommand == "preview":
image = DataLoader().load(args.filename)
image_preview(
image = qim3d.io.load(args.filename)
qim3d.viz.image_preview(
image,
image_width=args.resolution,
axis=args.axis,
......@@ -169,6 +169,7 @@ def main():
)
elif args.subcommand == "convert":
qim3d.io.convert(args.input_path, args.output_path, chunk_shape=args.chunks)
elif args.subcommand is None:
......@@ -183,9 +184,6 @@ def main():
parser.print_help()
print("\n")
elif args.subcommand == 'convert':
qim3d.io.convert(args.input_path, args.output_path)
if __name__ == "__main__":
main()
""" Example images for testing and demonstration purposes. """
from pathlib import Path as _Path
from qim3d.utils.logger import log as _log
from qim3d.io import load as _load
# Save the original log level and set to ERROR
# to suppress the log messages during loading
_original_log_level = _log.level
_log.setLevel("ERROR")
# Load image examples
for _file_path in _Path(__file__).resolve().parent.glob("*.tif"):
globals().update({_file_path.stem: _load(_file_path, progress_bar=False)})
# Restore the original log level
_log.setLevel(_original_log_level)
import numpy as np
import scipy.ndimage
from tqdm.notebook import tqdm
from skimage.filters import threshold_li
from qim3d.generate import blob as generate_blob
from qim3d.processing import get_3d_cc
from qim3d.io.logger import log
import qim3d.generate
from qim3d.utils.logger import log
def random_placement(
......@@ -320,7 +318,7 @@ def collection(
log.debug(f"- Threshold: {threshold:.3f}")
# Generate synthetic blob
blob = generate_blob(
blob = qim3d.generate.blob(
base_shape=blob_shape,
final_shape=tuple(l * r for l, r in zip(blob_shape, object_shape_zoom)),
noise_scale=noise_scale,
......