Skip to content
Snippets Groups Projects
Commit b48441fb authored by fima's avatar fima :beers:
Browse files

Merge branch 'pre_workshop_refactoring' into 'main'

Pre workshop refactoring

See merge request !103
parents b73ef9a0 18a53cf1
Branches
Tags
1 merge request!103Pre workshop refactoring
...@@ -8,14 +8,16 @@ Documentation available at https://platform.qim.dk/qim3d/ ...@@ -8,14 +8,16 @@ Documentation available at https://platform.qim.dk/qim3d/
""" """
__version__ = "0.3.7" __version__ = "0.3.8"
from . import io from . import io
from . import gui from . import gui
from . import viz from . import viz
from . import utils from . import utils
from . import processing from . import processing
from . import models
# commented out to avoid torch import
# from . import models
examples = io.ImgExamples() examples = io.ImgExamples()
io.logger.set_level_info() io.logger.set_level_info()
...@@ -5,6 +5,7 @@ import ipywidgets as widgets ...@@ -5,6 +5,7 @@ import ipywidgets as widgets
from IPython.display import clear_output, display from IPython.display import clear_output, display
import qim3d import qim3d
def circles(blobs, vol, alpha=0.5, color="#ff9900", **kwargs): def circles(blobs, vol, alpha=0.5, color="#ff9900", **kwargs):
""" """
Plots the blobs found on a slice of the volume. Plots the blobs found on a slice of the volume.
...@@ -32,10 +33,9 @@ def circles(blobs, vol, alpha=0.5, color="#ff9900", **kwargs): ...@@ -32,10 +33,9 @@ def circles(blobs, vol, alpha=0.5, color="#ff9900", **kwargs):
vol, vol,
n_slices=1, n_slices=1,
position=z_slice, position=z_slice,
img_height=3,
img_width=3,
cmap="gray", cmap="gray",
show_position=False, show_position=False,
**kwargs
) )
# Add circles from deteced blobs # Add circles from deteced blobs
for detected in blobs: for detected in blobs:
......
...@@ -232,6 +232,7 @@ def slices( ...@@ -232,6 +232,7 @@ def slices(
show: bool = False, show: bool = False,
show_position: bool = True, show_position: bool = True,
interpolation: Optional[str] = "none", interpolation: Optional[str] = "none",
img_size = None,
**imshow_kwargs, **imshow_kwargs,
) -> plt.Figure: ) -> plt.Figure:
"""Displays one or several slices from a 3d volume. """Displays one or several slices from a 3d volume.
...@@ -271,6 +272,9 @@ def slices( ...@@ -271,6 +272,9 @@ def slices(
``` ```
![Grid of slices](assets/screenshots/viz-slices.png) ![Grid of slices](assets/screenshots/viz-slices.png)
""" """
if img_size:
img_height = img_size
img_width = img_size
# Numpy array or Torch tensor input # Numpy array or Torch tensor input
if not isinstance(vol, (np.ndarray, torch.Tensor, da.core.Array)): if not isinstance(vol, (np.ndarray, torch.Tensor, da.core.Array)):
...@@ -409,6 +413,7 @@ def slicer( ...@@ -409,6 +413,7 @@ def slicer(
img_width: int = 3, img_width: int = 3,
show_position: bool = False, show_position: bool = False,
interpolation: Optional[str] = "none", interpolation: Optional[str] = "none",
img_size = None,
**imshow_kwargs, **imshow_kwargs,
) -> widgets.interactive: ) -> widgets.interactive:
"""Interactive widget for visualizing slices of a 3D volume. """Interactive widget for visualizing slices of a 3D volume.
...@@ -435,6 +440,10 @@ def slicer( ...@@ -435,6 +440,10 @@ def slicer(
![viz slicer](assets/screenshots/viz-slicer.gif) ![viz slicer](assets/screenshots/viz-slicer.gif)
""" """
if img_size:
img_height = img_size
img_width = img_size
# Create the interactive widget # Create the interactive widget
def _slicer(position): def _slicer(position):
fig = slices( fig = slices(
...@@ -472,6 +481,7 @@ def orthogonal( ...@@ -472,6 +481,7 @@ def orthogonal(
img_width: int = 3, img_width: int = 3,
show_position: bool = False, show_position: bool = False,
interpolation: Optional[str] = None, interpolation: Optional[str] = None,
img_size = None,
): ):
"""Interactive widget for visualizing orthogonal slices of a 3D volume. """Interactive widget for visualizing orthogonal slices of a 3D volume.
...@@ -496,6 +506,10 @@ def orthogonal( ...@@ -496,6 +506,10 @@ def orthogonal(
![viz orthogonal](assets/screenshots/viz-orthogonal.gif) ![viz orthogonal](assets/screenshots/viz-orthogonal.gif)
""" """
if img_size:
img_height = img_size
img_width = img_size
z_slicer = slicer( z_slicer = slicer(
vol, vol,
axis=0, axis=0,
......
...@@ -5,6 +5,7 @@ from matplotlib.gridspec import GridSpec ...@@ -5,6 +5,7 @@ from matplotlib.gridspec import GridSpec
import ipywidgets as widgets import ipywidgets as widgets
import logging as log import logging as log
def vectors( def vectors(
volume: np.ndarray, volume: np.ndarray,
vec: np.ndarray, vec: np.ndarray,
...@@ -120,10 +121,10 @@ def vectors( ...@@ -120,10 +121,10 @@ def vectors(
# Orientations histogram # Orientations histogram
nbins = 36 nbins = 36
angles = np.arctan2(vectors_slice_y, vectors_slice_x) # angles from 0 to pi angles = np.arctan2(vectors_slice_y, vectors_slice_x) # angles from 0 to pi
distribution, bin_edges = np.histogram(angles, bins=nbins, range=(0.0, np.pi)) distribution, bin_edges = np.histogram(angles, bins=nbins, range=(0, np.pi))
# Find the bin with the maximum count # Find the bin with the maximum count
peak_bin_idx = np.argmax(distribution) peak_bin_idx = np.argmax(abs(distribution))
# Calculate the center of the peak bin # Calculate the center of the peak bin
peak_angle_rad = (bin_edges[peak_bin_idx] + bin_edges[peak_bin_idx + 1]) / 2 peak_angle_rad = (bin_edges[peak_bin_idx] + bin_edges[peak_bin_idx + 1]) / 2
# Convert the peak angle to degrees # Convert the peak angle to degrees
......
...@@ -9,7 +9,7 @@ with open("README.md", "r", encoding="utf-8") as f: ...@@ -9,7 +9,7 @@ with open("README.md", "r", encoding="utf-8") as f:
setup( setup(
name="qim3d", name="qim3d",
version="0.3.7", version="0.3.8",
author="Felipe Delestro", author="Felipe Delestro",
author_email="fima@dtu.dk", author_email="fima@dtu.dk",
description="QIM tools and user interfaces", description="QIM tools and user interfaces",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment