Skip to content

Commit

Permalink
DOC: Add better comments in the notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
bnmajor committed Dec 11, 2023
1 parent 5c697a6 commit baaa34a
Showing 1 changed file with 54 additions and 39 deletions.
93 changes: 54 additions & 39 deletions examples/integrations/itk/SelectROI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mWARNING: jsonschema 3.2.0 does not provide the extra 'format-nongpl'\u001b[0m\u001b[33m\n",
"\u001b[0m"
]
}
],
"outputs": [],
"source": [
"# Install dependencies for this example\n",
"import sys\n",
Expand Down Expand Up @@ -134,14 +125,12 @@
]
},
{
"cell_type": "code",
"execution_count": 6,
"cell_type": "markdown",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Use the cropping planes to select the region of interest, then run the following cells"
"#### Use the cropping planes to select the region of interest, then run the following cells"
]
},
{
Expand All @@ -151,9 +140,16 @@
"<img src=\"https://raw.githubusercontent.com/InsightSoftwareConsortium/itkwidgets/examples/integrations/itk/select_roi.gif\" style=\"margin:auto\"/>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### There will be one or more resolution scales available depending on the size of the data. The lower the scale the higher the resolution, with zero being the highest resolution."
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {
"tags": ["skip-execution"]
},
Expand All @@ -165,7 +161,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {
"tags": ["skip-execution"]
},
Expand All @@ -176,7 +172,7 @@
"0"
]
},
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -185,9 +181,16 @@
"loaded_scale"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### The ROI region will return the physical, world coordinates for the selection"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {
"tags": ["skip-execution"]
},
Expand All @@ -199,18 +202,18 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {
"tags": ["skip-execution"]
},
"outputs": [
{
"data": {
"text/plain": [
"[[-0.5, -0.5, 103.06309145477312], [249.5, 349.5, 146.56424773624178]]"
"[[-0.5, -0.5, 84.31192586395754], [249.5, 349.5, 148.80125500944786]]"
]
},
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -219,51 +222,63 @@
"roi_region"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### By default the information for the current scale is returned when requesting the ROI slices. You can also pass a value in to explicitly request a scale."
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": { "tags": ["skip-execution"] },
"outputs": [],
"source": [
"# Request the slice information for the ROI\n",
"# By default the information for the current level is returned.\n",
"# Request the highest level explicitly in case that is not what is loaded.\n",
"roi_slice = viewer.get_roi_slice(0)"
"default_roi_slices = viewer.get_roi_slice()\n",
"roi_slices = viewer.get_roi_slice(loaded_scale)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### The results should match!\n",
"#### *Note*: The data is streamed in in chunks and the current resolution will improve as each scale becomes available. If you find that the slices do not match check the currently loaded scale (either programmatically or with the UI) - it may have improved since you last checked!"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": { "tags": ["skip-execution"] },
"outputs": [
{
"data": {
"text/plain": [
"(slice(0, 249, None), slice(0, 349, None), slice(103, 147, None))"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"(slice(0, 249, None), slice(0, 349, None), slice(84, 149, None)) (slice(0, 249, None), slice(0, 349, None), slice(84, 149, None))\n"
]
}
],
"source": [
"roi_slice"
"# The results should match\n",
"print(roi_slices, default_roi_slices)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"metadata": { "tags": ["skip-execution"] },
"outputs": [],
"source": [
"# Create a new viewer using only the data in the ROI determined above\n",
"roi = multiscales.images[0].data[roi_slice]"
"roi = multiscales.images[loaded_scale].data[roi_slices]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 13,
"metadata": {
"tags": ["skip-execution"]
},
Expand Down Expand Up @@ -315,7 +330,7 @@
}
],
"source": [
"viewer2 = view(roi)"
"viewer2 = view(roi, rotate=True)"
]
},
{
Expand Down

0 comments on commit baaa34a

Please sign in to comment.