From 782fc7a40aa341f91c872db3881265513f905613 Mon Sep 17 00:00:00 2001 From: Matt Cai Date: Mon, 23 Mar 2020 16:45:37 -0700 Subject: [PATCH 1/6] modified local_max_peak_finder to be able to remove labeled regions from masked_image when masked_image is 2D --- examples/how_to/local_max_peak_finder.py | 4 ---- expression | Bin 1360 -> 1360 bytes .../spots/FindSpots/local_max_peak_finder.py | 8 ++++++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/how_to/local_max_peak_finder.py b/examples/how_to/local_max_peak_finder.py index 46ea009db..85705a8ff 100644 --- a/examples/how_to/local_max_peak_finder.py +++ b/examples/how_to/local_max_peak_finder.py @@ -21,10 +21,6 @@ that can be detected. The recommended way to set parameters is to take a representative image and :ref:`visually assess ` results. -.. warning:: - :py:class:`.LocalMaxPeakFinder` does not support finding spots on independent 2D slices of a - volume (i.e., ``is_volume = False``). - .. warning:: :py:class:`.LocalMaxPeakFinder` is not compatible with cropped data sets. diff --git a/expression b/expression index f71b255fa38b942d49639b70d2d75e6ae9f404a8..7a08cf6b39b73c072ca613d9fce9b8b77d1447cd 100644 GIT binary patch delta 309 zcmcb>b%ATb6roCmDuoJ#L+)lz?rf%;tYbey(31o}<$o__VdgXc50SL#^}{g|ZXU>;I#9%5SM5IXcSYy1V+h#yf&ZCjc`KYv%v} delta 322 zcmcb>b%ATb6rJSMoSgW~6otIf+@#c^`24i^(!7+^l=$L;{E}jY#G=$hg(`(g zg^G;_beJadFgr~C!(=cyo`qv_4vWC#7-kUWsCO{R-MhKyU#~+z-m?gmYrYO1bA4jZ zFO_j{T9IF!(6Y%P?74v+^SR>=fin_WySNP;LNodd_f3&;aLkWeU|*5r5ctmW%e<{j z4gpo0-(E}&b#Rz^nDfEwTnC4Vg)O1UyB%CR&G??V`#J=Ekt-B_d%_`nhwsU!k2X7m zUs5{kU!&yV;Qy2@vqfd414~%C&Bn^T4#JJsQmQwtbg*tHy&%2dxx?gG7Wv6C%p8mk zlXY3dCx-wX-ooNBxd-TxGc3V|%nS?+EI`Zw#N0s43&eatEC9rUKr95r!tSnquJMjw G(g^@_>2Uo3 diff --git a/starfish/core/spots/FindSpots/local_max_peak_finder.py b/starfish/core/spots/FindSpots/local_max_peak_finder.py index 7c2e7bbd6..2400f8861 100644 --- a/starfish/core/spots/FindSpots/local_max_peak_finder.py +++ b/starfish/core/spots/FindSpots/local_max_peak_finder.py @@ -236,14 +236,18 @@ def image_to_spots( data_image_np = np.asarray(data_image) # identify each spot's size by binarizing and calculating regionprops - masked_image = data_image_np[:, :] > optimal_threshold + masked_image = data_image_np > optimal_threshold labels = label(masked_image)[0] spot_props = regionprops(np.squeeze(labels)) # mask spots whose areas are too small or too large for spot_prop in spot_props: if spot_prop.area < self.min_obj_area or spot_prop.area > self.max_obj_area: - masked_image[0, spot_prop.coords[:, 0], spot_prop.coords[:, 1]] = 0 + if self.is_volume: + masked_image[spot_prop.coords[:, 0], spot_prop.coords[:, 1], + spot_prop.coords[:, 2]] = 0 + else: + masked_image[spot_prop.coords[:, 0], spot_prop.coords[:, 1]] = 0 # store re-calculated regionprops and labels based on the area-masked image labels = label(masked_image)[0] From f763171bdcd9c834a2b6d1a08b2a3617372e24ea Mon Sep 17 00:00:00 2001 From: Matt Cai Date: Tue, 24 Mar 2020 00:16:35 -0700 Subject: [PATCH 2/6] fixed to allow 2D data with is_volume=True --- examples/how_to/local_max_peak_finder.py | 42 ++++++++++++++++--- .../spots/FindSpots/local_max_peak_finder.py | 5 ++- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/examples/how_to/local_max_peak_finder.py b/examples/how_to/local_max_peak_finder.py index 85705a8ff..bad010eb1 100644 --- a/examples/how_to/local_max_peak_finder.py +++ b/examples/how_to/local_max_peak_finder.py @@ -14,12 +14,16 @@ :py:class:`.LocalMaxPeakFinder` finds spots by finding the optimal threshold to binarize image into foreground (spots) and background and then using :py:func:`skimage.feature.peak_local_max` to -find local maxima or peaks in the foreground. Each peak is counted as a spot with radius equal to -one pixel. Using :py:class:`.LocalMaxPeakFinder` requires knowledge of expected spot sizes since it -uses ``min_obj_area`` and ``max_obj_area`` to filter foreground connected components before finding -peaks. ``min_distance`` is also used to to filter out noise by limiting the distance between peaks +find local maxima or peaks in the foreground. If spots are being detected in the dark areas, +increase the ``stringency`` value to increase the threshold. Using :py:class:`.LocalMaxPeakFinder` +requires knowledge of expected foreground sizes since it uses ``min_obj_area`` and +``max_obj_area`` to filter connected foreground components before finding peaks. On the low end, +``min_obj_area`` should be set to the area of one spot so that smaller foreground objects are +removed. On the high end, ``max_obj_area`` can be set to ``np.inf`` and decreased if necessary. +``min_distance`` is another threshold to filter out noise by limiting the distance between peaks that can be detected. The recommended way to set parameters is to take a representative image and -:ref:`visually assess ` results. +:ref:`visually assess ` results. Each peak is counted as a spot with +radius equal to one pixel. .. warning:: :py:class:`.LocalMaxPeakFinder` is not compatible with cropped data sets. @@ -49,6 +53,32 @@ stringency=0, min_obj_area=6, max_obj_area=600, - is_volume=True + is_volume=False ) spots = lmp.run(max_imgs) + + +from starfish.core.spots.DecodeSpots.trace_builders import build_traces_sequential +table = build_traces_sequential(spots) + +# plot spots found +import matplotlib +import matplotlib.pyplot as plt +from starfish.util.plot import imshow_plane + +# get x, y coords from intensity table +def get_cropped_coords(table, x_min, x_max, y_min, y_max): + df = table.to_features_dataframe() + df = df.loc[df['x'].between(x_min, x_max) & df['y'].between(y_min, y_max)] + return df['x'].values-x_min, df['y'].values-y_min, df['radius'].values.astype(int) +lmp_x, lmp_y, lmp_s = get_cropped_coords(lmp_table, 0, 500, 0, 500) + +matplotlib.rcParams["figure.dpi"] = 150 +f, (ax1, ax2, ax3) = plt.subplots(ncols=3) + +# Plot cropped region of max z-projected dots image +imshow_plane(max_imgs, sel={Axes.X: (0, 500), Axes.Y: (0, 500)}, ax=ax1, title='BlobDetector') +imshow_plane(max_imgs, sel={Axes.X: (0, 500), Axes.Y: (0, 500)}, ax=ax2, title='LocalMaxPeak') +imshow_plane(max_imgs, sel={Axes.X: (0, 500), Axes.Y: (0, 500)}, ax=ax3, title='Trackpy') +# Overlay spots found by each FindSpotsAlgorithm +ax1.scatter(lmp_x, lmp_y, marker='o', facecolors='none', edgecolors='r', s=lmp_s*10) \ No newline at end of file diff --git a/starfish/core/spots/FindSpots/local_max_peak_finder.py b/starfish/core/spots/FindSpots/local_max_peak_finder.py index 2400f8861..ffce31923 100644 --- a/starfish/core/spots/FindSpots/local_max_peak_finder.py +++ b/starfish/core/spots/FindSpots/local_max_peak_finder.py @@ -238,7 +238,10 @@ def image_to_spots( # identify each spot's size by binarizing and calculating regionprops masked_image = data_image_np > optimal_threshold labels = label(masked_image)[0] - spot_props = regionprops(np.squeeze(labels)) + if self.is_volume: + spot_props = regionprops(labels) + else: + spot_props = regionprops(np.squeeze(labels)) # mask spots whose areas are too small or too large for spot_prop in spot_props: From 3f74d60e98d1b91e80a1f020e4c20f32c6820484 Mon Sep 17 00:00:00 2001 From: Matt Cai Date: Tue, 24 Mar 2020 14:23:29 -0700 Subject: [PATCH 3/6] added note LocalMaxPeakFinder on 3D data with is_volume=True is slow --- examples/how_to/local_max_peak_finder.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/how_to/local_max_peak_finder.py b/examples/how_to/local_max_peak_finder.py index bad010eb1..e9db8002c 100644 --- a/examples/how_to/local_max_peak_finder.py +++ b/examples/how_to/local_max_peak_finder.py @@ -25,6 +25,10 @@ :ref:`visually assess ` results. Each peak is counted as a spot with radius equal to one pixel. +.. note:: + Running :py:class:`.LocalMaxPeakFinder` on 3-Dimensional images with ``is_volume=True`` can + be extremely slow. + .. warning:: :py:class:`.LocalMaxPeakFinder` is not compatible with cropped data sets. From d6cf91541e89f169f22441ed5796d0b88f33f109 Mon Sep 17 00:00:00 2001 From: Matt Cai Date: Tue, 24 Mar 2020 15:51:52 -0700 Subject: [PATCH 4/6] removed unnecessary code --- examples/how_to/local_max_peak_finder.py | 28 +---------------------- expression | Bin 1360 -> 1360 bytes 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/examples/how_to/local_max_peak_finder.py b/examples/how_to/local_max_peak_finder.py index e9db8002c..22e48f4b2 100644 --- a/examples/how_to/local_max_peak_finder.py +++ b/examples/how_to/local_max_peak_finder.py @@ -59,30 +59,4 @@ max_obj_area=600, is_volume=False ) -spots = lmp.run(max_imgs) - - -from starfish.core.spots.DecodeSpots.trace_builders import build_traces_sequential -table = build_traces_sequential(spots) - -# plot spots found -import matplotlib -import matplotlib.pyplot as plt -from starfish.util.plot import imshow_plane - -# get x, y coords from intensity table -def get_cropped_coords(table, x_min, x_max, y_min, y_max): - df = table.to_features_dataframe() - df = df.loc[df['x'].between(x_min, x_max) & df['y'].between(y_min, y_max)] - return df['x'].values-x_min, df['y'].values-y_min, df['radius'].values.astype(int) -lmp_x, lmp_y, lmp_s = get_cropped_coords(lmp_table, 0, 500, 0, 500) - -matplotlib.rcParams["figure.dpi"] = 150 -f, (ax1, ax2, ax3) = plt.subplots(ncols=3) - -# Plot cropped region of max z-projected dots image -imshow_plane(max_imgs, sel={Axes.X: (0, 500), Axes.Y: (0, 500)}, ax=ax1, title='BlobDetector') -imshow_plane(max_imgs, sel={Axes.X: (0, 500), Axes.Y: (0, 500)}, ax=ax2, title='LocalMaxPeak') -imshow_plane(max_imgs, sel={Axes.X: (0, 500), Axes.Y: (0, 500)}, ax=ax3, title='Trackpy') -# Overlay spots found by each FindSpotsAlgorithm -ax1.scatter(lmp_x, lmp_y, marker='o', facecolors='none', edgecolors='r', s=lmp_s*10) \ No newline at end of file +spots = lmp.run(max_imgs) \ No newline at end of file diff --git a/expression b/expression index 7a08cf6b39b73c072ca613d9fce9b8b77d1447cd..a409620156abc885118fdd883f78bd302eb5c78a 100644 GIT binary patch delta 332 zcmcb>b%ATb6rBo%#G=$hg(`)-(%hufqWJu@_|m+T)a3k>)Rg$*g8Y(Vg-V6w)SR67 z%#@7>beJalFdIycXW^Kv!z?jbhFJj2&S4Rl9K*~36R&sB-}3mx*Ugt5+^TPX4^eY; zu$S1l)9;nBgP*_?QK#7l9KwV=6IwoNI0Uw?@9-7hH_`AR$Z_2o`I{vy^P{Eg{%F}5xTtG#pDvWvqVtouzK z-8l2l!TpW-Ox6oZ5)M97-wGFpw>t!WP|Egkv~UPYZ&{h}W2%GqhmT7yKQMKe?8_`Z z*@i^{hy^Am0KL<~;xV}gNS|Q|He_L7U|<7c4j|?NVs0Sj0b*Vt764*FAQpCa^>dAP H1d~nx{zr7a delta 310 zcmcb>b%ATb6roCmDuoJ#ZgS29w_~Nld=a!ZDeJ zSz_`RAo~v!2blkbNn^4Ji(q|-=R;q9omCD&2@4i4ej4RqBDSolzx$Mf*BMFPW4C8G z1gGpOb?o2fAaTR?{;s;k4iWqhFRyu};$XNtXSLK{W1v3QJRPU)4uO8tyr*Bi@8J22 z?bZ4jHV&T8-O|G&|2c%ddc2`!^?Zj=r-{B-+b%h{&SHA%eD0}3fI#u~Yd^dU14vjZ^)5OV@CHxTmyF+UIs0I{IEtDkGUBbamo075Ho3jhEB From 40d8c1333edc89e92ba0d18e5dd68844abd0efe6 Mon Sep 17 00:00:00 2001 From: mattcai <39178165+mattcai@users.noreply.github.com> Date: Tue, 24 Mar 2020 16:38:22 -0700 Subject: [PATCH 5/6] Update local_max_peak_finder.py --- examples/how_to/local_max_peak_finder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/how_to/local_max_peak_finder.py b/examples/how_to/local_max_peak_finder.py index 22e48f4b2..547c92746 100644 --- a/examples/how_to/local_max_peak_finder.py +++ b/examples/how_to/local_max_peak_finder.py @@ -59,4 +59,4 @@ max_obj_area=600, is_volume=False ) -spots = lmp.run(max_imgs) \ No newline at end of file +spots = lmp.run(max_imgs) From a00ea73c7127768846d33550783f174f0a5372fc Mon Sep 17 00:00:00 2001 From: mattcai <39178165+mattcai@users.noreply.github.com> Date: Thu, 23 Jul 2020 15:34:12 -0700 Subject: [PATCH 6/6] Delete expression --- expression | Bin 1360 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 expression diff --git a/expression b/expression deleted file mode 100644 index a409620156abc885118fdd883f78bd302eb5c78a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1360 zcmZ>EabseD04^ZK48*L-sW~~t2r<_5)Vx$EAEcJOxTGjEFWn5Jf(@b!OmYKB4j>jx zttco;EiTT?&x_AZ1gfooD1zC;2;}krF^JEdoS$Eml9`uS0^@3RBm~#hYP8G%Gu;>7d zU;%|1$UKN~KBV1p-zV2+hD?{{hB=&@euXMwKOBJ*nn7=x=#^ z;_K$i4sO-AzlW$fI@n8W-0Anq*uhWWiKx@;0}f$Ao(V0VH5>w4*LV1eZ*mB>KeGAx zhf)Wb?h`V<)=hQ@cGFCjj(qN5=01C(>4``O{VC}O;(VnY{Q7dI9)A(*5dOyWyBJ%S zgVo+SZP~@)4%Yo9k8Yg#=ivUvd?xD!2?w94Z-tA)+Z_TwC}sONS~vuyx2#O~G1bBQ z!^fqUADB8o0|wn+FmYJ85t4_ggXK|b(J*tVNQ2TNsEh-ZYoPKGRK|hQ6E6@80I?tt O3%k4exyCz!NhbiYe9xr-