Mercurial > repos > imgteam > spot_detection_2d
changeset 1:859dd1c11ac0 draft
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 9f103372d66ae7e3c5c385bd444b2a80e51cdae6"
author | imgteam |
---|---|
date | Sat, 19 Feb 2022 20:43:29 +0000 |
parents | d78372040976 |
children | 4645b356bf3b |
files | spot_detection_2d.py spot_detection_2d.xml |
diffstat | 2 files changed, 34 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/spot_detection_2d.py Wed Jul 21 19:59:00 2021 +0000 +++ b/spot_detection_2d.py Sat Feb 19 20:43:29 2022 +0000 @@ -13,7 +13,7 @@ import numpy as np import pandas as pd from skimage.feature import peak_local_max -from skimage.filters import gaussian +from skimage.filters import gaussian, laplace def getbr(xy, img, nb, firstn): @@ -27,7 +27,9 @@ return br -def spot_detection(fn_in, fn_out, frame_1st=1, frame_end=0, typ_br='smoothed', th=10, ssig=1, bd=10): +def spot_detection(fn_in, fn_out, frame_1st=1, frame_end=0, + typ_filter='Gauss', ssig=1, th=10, + typ_br='smoothed', 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): @@ -40,6 +42,9 @@ txyb_all = np.array([]).reshape(0, 4) for i in range(frame_1st - 1, frame_end): tmp = np.copy(ims_smd[i, :, :]) + if typ_filter == 'LoG': + tmp = laplace(tmp) + 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) | @@ -66,21 +71,18 @@ if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Spot detection based on local maxima") + parser = argparse.ArgumentParser(description="Spot detection") 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("filter", help="Detection filter") + parser.add_argument("ssig", type=float, help="Sigma of the Gaussian for noise suppression") + parser.add_argument("thres", type=float, help="Percentage of the global maximal for thresholding candidate spots") 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) + spot_detection(args.fn_in, args.fn_out, + frame_1st=args.frame_1st, frame_end=args.frame_end, + typ_filter=args.filter, ssig=args.ssig, th=args.thres, + typ_br=args.typ_intens, bd=args.bndy)
--- a/spot_detection_2d.xml Wed Jul 21 19:59:00 2021 +0000 +++ b/spot_detection_2d.xml Sat Feb 19 20:43:29 2022 +0000 @@ -1,21 +1,22 @@ -<tool id="ip_spot_detection_2d" name="Spot Detection" version="0.0.1" profile="20.05"> - <description>based on local intensity maxima</description> +<tool id="ip_spot_detection_2d" name="Spot Detection" version="0.0.2" profile="20.05"> + <description>in a 2D image (sequence)</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> + <command detect_errors="aggressive"> <![CDATA[ python '$__tool_directory__/spot_detection_2d.py' '$fn_in' '$fn_out' '$frame_1st' '$frame_end' - '$typ_intens' + '$filter' + '$ssig' '$thres' - '$ssig' + '$typ_intens' '$bndy' ]]> </command> @@ -23,13 +24,17 @@ <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="filter" type="select" label="Choose a detection filter"> + <option value="Gauss" selected="True">Gaussian</option> + <option value="LoG">Laplacian-of-Gaussian, LoG (more accurate when spots have similar sizes)</option> + </param> + <param name="ssig" type="float" value="1.0" min="0.5" max="10" label="Sigma of the Gaussian (for noise suppression)" /> + <param name="thres" type="float" value="10.0" min="0" max="100" label="Percentage of the global maximal as the threshold for candidate spots" /> <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)" /> + <param name="bndy" type="integer" value="10" min="0" max="50" label="Width (in pixel) of image boundaries where spots will be ignored" /> </inputs> <outputs> <data format="tabular" name="fn_out" /> @@ -39,9 +44,10 @@ <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="filter" value="Gauss"/> + <param name="ssig" value="1"/> <param name="thres" value="10"/> - <param name="ssig" value="1"/> + <param name="typ_intens" value="smoothed"/> <param name="bndy" value="10"/> <output name="fn_out" value="spots_detected.tsv" ftype="tabular" /> </test> @@ -49,6 +55,8 @@ <help> **What it does** - This tool detects spots and measures the intensities in a 2D image sequence based on local intensity maxima. + This tool detects spots and measures the intensities in a 2D image (sequence). </help> + <citations> + </citations> </tool>