Repository 'spot_detection_2d'
hg clone https://toolshed.g2.bx.psu.edu/repos/imgteam/spot_detection_2d

Changeset 0:d78372040976 (2021-07-21)
Next changeset 1:859dd1c11ac0 (2022-02-19)
Commit message:
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
added:
spot_detection_2d.py
spot_detection_2d.xml
test-data/spots_detected.tsv
test-data/test_img1.tif
b
diff -r 000000000000 -r d78372040976 spot_detection_2d.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spot_detection_2d.py Wed Jul 21 19:59:00 2021 +0000
[
@@ -0,0 +1,86 @@
+"""
+Copyright 2021 Biomedical Computer Vision Group, Heidelberg University.
+Author: Qi Gao (qi.gao@bioquant.uni-heidelberg.de)
+
+Distributed under the MIT license.
+See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
+
+"""
+
+import argparse
+
+import imageio
+import numpy as np
+import pandas as pd
+from skimage.feature import peak_local_max
+from skimage.filters import gaussian
+
+
+def getbr(xy, img, nb, firstn):
+    ndata = xy.shape[0]
+    br = np.empty((ndata, 1))
+    for j in range(ndata):
+        br[j] = np.NaN
+        if not np.isnan(xy[j, 0]):
+            timg = img[xy[j, 1] - nb - 1:xy[j, 1] + nb, xy[j, 0] - nb - 1:xy[j, 0] + nb]
+            br[j] = np.mean(np.sort(timg, axis=None)[-firstn:])
+    return br
+
+
+def spot_detection(fn_in, fn_out, frame_1st=1, frame_end=0, typ_br='smoothed', th=10, ssig=1, bd=10):
+    ims_ori = imageio.mimread(fn_in, format='TIFF')
+    ims_smd = np.zeros((len(ims_ori), ims_ori[0].shape[0], ims_ori[0].shape[1]), dtype='float64')
+    if frame_end == 0 or frame_end > len(ims_ori):
+        frame_end = len(ims_ori)
+
+    for i in range(frame_1st - 1, frame_end):
+        ims_smd[i, :, :] = gaussian(ims_ori[i].astype('float64'), sigma=ssig)
+    ims_smd_max = np.max(ims_smd)
+
+    txyb_all = np.array([]).reshape(0, 4)
+    for i in range(frame_1st - 1, frame_end):
+        tmp = np.copy(ims_smd[i, :, :])
+        tmp[tmp < th * ims_smd_max / 100] = 0
+        coords = peak_local_max(tmp, min_distance=1)
+        idx_to_del = np.where((coords[:, 0] <= bd) | (coords[:, 0] >= tmp.shape[0] - bd) |
+                              (coords[:, 1] <= bd) | (coords[:, 1] >= tmp.shape[1] - bd))
+        coords = np.delete(coords, idx_to_del[0], axis=0)
+        xys = coords[:, ::-1]
+
+        if typ_br == 'smoothed':
+            intens = getbr(xys, ims_smd[i, :, :], 0, 1)
+        elif typ_br == 'robust':
+            intens = getbr(xys, ims_ori[i], 1, 4)
+        else:
+            intens = getbr(xys, ims_ori[i], 0, 1)
+
+        txyb = np.concatenate(((i + 1) * np.ones((xys.shape[0], 1)), xys, intens), axis=1)
+        txyb_all = np.concatenate((txyb_all, txyb), axis=0)
+
+    df = pd.DataFrame()
+    df['FRAME'] = txyb_all[:, 0].astype(int)
+    df['POS_X'] = txyb_all[:, 1].astype(int)
+    df['POS_Y'] = txyb_all[:, 2].astype(int)
+    df['INTENSITY'] = txyb_all[:, 3]
+    df.to_csv(fn_out, index=False, float_format='%.2f', sep="\t")
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Spot detection based on local maxima")
+    parser.add_argument("fn_in", help="Name of input image sequence (stack)")
+    parser.add_argument("fn_out", help="Name of output file to save the coordinates and intensities of detected spots")
+    parser.add_argument("frame_1st", type=int, help="Index for the starting frame to detect spots (1 for first frame of the stack)")
+    parser.add_argument("frame_end", type=int, help="Index for the last frame to detect spots (0 for the last frame of the stack)")
+    parser.add_argument("typ_intens", help="smoothed or robust (for measuring the intensities of spots)")
+    parser.add_argument("thres", type=float, help="Percentage of the global maximal intensity for thresholding candidate spots")
+    parser.add_argument("ssig", type=float, help="Sigma of the Gaussian filter for noise suppression")
+    parser.add_argument("bndy", type=int, help="Number of pixels (Spots close to image boundaries will be ignored)")
+    args = parser.parse_args()
+    spot_detection(args.fn_in,
+                   args.fn_out,
+                   frame_1st=args.frame_1st,
+                   frame_end=args.frame_end,
+                   typ_br=args.typ_intens,
+                   th=args.thres,
+                   ssig=args.ssig,
+                   bd=args.bndy)
b
diff -r 000000000000 -r d78372040976 spot_detection_2d.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spot_detection_2d.xml Wed Jul 21 19:59:00 2021 +0000
[
@@ -0,0 +1,54 @@
+<tool id="ip_spot_detection_2d" name="Spot Detection" version="0.0.1" profile="20.05"> 
+    <description>based on local intensity maxima</description>
+    <requirements>
+        <requirement type="package" version="2.9.0">imageio</requirement>
+        <requirement type="package" version="1.20.2">numpy</requirement>
+        <requirement type="package" version="1.2.4">pandas</requirement>
+        <requirement type="package" version="0.18.1">scikit-image</requirement>
+    </requirements>
+    <command>
+    <![CDATA[
+         python '$__tool_directory__/spot_detection_2d.py'
+         '$fn_in'
+         '$fn_out'
+         '$frame_1st'
+         '$frame_end'
+         '$typ_intens'
+         '$thres'
+         '$ssig'
+         '$bndy'
+    ]]>
+    </command>
+    <inputs>
+        <param name="fn_in" type="data" format="tiff" label="Image sequence (stack)" />
+        <param name="frame_1st" type="integer" value="1" label="Starting time point (1 for the first frame of the stack)" />
+        <param name="frame_end" type="integer" value="0" label="Ending time point (0 for the last frame of the stack)" />
+        <param name="typ_intens" type="select" label="How to measure the intensities">
+            <option value="smoothed" selected="True">Smoothed</option>
+            <option value="robust">Robust</option>
+        </param>
+        <param name="thres" type="float" value="10" label="Percentage of the global maximal intensity as the threshold for candidate spots" />
+        <param name="ssig" type="float" value="1" label="Sigma of the Gaussian filter for noise suppression" />
+        <param name="bndy" type="integer" value="10" label="Number of pixels (Spots within n-pixel image boundaries will be ignored)" />
+    </inputs>
+    <outputs>
+        <data format="tabular" name="fn_out" />
+    </outputs>
+    <tests>
+        <test>
+            <param name="fn_in" value="test_img1.tif"/>
+            <param name="frame_1st" value="1"/>
+            <param name="frame_end" value="0"/>
+            <param name="typ_intens" value="smoothed"/>
+            <param name="thres" value="10"/>
+            <param name="ssig" value="1"/>
+            <param name="bndy" value="10"/>
+            <output name="fn_out" value="spots_detected.tsv" ftype="tabular" />
+        </test>
+    </tests>
+    <help>
+    **What it does**
+
+    This tool detects spots and measures the intensities in a 2D image sequence based on local intensity maxima.
+    </help>
+</tool>
b
diff -r 000000000000 -r d78372040976 test-data/spots_detected.tsv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/spots_detected.tsv Wed Jul 21 19:59:00 2021 +0000
b
b'@@ -0,0 +1,462 @@\n+FRAME\tPOS_X\tPOS_Y\tINTENSITY\n+1\t126\t202\t55939.36\n+1\t218\t227\t41590.82\n+1\t132\t201\t41849.38\n+1\t120\t199\t45491.74\n+1\t113\t177\t27103.64\n+1\t95\t135\t33206.37\n+1\t130\t209\t36872.91\n+1\t128\t170\t30994.56\n+1\t315\t240\t38767.19\n+1\t123\t195\t32988.47\n+1\t117\t181\t40031.76\n+1\t118\t184\t36812.77\n+1\t127\t181\t29651.66\n+1\t134\t192\t28531.76\n+1\t137\t189\t35093.95\n+1\t195\t223\t30206.57\n+1\t78\t87\t30367.18\n+1\t146\t195\t26779.82\n+1\t175\t225\t28515.74\n+1\t213\t227\t30812.06\n+1\t114\t158\t31229.97\n+1\t171\t223\t26982.37\n+1\t87\t117\t27143.89\n+1\t129\t194\t29475.93\n+1\t115\t192\t28510.64\n+1\t248\t230\t22615.54\n+1\t154\t208\t26394.30\n+1\t109\t153\t26268.78\n+1\t328\t234\t26387.65\n+1\t138\t179\t20215.40\n+1\t159\t212\t24400.22\n+1\t335\t233\t21698.80\n+1\t387\t198\t24933.29\n+1\t121\t154\t18710.45\n+1\t308\t239\t22328.27\n+1\t258\t230\t18680.93\n+1\t340\t229\t15937.72\n+1\t78\t78\t18151.49\n+1\t81\t80\t24704.83\n+1\t117\t161\t24293.65\n+1\t120\t164\t24242.78\n+1\t160\t215\t23759.44\n+1\t86\t141\t10949.28\n+1\t222\t230\t22277.61\n+1\t370\t215\t18379.39\n+1\t109\t199\t18850.01\n+1\t83\t109\t15871.12\n+1\t117\t155\t15703.14\n+1\t100\t182\t17281.91\n+1\t168\t227\t17431.67\n+1\t392\t197\t15897.67\n+1\t184\t227\t11346.34\n+1\t294\t237\t10236.84\n+1\t377\t210\t15642.67\n+1\t152\t226\t9851.10\n+1\t93\t145\t12584.04\n+1\t147\t212\t14735.83\n+1\t80\t101\t11021.47\n+1\t394\t193\t14063.18\n+1\t105\t139\t12039.57\n+1\t301\t237\t11466.69\n+1\t273\t233\t8421.28\n+1\t111\t170\t14406.46\n+1\t237\t228\t9466.36\n+1\t106\t206\t14522.55\n+1\t83\t75\t11115.23\n+1\t290\t238\t12636.07\n+1\t205\t229\t12808.78\n+1\t381\t207\t11531.86\n+1\t92\t196\t9024.83\n+1\t185\t222\t11196.17\n+1\t180\t221\t8339.93\n+1\t146\t185\t7207.70\n+1\t142\t209\t11730.52\n+1\t88\t101\t10415.08\n+1\t235\t231\t11264.22\n+1\t85\t103\t5911.48\n+1\t104\t183\t8101.94\n+1\t85\t148\t7290.63\n+1\t145\t189\t9776.95\n+1\t361\t219\t7009.70\n+1\t282\t236\t8853.80\n+1\t121\t169\t7733.35\n+1\t107\t180\t8135.17\n+1\t266\t235\t7470.55\n+1\t79\t96\t6920.43\n+1\t152\t219\t5623.45\n+1\t149\t220\t5889.31\n+2\t126\t202\t59098.11\n+2\t126\t205\t53383.42\n+2\t218\t227\t46745.07\n+2\t120\t199\t43055.88\n+2\t116\t180\t45577.81\n+2\t127\t181\t42874.19\n+2\t130\t209\t41387.22\n+2\t123\t195\t33569.00\n+2\t113\t177\t31339.11\n+2\t128\t170\t35552.32\n+2\t135\t191\t30546.65\n+2\t95\t136\t34169.11\n+2\t315\t238\t31430.32\n+2\t314\t240\t30015.35\n+2\t116\t201\t26928.89\n+2\t196\t223\t29118.84\n+2\t175\t225\t29053.82\n+2\t213\t227\t34704.93\n+2\t115\t159\t29750.71\n+2\t146\t195\t27597.86\n+2\t328\t234\t28969.08\n+2\t113\t191\t25325.73\n+2\t79\t87\t27998.19\n+2\t340\t229\t19788.22\n+2\t154\t207\t25348.79\n+2\t81\t81\t25643.11\n+2\t172\t224\t25762.85\n+2\t87\t117\t24830.46\n+2\t169\t222\t19415.52\n+2\t325\t232\t23879.48\n+2\t248\t230\t23270.45\n+2\t110\t153\t24396.90\n+2\t387\t198\t23947.67\n+2\t87\t143\t16954.62\n+2\t118\t162\t26061.81\n+2\t78\t79\t23543.41\n+2\t258\t230\t16996.33\n+2\t121\t165\t22822.04\n+2\t387\t201\t25260.27\n+2\t335\t233\t19553.33\n+2\t223\t230\t22795.66\n+2\t159\t212\t20956.68\n+2\t370\t216\t19989.36\n+2\t320\t233\t13806.24\n+2\t308\t239\t17964.97\n+2\t105\t139\t18000.56\n+2\t109\t200\t17896.86\n+2\t83\t109\t16421.63\n+2\t105\t151\t17984.13\n+2\t137\t179\t12811.40\n+2\t110\t169\t14111.65\n+2\t228\t231\t18325.92\n+2\t392\t196\t14572.82\n+2\t153\t228\t14935.83\n+2\t122\t154\t11708.73\n+2\t83\t75\t13067.82\n+2\t153\t213\t16283.67\n+2\t295\t237\t9677.50\n+2\t377\t210\t13457.71\n+2\t273\t233\t9148.80\n+2\t205\t229\t13083.06\n+2\t381\t206\t10603.41\n+2\t80\t101\t9485.05\n+2\t152\t202\t15278.04\n+2\t185\t226\t11093.24\n+2\t161\t216\t15543.22\n+2\t146\t212\t14364.79\n+2\t235\t231\t12509.71\n+2\t290\t238\t13411.96\n+2\t93\t145\t9119.49\n+2\t142\t210\t13054.23\n+2\t239\t232\t13043.98\n+2\t92\t196\t10749.96\n+2\t185\t221\t9922.40\n+2\t299\t238\t13577.34\n+2\t278\t235\t11194.38\n+2\t100\t182\t11485.41\n+2\t145\t189\t11315.24\n+2\t237\t228\t11272.61\n+2\t107\t189\t8051.49\n+2\t87\t101\t8814.45\n+2\t146\t186\t7585.02\n+2\t106\t207\t8720.64\n+2\t109\t207\t7676.81\n+2\t402\t188\t7813.91\n+2\t88\t108\t7921.85\n+2\t360\t220\t7726.74\n+2\t86\t148\t7184.91\n+2\t106\t180\t8401.49\n+2\t95\t173\t4093.76\n+2\t266\t235\t5678.52\n+2\t122\t172\t5731.76\n+2\t127\t218\t4787.41\n+3\t126\t206\t56658.14\n+3\t126\t202\t54234.74\n+3\t218\t226\t35022.37\n+3\t119\t200\t40576.02\n+3\t133\t201\t44149.96\n+3\t115\t178\t43820.79\n+3\t124\t196\t41934.96\n+3\t117\t180\t43996.85\n+3\t130\t209\t42016.60\n+3\t136\t190\t39500.63\n+3\t316\t237\t31963.21\n+3\t97\t137\t36182.78\n+3\t127\t181\t31990.16\n+3\t119\t184\t34251.83\n+3\t114\t158\t29844.61\n+3\t146\t196\t37064.84\n+3\t128\t186\t34532.76\n+3\t176\t225\t30746.00\n+3\t196\t223\t29807.10\n+3\t213\t226\t25523.49\n+3\t128\t17'..b'34\t231\t13284.28\n+3\t236\t228\t8838.32\n+3\t106\t207\t10942.68\n+3\t381\t206\t8704.24\n+3\t238\t231\t13112.03\n+3\t109\t169\t9573.93\n+3\t88\t101\t9934.59\n+3\t104\t183\t7882.07\n+3\t85\t103\t8202.08\n+3\t361\t219\t7171.66\n+3\t278\t235\t10260.85\n+3\t268\t235\t8025.01\n+3\t146\t188\t9096.57\n+3\t283\t236\t9090.54\n+3\t399\t190\t6873.99\n+3\t145\t185\t6134.20\n+3\t105\t179\t6141.86\n+3\t97\t176\t6082.70\n+3\t110\t207\t4505.63\n+3\t127\t219\t5028.42\n+3\t94\t171\t6146.80\n+4\t126\t202\t55939.36\n+4\t218\t227\t41590.82\n+4\t132\t201\t41849.38\n+4\t120\t199\t45491.74\n+4\t113\t177\t27103.64\n+4\t95\t135\t33206.37\n+4\t130\t209\t36872.91\n+4\t128\t170\t30994.56\n+4\t315\t240\t38767.19\n+4\t123\t195\t32988.47\n+4\t117\t181\t40031.76\n+4\t118\t184\t36812.77\n+4\t127\t181\t29651.66\n+4\t134\t192\t28531.76\n+4\t137\t189\t35093.95\n+4\t195\t223\t30206.57\n+4\t78\t87\t30367.18\n+4\t146\t195\t26779.82\n+4\t175\t225\t28515.74\n+4\t213\t227\t30812.06\n+4\t114\t158\t31229.97\n+4\t171\t223\t26982.37\n+4\t87\t117\t27143.89\n+4\t129\t194\t29475.93\n+4\t115\t192\t28510.64\n+4\t248\t230\t22615.54\n+4\t154\t208\t26394.30\n+4\t109\t153\t26268.78\n+4\t328\t234\t26387.65\n+4\t138\t179\t20215.40\n+4\t159\t212\t24400.22\n+4\t335\t233\t21698.80\n+4\t387\t198\t24933.29\n+4\t121\t154\t18710.45\n+4\t308\t239\t22328.27\n+4\t258\t230\t18680.93\n+4\t340\t229\t15937.72\n+4\t78\t78\t18151.49\n+4\t81\t80\t24704.83\n+4\t117\t161\t24293.65\n+4\t120\t164\t24242.78\n+4\t160\t215\t23759.44\n+4\t86\t141\t10949.28\n+4\t222\t230\t22277.61\n+4\t370\t215\t18379.39\n+4\t109\t199\t18850.01\n+4\t83\t109\t15871.12\n+4\t117\t155\t15703.14\n+4\t100\t182\t17281.91\n+4\t168\t227\t17431.67\n+4\t392\t197\t15897.67\n+4\t184\t227\t11346.34\n+4\t294\t237\t10236.84\n+4\t377\t210\t15642.67\n+4\t152\t226\t9851.10\n+4\t93\t145\t12584.04\n+4\t147\t212\t14735.83\n+4\t80\t101\t11021.47\n+4\t394\t193\t14063.18\n+4\t105\t139\t12039.57\n+4\t301\t237\t11466.69\n+4\t273\t233\t8421.28\n+4\t111\t170\t14406.46\n+4\t237\t228\t9466.36\n+4\t106\t206\t14522.55\n+4\t83\t75\t11115.23\n+4\t290\t238\t12636.07\n+4\t205\t229\t12808.78\n+4\t381\t207\t11531.86\n+4\t92\t196\t9024.83\n+4\t185\t222\t11196.17\n+4\t180\t221\t8339.93\n+4\t146\t185\t7207.70\n+4\t142\t209\t11730.52\n+4\t88\t101\t10415.08\n+4\t235\t231\t11264.22\n+4\t85\t103\t5911.48\n+4\t104\t183\t8101.94\n+4\t85\t148\t7290.63\n+4\t145\t189\t9776.95\n+4\t361\t219\t7009.70\n+4\t282\t236\t8853.80\n+4\t121\t169\t7733.35\n+4\t107\t180\t8135.17\n+4\t266\t235\t7470.55\n+4\t79\t96\t6920.43\n+4\t152\t219\t5623.45\n+4\t149\t220\t5889.31\n+5\t126\t206\t56658.14\n+5\t126\t202\t54234.74\n+5\t218\t226\t35022.37\n+5\t119\t200\t40576.02\n+5\t133\t201\t44149.96\n+5\t115\t178\t43820.79\n+5\t124\t196\t41934.96\n+5\t117\t180\t43996.85\n+5\t130\t209\t42016.60\n+5\t136\t190\t39500.63\n+5\t316\t237\t31963.21\n+5\t97\t137\t36182.78\n+5\t127\t181\t31990.16\n+5\t119\t184\t34251.83\n+5\t114\t158\t29844.61\n+5\t146\t196\t37064.84\n+5\t128\t186\t34532.76\n+5\t176\t225\t30746.00\n+5\t196\t223\t29807.10\n+5\t213\t226\t25523.49\n+5\t128\t171\t28664.10\n+5\t152\t204\t24687.37\n+5\t329\t234\t28277.06\n+5\t78\t87\t26725.30\n+5\t81\t87\t30473.18\n+5\t172\t225\t26643.89\n+5\t120\t163\t26474.56\n+5\t387\t197\t21111.91\n+5\t86\t117\t20367.28\n+5\t335\t233\t20895.73\n+5\t324\t232\t23086.43\n+5\t339\t229\t15275.48\n+5\t129\t194\t24033.17\n+5\t123\t185\t24073.76\n+5\t77\t79\t19152.47\n+5\t169\t222\t17195.61\n+5\t132\t175\t25123.86\n+5\t81\t81\t24895.65\n+5\t109\t153\t21172.27\n+5\t117\t161\t24299.24\n+5\t307\t240\t19257.85\n+5\t370\t215\t18554.16\n+5\t222\t230\t22017.20\n+5\t104\t139\t20194.29\n+5\t248\t230\t23396.01\n+5\t257\t230\t17273.50\n+5\t116\t154\t15659.69\n+5\t114\t190\t21449.57\n+5\t158\t211\t18454.95\n+5\t83\t109\t17776.43\n+5\t84\t75\t15659.83\n+5\t158\t215\t19800.41\n+5\t109\t199\t15805.24\n+5\t101\t140\t20715.26\n+5\t143\t210\t20769.18\n+5\t88\t144\t20132.54\n+5\t93\t145\t12670.17\n+5\t228\t231\t19053.86\n+5\t393\t195\t13463.33\n+5\t80\t101\t13305.58\n+5\t105\t151\t15913.95\n+5\t137\t179\t15719.37\n+5\t167\t226\t17465.42\n+5\t293\t238\t15459.81\n+5\t377\t209\t10830.81\n+5\t185\t222\t13711.26\n+5\t108\t189\t16955.73\n+5\t185\t226\t12648.79\n+5\t153\t227\t14010.45\n+5\t101\t186\t14180.61\n+5\t298\t238\t16257.78\n+5\t121\t189\t14906.88\n+5\t151\t210\t12848.29\n+5\t274\t233\t11026.17\n+5\t93\t197\t14149.59\n+5\t234\t231\t13284.28\n+5\t236\t228\t8838.32\n+5\t106\t207\t10942.68\n+5\t381\t206\t8704.24\n+5\t238\t231\t13112.03\n+5\t109\t169\t9573.93\n+5\t88\t101\t9934.59\n+5\t104\t183\t7882.07\n+5\t85\t103\t8202.08\n+5\t361\t219\t7171.66\n+5\t278\t235\t10260.85\n+5\t268\t235\t8025.01\n+5\t146\t188\t9096.57\n+5\t283\t236\t9090.54\n+5\t399\t190\t6873.99\n+5\t145\t185\t6134.20\n+5\t105\t179\t6141.86\n+5\t97\t176\t6082.70\n+5\t110\t207\t4505.63\n+5\t127\t219\t5028.42\n+5\t94\t171\t6146.80\n'
b
diff -r 000000000000 -r d78372040976 test-data/test_img1.tif
b
Binary file test-data/test_img1.tif has changed