Skip to content

ImageWidget #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1fea4aa
started implementation of ImageWidget, nothing is tested yet
kushalkolar Dec 2, 2022
1bc65a0
basic stuff finished for single plot with a slider, need to test
kushalkolar Dec 2, 2022
6592cc3
basic image widget works
kushalkolar Dec 2, 2022
658f298
docs
kushalkolar Dec 2, 2022
5cc91ae
splitting imagewidget into two classes
kushalkolar Dec 4, 2022
7a6a136
split ImageWidget into ImageWidgetSingle and later ImageWidgetGrid
kushalkolar Dec 4, 2022
7cce91f
combined single and grid ImageWidget into single class
kushalkolar Dec 4, 2022
56a9b1c
simple and grid image widget works, tested with simple args, need to …
kushalkolar Dec 4, 2022
79f4452
catch another user error
kushalkolar Dec 4, 2022
e4f6b12
fix type annotation
kushalkolar Dec 4, 2022
5028ce7
docstrings, started slice_avg implementation
kushalkolar Dec 4, 2022
5ef32eb
slice averaging on single and multiple dimensions works perfectly
kushalkolar Dec 5, 2022
eca6599
is_array() checks for and attr, better error messages
kushalkolar Dec 8, 2022
0e3cf16
rename axis -> dims
kushalkolar Dec 10, 2022
570c076
make most imagewidget methods private, most attributes as read-only p…
kushalkolar Dec 10, 2022
4764b84
quick_min_max() returns pre-computed min max if int or float, imagewi…
kushalkolar Dec 10, 2022
afc0378
vmin vmax for gridplot
kushalkolar Dec 10, 2022
fc3365b
Merge branch 'master' into high-level-widgets
kushalkolar Dec 11, 2022
b1e922c
update Image -> ImageGraphic
kushalkolar Dec 11, 2022
e6c5d3a
refactor, window_funcs now works very well, slow with multiple dims b…
kushalkolar Dec 11, 2022
64faffd
vminmax works, also added names for subplots, everything works
kushalkolar Dec 11, 2022
8fc63b3
proper-ish image widget example
kushalkolar Dec 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
393 changes: 393 additions & 0 deletions examples/image_widget.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,393 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "04f453ca-d0bc-411f-b2a6-d38294dd0a26",
"metadata": {},
"outputs": [],
"source": [
"from fastplotlib.widgets import ImageWidget\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"id": "e933771b-f172-4fa9-b2f8-129723efb808",
"metadata": {},
"source": [
"# Single image sequence"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ea87f9a6-437f-41f6-8739-c957fb04bdbf",
"metadata": {},
"outputs": [],
"source": [
"a = np.random.rand(500, 512, 512)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8b7a6066-ff69-4bee-bae6-160fb4038393",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6d575ba7671047ca88c36606344714fa",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"RFBOutputContext()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"iw = ImageWidget(\n",
" data=a, \n",
" slider_dims=[\"t\"],\n",
" vmin_vmax_sliders=True,\n",
" cmap=\"gnuplot2\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "3d4cb44e-2c71-4bff-aeed-b2129f34d724",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8de187407b7746168c8d20a428d8712e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(JupyterWgpuCanvas(), IntSlider(value=0, description='dimension: t', max=499), FloatRangeSlider(…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"iw.show()"
]
},
{
"cell_type": "markdown",
"id": "9908103c-c35c-4f33-ada1-0fc357c3fd5e",
"metadata": {},
"source": [
"### Play with setting different window functions\n",
"\n",
"These can also be given as kwargs to `ImageWidget` during instantiation"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f278b26a-1b71-4e76-9cc7-efaddbd7b122",
"metadata": {},
"outputs": [],
"source": [
"# must be in the form of {dim: (func, window_size)}\n",
"iw.window_funcs = {\"t\": (np.mean, 13)}"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "cb4d4b7c-919f-41c0-b1cc-b4496473d760",
"metadata": {},
"outputs": [],
"source": [
"# change the winow size\n",
"iw.window_funcs[\"t\"].window_size = 23"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "2eea6432-4d38-4d42-ab75-f6aa1bab36f4",
"metadata": {},
"outputs": [],
"source": [
"# change the function\n",
"iw.window_funcs[\"t\"].func = np.max"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "afa2436f-2741-49d6-87f6-7a91a343fe0e",
"metadata": {},
"outputs": [],
"source": [
"# or set it again\n",
"iw.window_funcs = {\"t\": (np.min, 11)}"
]
},
{
"cell_type": "markdown",
"id": "aca22179-1b1f-4c51-97bf-ce2d7044e451",
"metadata": {},
"source": [
"# Gridplot of txy data"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "882162eb-c873-42df-a945-d5e05ad141c9",
"metadata": {},
"outputs": [],
"source": [
"dims = (100, 512, 512)\n",
"data = [np.random.rand(*dims) for i in range(4)]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "bf9f92b6-38ad-4d78-b88c-a32d473b6462",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "005bcbc7755748cfaf0644e28beb3b0e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"RFBOutputContext()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"iw = ImageWidget(\n",
" data=data, \n",
" slider_dims=[\"t\"], \n",
" # dims_order=\"txy\", # you can set this manually if dim order is not the usual\n",
" vmin_vmax_sliders=True,\n",
" names=[\"zero\", \"one\", \"two\", \"three\"],\n",
" window_funcs={\"t\": (np.mean, 5)},\n",
" cmap=\"gnuplot2\", \n",
")"
]
},
{
"cell_type": "markdown",
"id": "0721dc40-677e-431d-94c6-da59606199cb",
"metadata": {},
"source": [
"### pan-zoom controllers are all synced in a `ImageWidget`"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "403dde31-981a-46fb-b005-1bcef19c4f2c",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2b0a10be5d5b43b5a08f51a9d8f9b1dc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(JupyterWgpuCanvas(), IntSlider(value=0, description='dimension: t', max=99), FloatRangeSlider(v…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"iw.show()"
]
},
{
"cell_type": "markdown",
"id": "82545214-13c4-475e-87da-962117085834",
"metadata": {},
"source": [
"### Index the subplots using the names given to `ImageWidget`"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "b59d95e2-9092-4915-beef-01661d164781",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"two: Subplot @ 0x7f91486a7a00\n",
" parent: None\n",
" Graphics:\n",
"\tfastplotlib.ImageGraphic @ 0x7f914881ceb0"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"iw.plot[\"two\"]"
]
},
{
"cell_type": "markdown",
"id": "dc727d1a-681e-4cbf-bfb2-898ceb31cbe0",
"metadata": {},
"source": [
"### change window functions just like before"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "a8f070db-da11-4062-95aa-f19b96351ee8",
"metadata": {},
"outputs": [],
"source": [
"iw.window_funcs[\"t\"].func = np.max"
]
},
{
"cell_type": "markdown",
"id": "3e89c10f-6e34-4d63-9805-88403d487432",
"metadata": {},
"source": [
"## Gridplot of volumetric data"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "b1587410-a08e-484c-8795-195a413d6374",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a2e4d723405345e0a7bd7b005330d018",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"RFBOutputContext()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dims = (256, 256, 5, 100)\n",
"data = [np.random.rand(*dims) for i in range(4)]\n",
"\n",
"iw = ImageWidget(\n",
" data=data, \n",
" slider_dims=[\"t\", \"z\"], \n",
" dims_order=\"xyzt\", # example of how you can set this for non-standard orders\n",
" vmin_vmax_sliders=True,\n",
" names=[\"zero\", \"one\", \"two\", \"three\"],\n",
" # window_funcs={\"t\": (np.mean, 5)}, # window functions can be slow when indexing multiple dims\n",
" cmap=\"gnuplot2\", \n",
")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "3ccea6c6-9580-4720-bce8-a5507cf867a3",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "78a4ed0f59734124a7f3ee23e373e64a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(JupyterWgpuCanvas(), IntSlider(value=0, description='dimension: t', max=99), IntSlider(value=0,…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"iw.show()"
]
},
{
"cell_type": "markdown",
"id": "2382809c-4c7d-4da4-9955-71d316dee46a",
"metadata": {},
"source": [
"### window functions, can be slow when you have \"t\" and \"z\""
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "fd4433a9-2add-417c-a618-5891371efae0",
"metadata": {},
"outputs": [],
"source": [
"iw.window_funcs = {\"t\": (np.mean, 11)}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3090a7e2-558e-4975-82f4-6a67ae141900",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading