Mercurial > repos > imgteam > spot_detection_2d
annotate spot_detection_2d.py @ 5:e8c9e104e109 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
author | imgteam |
---|---|
date | Wed, 25 Sep 2024 08:19:30 +0000 |
parents | 4645b356bf3b |
children |
rev | line source |
---|---|
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
1 """ |
2
4645b356bf3b
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents:
1
diff
changeset
|
2 Copyright 2021-2022 Biomedical Computer Vision Group, Heidelberg University. |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
3 Authors: |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
4 - Qi Gao (qi.gao@bioquant.uni-heidelberg.de) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
5 - Leonid Kostrykin (leonid.kostrykin@bioquant.uni-heidelberg.de) |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
6 |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
7 Distributed under the MIT license. |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
8 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
9 """ |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
10 |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
11 import argparse |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
12 |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
13 import giatools.io |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
14 import numpy as np |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
15 import pandas as pd |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
16 import scipy.ndimage as ndi |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
17 from numpy.typing import NDArray |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
18 from skimage.feature import blob_dog, blob_doh, blob_log |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
19 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
20 blob_filters = { |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
21 'dog': blob_dog, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
22 'doh': blob_doh, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
23 'log': blob_log, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
24 } |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
25 |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
26 |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
27 def mean_intensity(img: NDArray, y: int, x: int, radius: int) -> float: |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
28 assert img.ndim == 2 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
29 assert radius >= 0 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
30 if radius == 0: |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
31 return float(img[y, x]) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
32 else: |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
33 mask = np.ones(img.shape, bool) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
34 mask[y, x] = False |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
35 mask = (ndi.distance_transform_edt(mask) <= radius) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
36 return img[mask].mean() |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
37 |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
38 |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
39 def spot_detection( |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
40 fn_in: str, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
41 fn_out: str, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
42 frame_1st: int, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
43 frame_end: int, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
44 filter_type: str, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
45 min_scale: float, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
46 max_scale: float, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
47 abs_threshold: float, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
48 rel_threshold: float, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
49 boundary: int, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
50 ) -> None: |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
51 |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
52 # Load the single-channel 2-D input image (or stack thereof) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
53 stack = giatools.io.imread(fn_in) |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
54 |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
55 # Normalize input image so that it is a stack of images (possibly a stack of a single image) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
56 assert stack.ndim in (2, 3) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
57 if stack.ndim == 2: |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
58 stack = stack.reshape(1, *stack.shape) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
59 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
60 # Slice the stack |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
61 assert frame_1st >= 1 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
62 assert frame_end >= 0 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
63 stack = stack[frame_1st - 1:] |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
64 if frame_end > 0: |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
65 stack = stack[:-frame_end] |
1
859dd1c11ac0
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 9f103372d66ae7e3c5c385bd444b2a80e51cdae6"
imgteam
parents:
0
diff
changeset
|
66 |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
67 # Select the blob detection filter |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
68 assert filter_type.lower() in blob_filters.keys() |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
69 blob_filter = blob_filters[filter_type.lower()] |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
70 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
71 # Perform blob detection on each image of the stack |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
72 detections = list() |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
73 for img_idx, img in enumerate(stack): |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
74 blobs = blob_filter(img, threshold=abs_threshold, threshold_rel=rel_threshold, min_sigma=min_scale, max_sigma=max_scale) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
75 for blob in blobs: |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
76 y, x, scale = blob |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
77 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
78 # Skip the detection if it is too close to the boundary of the image |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
79 if y < boundary or x < boundary or y >= img.shape[0] - boundary or x >= img.shape[1] - boundary: |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
80 continue |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
81 |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
82 # Add the detection to the list of detections |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
83 radius = scale * np.sqrt(2) * 2 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
84 intensity = mean_intensity(img, round(y), round(x), round(radius)) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
85 detections.append( |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
86 { |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
87 'frame': img_idx + 1, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
88 'pos_x': round(x), |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
89 'pos_y': round(y), |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
90 'scale': scale, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
91 'radius': radius, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
92 'intensity': intensity, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
93 } |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
94 ) |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
95 |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
96 # Build and save dataframe |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
97 df = pd.DataFrame.from_dict(detections) |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
98 df.to_csv(fn_out, index=False, float_format='%.2f', sep="\t") |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
99 |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
100 |
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
101 if __name__ == "__main__": |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
102 |
1
859dd1c11ac0
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 9f103372d66ae7e3c5c385bd444b2a80e51cdae6"
imgteam
parents:
0
diff
changeset
|
103 parser = argparse.ArgumentParser(description="Spot detection") |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
104 |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
105 parser.add_argument("fn_in", help="Name of input image or image stack.") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
106 parser.add_argument("fn_out", help="Name of output file to write the detections into.") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
107 parser.add_argument("frame_1st", type=int, help="Index for the starting frame to detect spots (1 for first frame of the stack).") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
108 parser.add_argument("frame_end", type=int, help="Index for the last frame to detect spots (0 for the last frame of the stack).") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
109 parser.add_argument("filter_type", help="Detection filter") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
110 parser.add_argument("min_scale", type=float, help="The minimum scale to consider for multi-scale detection.") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
111 parser.add_argument("max_scale", type=float, help="The maximum scale to consider for multi-scale detection.") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
112 parser.add_argument("abs_threshold", type=float, help=( |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
113 "Filter responses below this threshold will be ignored. Only filter responses above this thresholding will be considered as blobs. " |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
114 "This threshold is ignored if the relative threshold (below) corresponds to a higher response.") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
115 ) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
116 parser.add_argument("rel_threshold", type=float, help=( |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
117 "Same as the absolute threshold (above), but as a fraction of the overall maximal filter response of an image. " |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
118 "This threshold is ignored if it corresponds to a response below the absolute threshold.") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
119 ) |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
120 parser.add_argument("boundary", type=int, help="Width of image boundaries (in pixel) where spots will be ignored.") |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
121 |
0
d78372040976
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
122 args = parser.parse_args() |
1
859dd1c11ac0
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 9f103372d66ae7e3c5c385bd444b2a80e51cdae6"
imgteam
parents:
0
diff
changeset
|
123 spot_detection(args.fn_in, args.fn_out, |
859dd1c11ac0
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 9f103372d66ae7e3c5c385bd444b2a80e51cdae6"
imgteam
parents:
0
diff
changeset
|
124 frame_1st=args.frame_1st, frame_end=args.frame_end, |
5
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
125 filter_type=args.filter_type, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
126 min_scale=args.min_scale, max_scale=args.max_scale, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
127 abs_threshold=args.abs_threshold, rel_threshold=args.rel_threshold, |
e8c9e104e109
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit f1b9207ec23c0af1681c929281bcbf1d0638368e
imgteam
parents:
2
diff
changeset
|
128 boundary=args.boundary) |