-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d026d2c
commit 95c161e
Showing
74 changed files
with
3,142 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
165 changes: 165 additions & 0 deletions
165
main/_downloads/19192f653cbb57a934e348239ca7e840/phasorpy_cursors.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 modified
BIN
+2.64 KB
(110%)
main/_downloads/315c4c52fb68082a731b192d944e2ede/tutorials_python.zip
Binary file not shown.
107 changes: 107 additions & 0 deletions
107
main/_downloads/78c7466b0ab259d8505a9a93cf280ce0/phasorpy_cursors.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 modified
BIN
+5.25 KB
(110%)
main/_downloads/a5659940aa3f8f568547d47752a43172/tutorials_jupyter.zip
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.