Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-pannunzio committed Jul 17, 2024
1 parent d026d2c commit 95c161e
Show file tree
Hide file tree
Showing 74 changed files with 3,142 additions and 211 deletions.
2 changes: 1 addition & 1 deletion main/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 6a1d0a9c1312d1a5df376d628fa2dfc5
config: 8b702b1bb427bbb58c36af3bd5837df4
tags: 645f666f9bcd5a90fca523b33c5a78b7
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Cursors\n\nAn introduction to selecting phasor coordinates using cursors.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import required modules, functions, and classes:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nimport tifffile\n\nfrom phasorpy.color import CATEGORICAL\nfrom phasorpy.cursors import (\n mask_from_circular_cursor,\n mask_from_polar_cursor,\n pseudo_color,\n)\nfrom phasorpy.datasets import fetch\nfrom phasorpy.phasor import phasor_from_signal, phasor_to_polar\nfrom phasorpy.plot import PhasorPlot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Circular cursors\n\nUse circular cursors in the phasor space to mask regions of interest:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"signal = tifffile.imread(fetch('paramecium.lsm'))\nmean, real, imag = phasor_from_signal(signal, axis=0)\ncursors_real = [-0.33, 0.55]\ncursors_imag = [-0.72, -0.72]\ncircular_mask = mask_from_circular_cursor(\n real, imag, cursors_real, cursors_imag, radius=0.2\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Show the circular cursors in the phasor plot:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"threshold = mean > 1\n\nplot = PhasorPlot(allquadrants=True, title='Two circular cursors')\nplot.hist2d(real[threshold], imag[threshold])\nfor i in range(len(cursors_real)):\n plot.cursor(\n cursors_real[i],\n cursors_imag[i],\n radius=0.2,\n color=CATEGORICAL[i],\n linestyle='-',\n )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Polar cursor\n\nCreate a mask with phase and modulation values:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"phase, mod = phasor_to_polar(real, imag)\n\nphase_range = [[-2.27, -1.57], [-1.22, -0.70]]\nmodulation_range = [[0.7, 0.9], [0.8, 1.0]]\npolar_mask = mask_from_polar_cursor(phase, mod, phase_range, modulation_range)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Show cursors in the phasor plot:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plot = PhasorPlot(allquadrants=True, title='Two polar cursors')\nplot.hist2d(real[threshold], imag[threshold], cmap='Blues')\nfor i in range(len(phase_range[0])):\n plot.polar_cursor(\n phase=phase_range[i][0],\n phase_limit=phase_range[i][1],\n modulation=modulation_range[i][0],\n modulation_limit=modulation_range[i][1],\n color=CATEGORICAL[i + 2],\n linestyle='-',\n )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pseudo-color\n\nAverage images can be pseudo-colored (segmented) using cursor's masks.\nSegmented image with circular cursors:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"segmented_image = pseudo_color(mean, circular_mask)\n\nfig, ax = plt.subplots()\nax.set_title('Segmented image with circular cursors')\nax.imshow(segmented_image)\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Segmented image with polar cursors:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"segmented_image = pseudo_color(mean, polar_mask, colors=CATEGORICAL[2:])\n\nfig, ax = plt.subplots()\nax.set_title('Segmented image with polar cursors')\nax.imshow(segmented_image)\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"sphinx_gallery_thumbnail_number = 1\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Binary file not shown.
107 changes: 107 additions & 0 deletions main/_downloads/78c7466b0ab259d8505a9a93cf280ce0/phasorpy_cursors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""
Cursors
=======
An introduction to selecting phasor coordinates using cursors.
"""

# %%
# Import required modules, functions, and classes:

import matplotlib.pyplot as plt
import tifffile

from phasorpy.color import CATEGORICAL
from phasorpy.cursors import (
mask_from_circular_cursor,
mask_from_polar_cursor,
pseudo_color,
)
from phasorpy.datasets import fetch
from phasorpy.phasor import phasor_from_signal, phasor_to_polar
from phasorpy.plot import PhasorPlot

# %%
# Circular cursors
# ----------------
#
# Use circular cursors in the phasor space to mask regions of interest:

signal = tifffile.imread(fetch('paramecium.lsm'))
mean, real, imag = phasor_from_signal(signal, axis=0)
cursors_real = [-0.33, 0.55]
cursors_imag = [-0.72, -0.72]
circular_mask = mask_from_circular_cursor(
real, imag, cursors_real, cursors_imag, radius=0.2
)

# %%
# Show the circular cursors in the phasor plot:

threshold = mean > 1

plot = PhasorPlot(allquadrants=True, title='Two circular cursors')
plot.hist2d(real[threshold], imag[threshold])
for i in range(len(cursors_real)):
plot.cursor(
cursors_real[i],
cursors_imag[i],
radius=0.2,
color=CATEGORICAL[i],
linestyle='-',
)

# %%
# Polar cursor
# ------------
#
# Create a mask with phase and modulation values:

phase, mod = phasor_to_polar(real, imag)

phase_range = [[-2.27, -1.57], [-1.22, -0.70]]
modulation_range = [[0.7, 0.9], [0.8, 1.0]]
polar_mask = mask_from_polar_cursor(phase, mod, phase_range, modulation_range)

# %%
# Show cursors in the phasor plot:

plot = PhasorPlot(allquadrants=True, title='Two polar cursors')
plot.hist2d(real[threshold], imag[threshold], cmap='Blues')
for i in range(len(phase_range[0])):
plot.polar_cursor(
phase=phase_range[i][0],
phase_limit=phase_range[i][1],
modulation=modulation_range[i][0],
modulation_limit=modulation_range[i][1],
color=CATEGORICAL[i + 2],
linestyle='-',
)

# %%
# Pseudo-color
# ------------
#
# Average images can be pseudo-colored (segmented) using cursor's masks.
# Segmented image with circular cursors:

segmented_image = pseudo_color(mean, circular_mask)

fig, ax = plt.subplots()
ax.set_title('Segmented image with circular cursors')
ax.imshow(segmented_image)
plt.show()

# %%
# Segmented image with polar cursors:

segmented_image = pseudo_color(mean, polar_mask, colors=CATEGORICAL[2:])

fig, ax = plt.subplots()
ax.set_title('Segmented image with polar cursors')
ax.imshow(segmented_image)
plt.show()

# %%
# sphinx_gallery_thumbnail_number = 1
Binary file not shown.
Binary file added main/_images/sphx_glr_phasorpy_cursors_001.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 main/_images/sphx_glr_phasorpy_cursors_002.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 main/_images/sphx_glr_phasorpy_cursors_003.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 main/_images/sphx_glr_phasorpy_cursors_004.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 main/_images/sphx_glr_phasorpy_cursors_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion main/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@
<h1>All modules for which code is available</h1>
<ul><li><a href="phasorpy/color.html">phasorpy.color</a></li>
<li><a href="phasorpy/components.html">phasorpy.components</a></li>
<li><a href="phasorpy/cursors.html">phasorpy.cursors</a></li>
<li><a href="phasorpy/datasets.html">phasorpy.datasets</a></li>
<li><a href="phasorpy/io.html">phasorpy.io</a></li>
<li><a href="phasorpy/phasor.html">phasorpy.phasor</a></li>
Expand Down Expand Up @@ -512,7 +513,7 @@ <h1>All modules for which code is available</h1>
<div class="footer-item">

<p class="sphinx-version">
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.3.7.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.4.5.
<br/>
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion main/_modules/phasorpy/color.html
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ <h1>Source code for phasorpy.color</h1><div class="highlight"><pre>
<div class="footer-item">

<p class="sphinx-version">
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.3.7.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.4.5.
<br/>
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion main/_modules/phasorpy/components.html
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ <h1>Source code for phasorpy.components</h1><div class="highlight"><pre>
<div class="footer-item">

<p class="sphinx-version">
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.3.7.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.4.5.
<br/>
</p>
</div>
Expand Down
Loading

0 comments on commit 95c161e

Please sign in to comment.