Mercurial > repos > imgteam > spot_detection_2d
annotate spot_detection_2d.py @ 4:d77f71572fc4 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:22 +0000 |
parents | a58d8f8149e1 |
children |
rev | line source |
---|---|
0
ba44bc2a0928
"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
a58d8f8149e1
"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. |
4
d77f71572fc4
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: |
d77f71572fc4
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) |
d77f71572fc4
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
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
6 |
ba44bc2a0928
"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. |
ba44bc2a0928
"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 |
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
9 """ |
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
10 |
ba44bc2a0928
"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 |
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
12 |
4
d77f71572fc4
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
ba44bc2a0928
"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 |
ba44bc2a0928
"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 |
4
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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 = { |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
25 |
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
26 |
4
d77f71572fc4
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: |
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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: |
d77f71572fc4
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]) |
d77f71572fc4
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: |
d77f71572fc4
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) |
d77f71572fc4
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 |
d77f71572fc4
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) |
d77f71572fc4
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
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
37 |
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
38 |
4
d77f71572fc4
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( |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
51 |
4
d77f71572fc4
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) |
d77f71572fc4
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
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
54 |
4
d77f71572fc4
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) |
d77f71572fc4
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) |
d77f71572fc4
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: |
d77f71572fc4
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) |
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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:] |
d77f71572fc4
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: |
d77f71572fc4
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
2f2d46f89418
"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 |
4
d77f71572fc4
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 |
d77f71572fc4
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() |
d77f71572fc4
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()] |
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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() |
d77f71572fc4
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): |
d77f71572fc4
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) |
d77f71572fc4
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: |
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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: |
d77f71572fc4
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
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
81 |
4
d77f71572fc4
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 |
d77f71572fc4
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 |
d77f71572fc4
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)) |
d77f71572fc4
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( |
d77f71572fc4
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 { |
d77f71572fc4
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, |
d77f71572fc4
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), |
d77f71572fc4
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), |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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 } |
d77f71572fc4
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
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
95 |
4
d77f71572fc4
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 |
d77f71572fc4
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
ba44bc2a0928
"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") |
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
99 |
ba44bc2a0928
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/spot_detection_2d/ commit 481cd51a76341c0ec3759f919454e95139f0cc4e"
imgteam
parents:
diff
changeset
|
100 |
ba44bc2a0928
"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__": |
4
d77f71572fc4
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
2f2d46f89418
"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") |
4
d77f71572fc4
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 |
d77f71572fc4
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.") |
d77f71572fc4
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.") |
d77f71572fc4
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).") |
d77f71572fc4
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).") |
d77f71572fc4
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") |
d77f71572fc4
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.") |
d77f71572fc4
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.") |
d77f71572fc4
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=( |
d77f71572fc4
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. " |
d77f71572fc4
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.") |
d77f71572fc4
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 ) |
d77f71572fc4
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=( |
d77f71572fc4
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. " |
d77f71572fc4
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.") |
d77f71572fc4
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 ) |
d77f71572fc4
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.") |
d77f71572fc4
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
ba44bc2a0928
"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
2f2d46f89418
"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, |
2f2d46f89418
"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, |
4
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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, |
d77f71572fc4
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) |