summaryrefslogtreecommitdiff
path: root/doc/source/Tutorials/Sift/sift.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'doc/source/Tutorials/Sift/sift.ipynb')
-rw-r--r--doc/source/Tutorials/Sift/sift.ipynb66
1 files changed, 40 insertions, 26 deletions
diff --git a/doc/source/Tutorials/Sift/sift.ipynb b/doc/source/Tutorials/Sift/sift.ipynb
index 4b96aad..af880d4 100644
--- a/doc/source/Tutorials/Sift/sift.ipynb
+++ b/doc/source/Tutorials/Sift/sift.ipynb
@@ -43,6 +43,7 @@
],
"source": [
"import time\n",
+ "\n",
"start_time = time.time()\n",
"%pylab nbagg"
]
@@ -865,10 +866,12 @@
"source": [
"# display test image\n",
"import silx\n",
- "print(\"Silx version %s\"%silx.version)\n",
+ "\n",
+ "print(\"Silx version %s\" % silx.version)\n",
"\n",
"from PIL import Image\n",
"from silx.test.utils import utilstest\n",
+ "\n",
"path = utilstest.getfile(\"lena.png\")\n",
"image = numpy.asarray(Image.open(path))\n",
"fig, ax = subplots()\n",
@@ -891,15 +894,16 @@
}
],
"source": [
- "#Initialization of the sift object is time consuming: it compiles all the code.\n",
- "import os \n",
- "#set to 1 to see the compilation going on\n",
- "os.environ[\"PYOPENCL_COMPILER_OUTPUT\"] = \"0\" \n",
- "#switch to \"GPU\" to \"CPU\" to enable fail-save version.\n",
- "devicetype=\"GPU\"\n",
+ "# Initialization of the sift object is time consuming: it compiles all the code.\n",
+ "import os\n",
+ "\n",
+ "# set to 1 to see the compilation going on\n",
+ "os.environ[\"PYOPENCL_COMPILER_OUTPUT\"] = \"0\"\n",
+ "# switch to \"GPU\" to \"CPU\" to enable fail-save version.\n",
+ "devicetype = \"GPU\"\n",
"from silx.image import sift\n",
"\n",
- "%time sift_ocl = sift.SiftPlan(template=image, devicetype=devicetype) \n",
+ "%time sift_ocl = sift.SiftPlan(template=image, devicetype=devicetype)\n",
"\n",
"print(\"Device used for calculation: \", sift_ocl.ctx.devices[0].name)"
]
@@ -933,13 +937,15 @@
}
],
"source": [
- "print(\"Time for calculating the keypoints on one image of size %sx%s\"%image.shape[:2])\n",
+ "print(\"Time for calculating the keypoints on one image of size %sx%s\" % image.shape[:2])\n",
"%time keypoints = sift_ocl(image)\n",
- "print(\"Number of keypoints: %s\"%len(keypoints))\n",
+ "print(\"Number of keypoints: %s\" % len(keypoints))\n",
"print(\"Keypoint content:\")\n",
"print(keypoints.dtype)\n",
- "print(\"x: %.3f \\t y: %.3f \\t sigma: %.3f \\t angle: %.3f\" % \n",
- " (keypoints[-1].x,keypoints[-1].y,keypoints[-1].scale,keypoints[-1].angle))\n",
+ "print(\n",
+ " \"x: %.3f \\t y: %.3f \\t sigma: %.3f \\t angle: %.3f\"\n",
+ " % (keypoints[-1].x, keypoints[-1].y, keypoints[-1].scale, keypoints[-1].angle)\n",
+ ")\n",
"print(\"descriptor:\")\n",
"print(keypoints[-1].desc)"
]
@@ -1753,10 +1759,10 @@
}
],
"source": [
- "#Overlay keypoints on the image:\n",
+ "# Overlay keypoints on the image:\n",
"fig, ax = subplots()\n",
"ax.imshow(image)\n",
- "ax.plot(keypoints[:].x, keypoints[:].y,\".g\")"
+ "ax.plot(keypoints[:].x, keypoints[:].y, \".g\")"
]
},
{
@@ -2568,7 +2574,7 @@
}
],
"source": [
- "#Diplaying keypoints by scale:\n",
+ "# Diplaying keypoints by scale:\n",
"fig, ax = subplots()\n",
"ax.hist(keypoints[:].scale, 100)\n",
"ax.set_xlabel(\"scale\")"
@@ -3383,18 +3389,18 @@
}
],
"source": [
- "#One can see 3 groups of keypoints, boundaries at: 8 and 20. Let's display them using colors.\n",
+ "# One can see 3 groups of keypoints, boundaries at: 8 and 20. Let's display them using colors.\n",
"S = 8\n",
"L = 20\n",
- "tiny = keypoints[keypoints[:].scale<S]\n",
- "small = keypoints[numpy.logical_and(keypoints[:].scale<L,keypoints[:].scale>=S)]\n",
- "bigger = keypoints[keypoints[:].scale>=L]\n",
+ "tiny = keypoints[keypoints[:].scale < S]\n",
+ "small = keypoints[numpy.logical_and(keypoints[:].scale < L, keypoints[:].scale >= S)]\n",
+ "bigger = keypoints[keypoints[:].scale >= L]\n",
"\n",
"fig, ax = subplots()\n",
"ax.imshow(image, cmap=\"gray\")\n",
- "ax.plot(tiny[:].x, tiny[:].y,\",g\", label=\"tiny\")\n",
- "ax.plot(small[:].x, small[:].y,\".b\", label=\"small\")\n",
- "ax.plot(bigger[:].x, bigger[:].y,\"or\", label=\"large\")\n",
+ "ax.plot(tiny[:].x, tiny[:].y, \",g\", label=\"tiny\")\n",
+ "ax.plot(small[:].x, small[:].y, \".b\", label=\"small\")\n",
+ "ax.plot(bigger[:].x, bigger[:].y, \"or\", label=\"large\")\n",
"ax.legend()"
]
},
@@ -3417,7 +3423,7 @@
"outputs": [],
"source": [
"shifted = numpy.zeros_like(image)\n",
- "shifted[5:,8:] = image[:-5, :-8]\n",
+ "shifted[5:, 8:] = image[:-5, :-8]\n",
"shifted_points = sift_ocl(shifted)"
]
},
@@ -3442,9 +3448,16 @@
"source": [
"%time mp = sift.MatchPlan()\n",
"%time match = mp(keypoints, shifted_points)\n",
- "print(\"Number of Keypoints with for image 1 : %i, For image 2 : %i, Matching keypoints: %i\" % (keypoints.size, shifted_points.size, match.shape[0]))\n",
+ "print(\n",
+ " \"Number of Keypoints with for image 1 : %i, For image 2 : %i, Matching keypoints: %i\"\n",
+ " % (keypoints.size, shifted_points.size, match.shape[0])\n",
+ ")\n",
"from numpy import median\n",
- "print(\"Measured offsets dx: %.3f, dy: %.3f\"%(median(match[:,1].x-match[:,0].x),median(match[:,1].y-match[:,0].y)))"
+ "\n",
+ "print(\n",
+ " \"Measured offsets dx: %.3f, dy: %.3f\"\n",
+ " % (median(match[:, 1].x - match[:, 0].x), median(match[:, 1].y - match[:, 0].y))\n",
+ ")"
]
},
{
@@ -4258,9 +4271,10 @@
"source": [
"# Example of usage of the automatic alignment:\n",
"import scipy.ndimage\n",
+ "\n",
"rotated = scipy.ndimage.rotate(image, 20, reshape=False)\n",
"sa = sift.LinearAlign(image, devicetype=devicetype)\n",
- "fig,ax = subplots(1, 3, figsize=(9,3))\n",
+ "fig, ax = subplots(1, 3, figsize=(9, 3))\n",
"ax[0].imshow(image)\n",
"ax[0].set_title(\"original\")\n",
"ax[1].imshow(rotated)\n",