From 43246e30afdd99b8be191485f2311c84ab08db9c Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 4 Dec 2014 15:42:42 -0800 Subject: [PATCH 1/8] Blob detection supports for non-integer sigmas --- skimage/feature/blob.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/skimage/feature/blob.py b/skimage/feature/blob.py index bc93d265..5ef5b314 100644 --- a/skimage/feature/blob.py +++ b/skimage/feature/blob.py @@ -200,9 +200,11 @@ def blob_dog(image, min_sigma=1, max_sigma=50, sigma_ratio=1.6, threshold=2.0, footprint=np.ones((3, 3, 3)), threshold_rel=0.0, exclude_border=False) - + # Convert array to float32 + lm = local_maxima.astype('float32') # Convert the last index to its corresponding scale value - local_maxima[:, 2] = sigma_list[local_maxima[:, 2]] + lm[:,2] = sigma_list[local_maxima[:,2]] + local_maxima = lm return _prune_blobs(local_maxima, overlap) @@ -300,8 +302,11 @@ def blob_log(image, min_sigma=1, max_sigma=50, num_sigma=10, threshold=.2, threshold_rel=0.0, exclude_border=False) + # Convert array to float32 + lm = local_maxima.astype('float32') # Convert the last index to its corresponding scale value - local_maxima[:, 2] = sigma_list[local_maxima[:, 2]] + lm[:,2] = sigma_list[local_maxima[:,2]] + local_maxima = lm return _prune_blobs(local_maxima, overlap) @@ -408,6 +413,9 @@ def blob_doh(image, min_sigma=1, max_sigma=30, num_sigma=10, threshold=0.01, threshold_rel=0.0, exclude_border=False) + # Convert array to float32 + lm = local_maxima.astype('float32') # Convert the last index to its corresponding scale value - local_maxima[:, 2] = sigma_list[local_maxima[:, 2]] + lm[:,2] = sigma_list[local_maxima[:,2]] + local_maxima = lm return _prune_blobs(local_maxima, overlap) From eb6ddc735b87e50021fb73928e470e2859c90619 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 4 Dec 2014 16:17:10 -0800 Subject: [PATCH 2/8] Changed local_maxima to float32 --- skimage/feature/blob.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/skimage/feature/blob.py b/skimage/feature/blob.py index 5ef5b314..d698cde0 100644 --- a/skimage/feature/blob.py +++ b/skimage/feature/blob.py @@ -200,8 +200,8 @@ def blob_dog(image, min_sigma=1, max_sigma=50, sigma_ratio=1.6, threshold=2.0, footprint=np.ones((3, 3, 3)), threshold_rel=0.0, exclude_border=False) - # Convert array to float32 - lm = local_maxima.astype('float32') + # Convert array to float64 + lm = local_maxima.astype('float64') # Convert the last index to its corresponding scale value lm[:,2] = sigma_list[local_maxima[:,2]] local_maxima = lm @@ -302,8 +302,8 @@ def blob_log(image, min_sigma=1, max_sigma=50, num_sigma=10, threshold=.2, threshold_rel=0.0, exclude_border=False) - # Convert array to float32 - lm = local_maxima.astype('float32') + # Convert array to float64 + lm = local_maxima.astype('float64') # Convert the last index to its corresponding scale value lm[:,2] = sigma_list[local_maxima[:,2]] local_maxima = lm @@ -413,8 +413,8 @@ def blob_doh(image, min_sigma=1, max_sigma=30, num_sigma=10, threshold=0.01, threshold_rel=0.0, exclude_border=False) - # Convert array to float32 - lm = local_maxima.astype('float32') + # Convert array to float64 + lm = local_maxima.astype('float64') # Convert the last index to its corresponding scale value lm[:,2] = sigma_list[local_maxima[:,2]] local_maxima = lm From 833edc17ef749054ed629936b2143aef8a8465c8 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 4 Dec 2014 16:22:58 -0800 Subject: [PATCH 3/8] Fixed typo --- skimage/feature/blob.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skimage/feature/blob.py b/skimage/feature/blob.py index d698cde0..d19fb3f1 100644 --- a/skimage/feature/blob.py +++ b/skimage/feature/blob.py @@ -200,7 +200,7 @@ def blob_dog(image, min_sigma=1, max_sigma=50, sigma_ratio=1.6, threshold=2.0, footprint=np.ones((3, 3, 3)), threshold_rel=0.0, exclude_border=False) - # Convert array to float64 + # Convert local_maxima to float64 lm = local_maxima.astype('float64') # Convert the last index to its corresponding scale value lm[:,2] = sigma_list[local_maxima[:,2]] @@ -302,7 +302,7 @@ def blob_log(image, min_sigma=1, max_sigma=50, num_sigma=10, threshold=.2, threshold_rel=0.0, exclude_border=False) - # Convert array to float64 + # Convert local_maxima to float64 lm = local_maxima.astype('float64') # Convert the last index to its corresponding scale value lm[:,2] = sigma_list[local_maxima[:,2]] @@ -413,7 +413,7 @@ def blob_doh(image, min_sigma=1, max_sigma=30, num_sigma=10, threshold=0.01, threshold_rel=0.0, exclude_border=False) - # Convert array to float64 + # Convert local_maxima to float64 lm = local_maxima.astype('float64') # Convert the last index to its corresponding scale value lm[:,2] = sigma_list[local_maxima[:,2]] From c86c6effe8ead802e01a8fa83aefc7bc945f2662 Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Sat, 2 May 2015 16:52:44 +0200 Subject: [PATCH 4/8] Fix tests for #1257 The test of blob_doh() set an unrealistically strict threshold for the accuracy of the estimated blob radius, causing the test to fail with the true floating-point value (previously, the test passed only because sigma was truncated to integer). Increasing the threshold fixes the problem. --- skimage/feature/tests/test_blob.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/feature/tests/test_blob.py b/skimage/feature/tests/test_blob.py index a46c442b..5def047c 100644 --- a/skimage/feature/tests/test_blob.py +++ b/skimage/feature/tests/test_blob.py @@ -141,7 +141,7 @@ def test_blob_doh(): radius = lambda x: x[2] s = sorted(blobs, key=radius) - thresh = 3 + thresh = 4 b = s[0] assert abs(b[0] - 400) <= thresh From dc0a91b5690554d330ed5e9b688a15f9d958a71f Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Sat, 2 May 2015 16:56:33 +0200 Subject: [PATCH 5/8] Fix doctests for #1257 Changing the return type of the blob functions from integer to float arrays invalidated the docstring examples. Updating the examples fixes the doctests. --- skimage/feature/blob.py | 117 ++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/skimage/feature/blob.py b/skimage/feature/blob.py index d19fb3f1..b4352e61 100644 --- a/skimage/feature/blob.py +++ b/skimage/feature/blob.py @@ -147,30 +147,30 @@ def blob_dog(image, min_sigma=1, max_sigma=50, sigma_ratio=1.6, threshold=2.0, -------- >>> from skimage import data, feature >>> feature.blob_dog(data.coins(), threshold=.5, max_sigma=40) - array([[ 45, 336, 16], - [ 52, 155, 16], - [ 52, 216, 16], - [ 54, 42, 16], - [ 54, 276, 10], - [ 58, 100, 10], - [120, 272, 16], - [124, 337, 10], - [125, 45, 16], - [125, 208, 10], - [127, 102, 10], - [128, 154, 10], - [185, 347, 16], - [193, 213, 16], - [194, 277, 16], - [195, 102, 16], - [196, 43, 10], - [198, 155, 10], - [260, 46, 16], - [261, 173, 16], - [263, 245, 16], - [263, 302, 16], - [267, 115, 10], - [267, 359, 16]]) + array([[ 45. , 336. , 16.777216], + [ 52. , 155. , 16.777216], + [ 52. , 216. , 16.777216], + [ 54. , 42. , 16.777216], + [ 54. , 276. , 10.48576 ], + [ 58. , 100. , 10.48576 ], + [ 120. , 272. , 16.777216], + [ 124. , 337. , 10.48576 ], + [ 125. , 45. , 16.777216], + [ 125. , 208. , 10.48576 ], + [ 127. , 102. , 10.48576 ], + [ 128. , 154. , 10.48576 ], + [ 185. , 347. , 16.777216], + [ 193. , 213. , 16.777216], + [ 194. , 277. , 16.777216], + [ 195. , 102. , 16.777216], + [ 196. , 43. , 10.48576 ], + [ 198. , 155. , 10.48576 ], + [ 260. , 46. , 16.777216], + [ 261. , 173. , 16.777216], + [ 263. , 245. , 16.777216], + [ 263. , 302. , 16.777216], + [ 267. , 115. , 10.48576 ], + [ 267. , 359. , 16.777216]]) Notes ----- @@ -259,23 +259,23 @@ def blob_log(image, min_sigma=1, max_sigma=50, num_sigma=10, threshold=.2, >>> img = data.coins() >>> img = exposure.equalize_hist(img) # improves detection >>> feature.blob_log(img, threshold = .3) - array([[113, 323, 1], - [121, 272, 17], - [124, 336, 11], - [126, 46, 11], - [126, 208, 11], - [127, 102, 11], - [128, 154, 11], - [185, 344, 17], - [194, 213, 17], - [194, 276, 17], - [197, 44, 11], - [198, 103, 11], - [198, 155, 11], - [260, 174, 17], - [263, 244, 17], - [263, 302, 17], - [266, 115, 11]]) + array([[ 113. , 323. , 1. ], + [ 121. , 272. , 17.33333333], + [ 124. , 336. , 11.88888889], + [ 126. , 46. , 11.88888889], + [ 126. , 208. , 11.88888889], + [ 127. , 102. , 11.88888889], + [ 128. , 154. , 11.88888889], + [ 185. , 344. , 17.33333333], + [ 194. , 213. , 17.33333333], + [ 194. , 276. , 17.33333333], + [ 197. , 44. , 11.88888889], + [ 198. , 103. , 11.88888889], + [ 198. , 155. , 11.88888889], + [ 260. , 174. , 17.33333333], + [ 263. , 244. , 17.33333333], + [ 263. , 302. , 17.33333333], + [ 266. , 115. , 11.88888889]]) Notes ----- @@ -364,24 +364,23 @@ def blob_doh(image, min_sigma=1, max_sigma=30, num_sigma=10, threshold=0.01, >>> from skimage import data, feature >>> img = data.coins() >>> feature.blob_doh(img) - array([[121, 271, 30], - [123, 44, 23], - [123, 205, 20], - [124, 336, 20], - [126, 101, 20], - [126, 153, 20], - [156, 302, 30], - [185, 348, 30], - [192, 212, 23], - [193, 275, 23], - [195, 100, 23], - [197, 44, 20], - [197, 153, 20], - [260, 173, 30], - [262, 243, 23], - [265, 113, 23], - [270, 363, 30]]) - + array([[ 121. , 271. , 30. ], + [ 123. , 44. , 23.55555556], + [ 123. , 205. , 20.33333333], + [ 124. , 336. , 20.33333333], + [ 126. , 101. , 20.33333333], + [ 126. , 153. , 20.33333333], + [ 156. , 302. , 30. ], + [ 185. , 348. , 30. ], + [ 192. , 212. , 23.55555556], + [ 193. , 275. , 23.55555556], + [ 195. , 100. , 23.55555556], + [ 197. , 44. , 20.33333333], + [ 197. , 153. , 20.33333333], + [ 260. , 173. , 30. ], + [ 262. , 243. , 23.55555556], + [ 265. , 113. , 23.55555556], + [ 270. , 363. , 30. ]]) Notes ----- From b80e49448484a0e20dc13bd5c8f31def4e9b3c4b Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Sat, 2 May 2015 17:43:43 +0200 Subject: [PATCH 6/8] Change data types to conform to style guide --- skimage/feature/blob.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skimage/feature/blob.py b/skimage/feature/blob.py index b4352e61..b84f3a9e 100644 --- a/skimage/feature/blob.py +++ b/skimage/feature/blob.py @@ -201,7 +201,7 @@ def blob_dog(image, min_sigma=1, max_sigma=50, sigma_ratio=1.6, threshold=2.0, threshold_rel=0.0, exclude_border=False) # Convert local_maxima to float64 - lm = local_maxima.astype('float64') + lm = local_maxima.astype(np.float64) # Convert the last index to its corresponding scale value lm[:,2] = sigma_list[local_maxima[:,2]] local_maxima = lm @@ -303,7 +303,7 @@ def blob_log(image, min_sigma=1, max_sigma=50, num_sigma=10, threshold=.2, exclude_border=False) # Convert local_maxima to float64 - lm = local_maxima.astype('float64') + lm = local_maxima.astype(np.float64) # Convert the last index to its corresponding scale value lm[:,2] = sigma_list[local_maxima[:,2]] local_maxima = lm @@ -413,7 +413,7 @@ def blob_doh(image, min_sigma=1, max_sigma=30, num_sigma=10, threshold=0.01, exclude_border=False) # Convert local_maxima to float64 - lm = local_maxima.astype('float64') + lm = local_maxima.astype(np.float64) # Convert the last index to its corresponding scale value lm[:,2] = sigma_list[local_maxima[:,2]] local_maxima = lm From d5099db362e7219b98005186c9e1a581c6ca9eba Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Sun, 3 May 2015 01:32:56 +0200 Subject: [PATCH 7/8] Fix PEP8 --- skimage/feature/blob.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skimage/feature/blob.py b/skimage/feature/blob.py index b84f3a9e..1d4e8339 100644 --- a/skimage/feature/blob.py +++ b/skimage/feature/blob.py @@ -203,7 +203,7 @@ def blob_dog(image, min_sigma=1, max_sigma=50, sigma_ratio=1.6, threshold=2.0, # Convert local_maxima to float64 lm = local_maxima.astype(np.float64) # Convert the last index to its corresponding scale value - lm[:,2] = sigma_list[local_maxima[:,2]] + lm[:, 2] = sigma_list[local_maxima[:, 2]] local_maxima = lm return _prune_blobs(local_maxima, overlap) @@ -305,7 +305,7 @@ def blob_log(image, min_sigma=1, max_sigma=50, num_sigma=10, threshold=.2, # Convert local_maxima to float64 lm = local_maxima.astype(np.float64) # Convert the last index to its corresponding scale value - lm[:,2] = sigma_list[local_maxima[:,2]] + lm[:, 2] = sigma_list[local_maxima[:, 2]] local_maxima = lm return _prune_blobs(local_maxima, overlap) @@ -415,6 +415,6 @@ def blob_doh(image, min_sigma=1, max_sigma=30, num_sigma=10, threshold=0.01, # Convert local_maxima to float64 lm = local_maxima.astype(np.float64) # Convert the last index to its corresponding scale value - lm[:,2] = sigma_list[local_maxima[:,2]] + lm[:, 2] = sigma_list[local_maxima[:, 2]] local_maxima = lm return _prune_blobs(local_maxima, overlap) From 113c9984944f623755641c3d59910881b52296c8 Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Sat, 9 May 2015 20:41:55 +0200 Subject: [PATCH 8/8] Add note about blob detection api change --- doc/source/api_changes.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/source/api_changes.txt b/doc/source/api_changes.txt index 84625732..a8edfc3d 100644 --- a/doc/source/api_changes.txt +++ b/doc/source/api_changes.txt @@ -1,3 +1,8 @@ +Version 0.12 +------------ +- The functions ``blob_dog``, ``blob_log`` and ``blob_doh`` now return float + arrays instead of integer arrays. + Version 0.11 ------------ - The ``skimage.filter`` subpackage has been renamed to ``skimage.filters``.