Mercurial > repos > perssond > s3segmenter
annotate S3segmenter.py @ 0:37acf42a824b draft
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
author | perssond |
---|---|
date | Fri, 12 Mar 2021 00:18:40 +0000 |
parents | |
children | 41e8efe8df43 |
rev | line source |
---|---|
0
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
1 import matplotlib.pyplot as plt |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
2 import tifffile |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
3 import os |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
4 import numpy as np |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
5 from skimage import io as skio |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
6 from scipy.ndimage import * |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
7 import scipy.ndimage as ndi |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
8 from skimage.morphology import * |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
9 from skimage.morphology import extrema |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
10 from skimage import morphology |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
11 from skimage.measure import regionprops |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
12 from skimage.transform import resize |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
13 from skimage.filters import gaussian, threshold_otsu, threshold_local |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
14 from skimage.feature import peak_local_max |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
15 from skimage.color import label2rgb |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
16 from skimage.io import imsave,imread |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
17 from skimage.segmentation import clear_border, watershed, find_boundaries |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
18 from scipy.ndimage.filters import uniform_filter |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
19 from os.path import * |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
20 from os import listdir, makedirs, remove |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
21 import pickle |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
22 import shutil |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
23 import fnmatch |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
24 import cv2 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
25 import sys |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
26 import argparse |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
27 import re |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
28 import copy |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
29 import datetime |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
30 from joblib import Parallel, delayed |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
31 from rowit import WindowView, crop_with_padding_mask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
32 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
33 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
34 def imshowpair(A,B): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
35 plt.imshow(A,cmap='Purples') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
36 plt.imshow(B,cmap='Greens',alpha=0.5) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
37 plt.show() |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
38 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
39 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
40 def imshow(A): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
41 plt.imshow(A) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
42 plt.show() |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
43 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
44 def overlayOutline(outline,img): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
45 img2 = img.copy() |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
46 stacked_img = np.stack((img2,)*3, axis=-1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
47 stacked_img[outline > 0] = [65535, 0, 0] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
48 imshowpair(img2,stacked_img) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
49 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
50 def normI(I): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
51 Irs=resize(I,(I.shape[0]//10,I.shape[1]//10) ); |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
52 p1 = np.percentile(Irs,10); |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
53 J = I-p1; |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
54 p99 = np.percentile(Irs,99.99); |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
55 J = J/(p99-p1); |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
56 return J |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
57 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
58 def contour_pm_watershed( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
59 contour_pm, sigma=2, h=0, tissue_mask=None, |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
60 padding_mask=None, min_area=None, max_area=None |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
61 ): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
62 if tissue_mask is None: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
63 tissue_mask = np.ones_like(contour_pm) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
64 padded = None |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
65 if padding_mask is not None and np.any(padding_mask == 0): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
66 contour_pm, padded = crop_with_padding_mask( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
67 contour_pm, padding_mask, return_mask=True |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
68 ) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
69 tissue_mask = crop_with_padding_mask( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
70 tissue_mask, padding_mask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
71 ) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
72 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
73 maxima = peak_local_max( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
74 extrema.h_maxima( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
75 ndi.gaussian_filter(np.invert(contour_pm), sigma=sigma), |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
76 h=h |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
77 ), |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
78 indices=False, |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
79 footprint=np.ones((3, 3)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
80 ) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
81 maxima = label(maxima).astype(np.int32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
82 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
83 # Passing mask into the watershed function will exclude seeds outside |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
84 # of the mask, which gives fewer and more accurate segments |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
85 maxima = watershed( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
86 contour_pm, maxima, watershed_line=True, mask=tissue_mask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
87 ) > 0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
88 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
89 if min_area is not None and max_area is not None: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
90 maxima = label(maxima, connectivity=1).astype(np.int32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
91 areas = np.bincount(maxima.ravel()) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
92 size_passed = np.arange(areas.size)[ |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
93 np.logical_and(areas > min_area, areas < max_area) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
94 ] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
95 maxima *= np.isin(maxima, size_passed) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
96 np.greater(maxima, 0, out=maxima) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
97 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
98 if padded is None: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
99 return maxima.astype(np.bool) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
100 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
101 padded[padded == 1] = maxima.flatten() |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
102 return padded.astype(np.bool) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
103 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
104 def S3AreaSegmenter(nucleiPM, images, TMAmask, threshold,outputPath): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
105 nucleiCenters = nucleiPM[:,:,0] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
106 TMAmask= (nucleiCenters>np.amax(nucleiCenters)*0.8)*TMAmask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
107 area = [] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
108 area.append(np.sum(np.sum(TMAmask))) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
109 for iChan in range(len(images)): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
110 image_gauss = gaussian(resize(images[iChan,:,:],(int(0.25*images.shape[1]),int(0.25*images.shape[2]))),1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
111 if threshold ==-1: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
112 threshold = threshold_otsu(image_gauss) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
113 mask=resize(image_gauss>threshold,(images.shape[1],images.shape[2]),order = 0)*TMAmask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
114 area.append(np.sum(np.sum(mask))) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
115 np.savetxt(outputPath + os.path.sep + 'area.csv',(np.transpose(np.asarray(area))),fmt='%10.5f') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
116 return TMAmask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
117 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
118 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
119 def S3NucleiSegmentationWatershed(nucleiPM,nucleiImage,logSigma,TMAmask,nucleiFilter,nucleiRegion): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
120 nucleiContours = nucleiPM[:,:,1] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
121 nucleiCenters = nucleiPM[:,:,0] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
122 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
123 mask = resize(TMAmask,(nucleiImage.shape[0],nucleiImage.shape[1]),order = 0)>0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
124 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
125 if nucleiRegion == 'localThreshold': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
126 Imax = peak_local_max(extrema.h_maxima(255-nucleiContours,logSigma[0]),indices=False) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
127 Imax = label(Imax).astype(np.int32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
128 foregroundMask = watershed(nucleiContours, Imax, watershed_line=True) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
129 P = regionprops(foregroundMask, np.amax(nucleiCenters) - nucleiCenters - nucleiContours) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
130 prop_keys = ['mean_intensity', 'label','area'] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
131 def props_of_keys(prop, keys): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
132 return [prop[k] for k in keys] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
133 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
134 mean_ints, labels, areas = np.array(Parallel(n_jobs=6)(delayed(props_of_keys)(prop, prop_keys) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
135 for prop in P |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
136 ) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
137 ).T |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
138 del P |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
139 maxArea = (logSigma[1]**2)*3/4 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
140 minArea = (logSigma[0]**2)*3/4 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
141 passed = np.logical_and.reduce(( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
142 np.logical_and(areas > minArea, areas < maxArea), |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
143 np.less(mean_ints, 50) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
144 )) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
145 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
146 foregroundMask *= np.isin(foregroundMask, labels[passed]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
147 np.greater(foregroundMask, 0, out=foregroundMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
148 foregroundMask = label(foregroundMask, connectivity=1).astype(np.int32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
149 elif nucleiRegion =='bypass': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
150 foregroundMask = nucleiPM[:,:,0] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
151 P = regionprops(foregroundMask, nucleiImage) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
152 prop_keys = ['mean_intensity', 'label','area'] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
153 def props_of_keys(prop, keys): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
154 return [prop[k] for k in keys] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
155 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
156 mean_ints, labels, areas = np.array(Parallel(n_jobs=6)(delayed(props_of_keys)(prop, prop_keys) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
157 for prop in P |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
158 ) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
159 ).T |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
160 del P |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
161 maxArea = (logSigma[1]**2)*3/4 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
162 minArea = (logSigma[0]**2)*3/4 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
163 passed = np.logical_and(areas > minArea, areas < maxArea) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
164 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
165 foregroundMask *= np.isin(foregroundMask, labels[passed]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
166 np.greater(foregroundMask, 0, out=foregroundMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
167 foregroundMask = label(foregroundMask, connectivity=1).astype(np.int32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
168 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
169 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
170 if len(logSigma)==1: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
171 nucleiDiameter = [logSigma*0.5, logSigma*1.5] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
172 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
173 nucleiDiameter = logSigma |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
174 logMask = nucleiCenters > 150 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
175 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
176 win_view_setting = WindowView(nucleiContours.shape, 2000, 500) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
177 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
178 nucleiContours = win_view_setting.window_view_list(nucleiContours) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
179 padding_mask = win_view_setting.padding_mask() |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
180 mask = win_view_setting.window_view_list(mask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
181 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
182 maxArea = (logSigma[1]**2)*3/4 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
183 minArea = (logSigma[0]**2)*3/4 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
184 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
185 foregroundMask = np.array( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
186 Parallel(n_jobs=6)(delayed(contour_pm_watershed)( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
187 img, sigma=logSigma[1]/30, h=logSigma[1]/30, tissue_mask=tm, |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
188 padding_mask=m, min_area=minArea, max_area=maxArea |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
189 ) for img, tm, m in zip(nucleiContours, mask, padding_mask)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
190 ) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
191 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
192 del nucleiContours, mask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
193 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
194 foregroundMask = win_view_setting.reconstruct(foregroundMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
195 foregroundMask = label(foregroundMask, connectivity=1).astype(np.int32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
196 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
197 if nucleiFilter == 'IntPM': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
198 int_img = nucleiCenters |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
199 elif nucleiFilter == 'Int': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
200 int_img = nucleiImage |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
201 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
202 print(' ', datetime.datetime.now(), 'regionprops') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
203 P = regionprops(foregroundMask, int_img) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
204 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
205 def props_of_keys(prop, keys): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
206 return [prop[k] for k in keys] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
207 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
208 prop_keys = ['mean_intensity', 'area', 'solidity', 'label'] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
209 mean_ints, areas, solidities, labels = np.array( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
210 Parallel(n_jobs=6)(delayed(props_of_keys)(prop, prop_keys) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
211 for prop in P |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
212 ) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
213 ).T |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
214 del P |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
215 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
216 MITh = threshold_otsu(mean_ints) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
217 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
218 minSolidity = 0.8 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
219 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
220 passed = np.logical_and.reduce(( |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
221 np.greater(mean_ints, MITh), |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
222 np.logical_and(areas > minArea, areas < maxArea), |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
223 np.greater(solidities, minSolidity) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
224 )) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
225 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
226 # set failed mask label to zero |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
227 foregroundMask *= np.isin(foregroundMask, labels[passed]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
228 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
229 np.greater(foregroundMask, 0, out=foregroundMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
230 foregroundMask = label(foregroundMask, connectivity=1).astype(np.int32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
231 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
232 return foregroundMask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
233 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
234 def bwmorph(mask,radius): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
235 mask = np.array(mask,dtype=np.uint8) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
236 #labels = label(mask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
237 background = nucleiMask == 0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
238 distances, (i, j) = distance_transform_edt(background, return_indices=True) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
239 cellMask = nucleiMask.copy() |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
240 finalmask = background & (distances <= radius) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
241 cellMask[finalmask] = nucleiMask[i[finalmask], j[finalmask]] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
242 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
243 # imshowpair(cellMask,mask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
244 return cellMask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
245 # imshow(fg) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
246 # fg = cv2.dilate(mask,ndimage.generate_binary_structure(2, 2)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
247 # bg = 1-fg-mask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
248 # imshowpair(bg,mask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
249 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
250 def S3CytoplasmSegmentation(nucleiMask,cyto,mask,cytoMethod='distanceTransform',radius = 5): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
251 mask = (nucleiMask + resize(mask,(nucleiMask.shape[0],nucleiMask.shape[1]),order=0))>0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
252 gdist = distance_transform_edt(1-(nucleiMask>0)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
253 if cytoMethod == 'distanceTransform': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
254 mask = np.array(mask,dtype=np.uint32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
255 markers= nucleiMask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
256 elif cytoMethod == 'hybrid': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
257 cytoBlur = gaussian(cyto,2) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
258 c1 = uniform_filter(cytoBlur, 3, mode='reflect') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
259 c2 = uniform_filter(cytoBlur*cytoBlur, 3, mode='reflect') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
260 grad = np.sqrt(c2 - c1*c1)*np.sqrt(9./8) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
261 grad[np.isnan(grad)]=0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
262 gdist= np.sqrt(np.square(grad) + 0.000001*np.amax(grad)/np.amax(gdist)*np.square(gdist)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
263 bg = binary_erosion(np.invert(mask),morphology.selem.disk(radius, np.uint8)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
264 markers=nucleiMask.copy() |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
265 markers[bg==1] = np.amax(nucleiMask)+1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
266 markers = label(markers>0,connectivity=1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
267 mask = np.ones(nucleiMask.shape) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
268 del bg |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
269 elif cytoMethod == 'ring': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
270 # mask =np.array(bwmorph(nucleiMask,radius)*mask,dtype=np.uint32)>0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
271 mask =np.array(bwmorph(nucleiMask,radius),dtype=np.uint32)>0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
272 markers= nucleiMask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
273 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
274 cellMask =clear_border(watershed(gdist,markers,watershed_line=True)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
275 del gdist, markers, cyto |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
276 cellMask = np.array(cellMask*mask,dtype=np.uint32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
277 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
278 finalCellMask = np.zeros(cellMask.shape,dtype=np.uint32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
279 P = regionprops(label(cellMask>0,connectivity=1),nucleiMask>0,cache=False) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
280 count=0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
281 for props in P: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
282 if props.max_intensity>0 : |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
283 count += 1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
284 yi = props.coords[:, 0] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
285 xi = props.coords[:, 1] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
286 finalCellMask[yi, xi] = count |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
287 nucleiMask = np.array(nucleiMask>0,dtype=np.uint32) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
288 nucleiMask = finalCellMask*nucleiMask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
289 cytoplasmMask = np.subtract(finalCellMask,nucleiMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
290 return cytoplasmMask,nucleiMask,finalCellMask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
291 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
292 def exportMasks(mask,image,outputPath,filePrefix,fileName,saveFig=True,saveMasks = True): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
293 outputPath =outputPath + os.path.sep + filePrefix |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
294 if not os.path.exists(outputPath): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
295 os.makedirs(outputPath) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
296 if saveMasks ==True: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
297 kwargs={} |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
298 kwargs['bigtiff'] = True |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
299 kwargs['photometric'] = 'minisblack' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
300 resolution = np.round(1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
301 kwargs['resolution'] = (resolution, resolution, 'cm') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
302 kwargs['metadata'] = None |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
303 kwargs['description'] = '!!xml!!' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
304 imsave(outputPath + os.path.sep + fileName + 'Mask.tif',mask, plugin="tifffile") |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
305 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
306 if saveFig== True: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
307 mask=np.uint8(mask>0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
308 edges = find_boundaries(mask,mode = 'outer') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
309 stacked_img=np.stack((np.uint16(edges)*np.amax(image),image),axis=0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
310 tifffile.imsave(outputPath + os.path.sep + fileName + 'Outlines.tif',stacked_img) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
311 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
312 def S3punctaDetection(spotChan,mask,sigma,SD): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
313 Ilog = -gaussian_laplace(np.float32(spotChan),sigma) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
314 fgm=peak_local_max(Ilog, indices=False,footprint=np.ones((3, 3))) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
315 test=Ilog[fgm==1] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
316 med = np.median(test) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
317 mad = np.median(np.absolute(test - med)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
318 thresh = med + 1.4826*SD*mad |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
319 return (Ilog>thresh)*fgm*(mask>0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
320 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
321 # stacked_img=np.stack((spots*4095,nucleiCrop),axis=0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
322 # tifffile.imsave('D:/Seidman/ZeissTest Sets/registration/spottest.tif',stacked_img) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
323 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
324 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
325 # assign nan to tissue mask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
326 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
327 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
328 if __name__ == '__main__': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
329 parser=argparse.ArgumentParser() |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
330 parser.add_argument("--imagePath") |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
331 parser.add_argument("--contoursClassProbPath",default ='') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
332 parser.add_argument("--nucleiClassProbPath",default ='') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
333 parser.add_argument("--stackProbPath",default ='') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
334 parser.add_argument("--outputPath") |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
335 parser.add_argument("--dearrayPath") |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
336 parser.add_argument("--maskPath") |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
337 parser.add_argument("--probMapChan",type = int, default = -1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
338 parser.add_argument("--mask",choices=['TMA', 'tissue','none'],default = 'tissue') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
339 parser.add_argument("--crop",choices=['interactiveCrop','autoCrop','noCrop','dearray','plate'], default = 'noCrop') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
340 parser.add_argument("--cytoMethod",choices=['hybrid','distanceTransform','bwdistanceTransform','ring'],default = 'distanceTransform') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
341 parser.add_argument("--nucleiFilter",choices=['IntPM','LoG','Int','none'],default = 'IntPM') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
342 parser.add_argument("--nucleiRegion",choices=['watershedContourDist','watershedContourInt','watershedBWDist','dilation','localThreshold','bypass','pixellevel'], default = 'watershedContourInt') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
343 parser.add_argument("--pixelThreshold",type = float, default = -1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
344 parser.add_argument("--segmentCytoplasm",choices = ['segmentCytoplasm','ignoreCytoplasm'],default = 'ignoreCytoplasm') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
345 parser.add_argument("--cytoDilation",type = int, default = 5) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
346 parser.add_argument("--logSigma",type = int, nargs = '+', default = [3, 60]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
347 parser.add_argument("--CytoMaskChan",type=int, nargs = '+', default=[1]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
348 parser.add_argument("--pixelMaskChan",type=int, nargs = '+', default=[1]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
349 parser.add_argument("--TissueMaskChan",type=int, nargs = '+', default=-1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
350 parser.add_argument("--detectPuncta",type=int, nargs = '+', default=[-1]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
351 parser.add_argument("--punctaSigma", nargs = '+', type=float, default=[1]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
352 parser.add_argument("--punctaSD", nargs = '+', type=float, default=[4]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
353 parser.add_argument("--saveMask",action='store_false') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
354 parser.add_argument("--saveFig",action='store_false') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
355 args = parser.parse_args() |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
356 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
357 # gather filename information |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
358 #exemplar001 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
359 # imagePath = 'D:/LSP/cycif/testsets/exemplar-001/registration/exemplar-001small.ome.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
360 # outputPath = 'D:/LSP/cycif/testsets/exemplar-001/segmentation' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
361 ## nucleiClassProbPath = 'D:/LSP/cycif/testsets/exemplar-001/probability_maps/exemplar-001_NucleiPM_0.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
362 ## contoursClassProbPath = 'D:/LSP/cycif/testsets/exemplar-001/probability_maps/exemplar-001_ContoursPM_0.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
363 # contoursClassProbPath ='' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
364 # stackProbPath = 'D:/LSP/cycif/testsets/exemplar-001_Probabilities_0.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
365 # maskPath = 'D:/LSP/cycif/testsets/exemplar-001/dearray/masks/A1_mask.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
366 # args.cytoMethod = 'hybrid' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
367 # args.nucleiRegion = 'localThreshold' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
368 # args.segmentCytoplasm = 'segmentCytoplasm' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
369 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
370 # exemplar002 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
371 # imagePath = 'D:/LSP/cycif/testsets/exemplar-002/dearray/1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
372 # outputPath = 'D:/LSP/cycif/testsets/exemplar-002/segmentation' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
373 # nucleiClassProbPath = ''#'D:/LSP/cycif/testsets/exemplar-002/prob_map/1_NucleiPM_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
374 # contoursClassProbPath = ''#'D:/LSP/cycif/testsets/exemplar-002/prob_map/1_ContoursPM_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
375 # stackProbPath = 'D:/LSP/cycif/testsets/exemplar-002/probability-maps/unmicst_1new_Probabilities_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
376 # maskPath = 'D:/LSP/cycif/testsets/exemplar-002/dearrayPython/masks/1_mask.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
377 # args.probMapChan =1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
378 # args.cytoMethod = 'hybrid' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
379 # args.mask = 'TMA' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
380 # args.crop = 'dearray' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
381 # args.crop = 'autoCrop' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
382 # args.segmentCytoplasm = 'segmentCytoplasm' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
383 #PTCL |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
384 # imagePath = 'D:/LSP/cycif/testsets/PTCL/dearrayPython/1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
385 # outputPath = 'D:/LSP/cycif/testsets/PTCL/dearrayPython/segmentation' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
386 # nucleiClassProbPath = ''#'D:/LSP/cycif/testsets/exemplar-002/prob_map/1_NucleiPM_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
387 # contoursClassProbPath = ''#'D:/LSP/cycif/testsets/exemplar-002/prob_map/1_ContoursPM_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
388 # stackProbPath = 'D:/LSP/cycif/testsets/PTCL/prob_maps/1_Probabilities_40.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
389 # maskPath = 'D:/LSP/cycif/testsets/exemplar-002/dearrayPython/masks/1_mask.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
390 # args.crop = 'dearray' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
391 # args.segmentCytoplasm = 'segmentCytoplasm' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
392 # |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
393 #punctatest |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
394 # imagePath = 'Z:/IDAC/Clarence/Seidman/ZeissMouseTestSet/31082020_XXWT_Txnip550_Ddx3x647_WGA488_40x_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
395 # outputPath = 'Z:/IDAC/Clarence/Seidman/ZeissMouseTestSet/segmentation' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
396 ## nucleiClassProbPath = 'Z:/IDAC/Clarence/Seidman/ZeissMouseTestSet/probability-maps/test_NucleiPM_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
397 ## contoursClassProbPath = 'Z:/IDAC/Clarence/Seidman/DanMouse/probability-maps/test_ContoursPM_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
398 # contoursClassProbPath ='' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
399 # stackProbPath = 'Z:/IDAC/Clarence/Seidman/ZeissMouseTestSet/probability-maps/31082020_XXWT_Txnip550_Ddx3x647_WGA488_40x_1_Probabilities_2.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
400 # maskPath = 'D:/Seidman/ZeissTest Sets/segmentation/13042020_15AP_FAP488_LINC550_DCN647_WGA_40x_1/cellMask.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
401 # args.nucleiRegion = 'localThreshold' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
402 # args.logSigma = [45, 300] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
403 # args.segmentCytoplasm = 'ignoreCytoplasm' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
404 # args.detectPuncta = [1] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
405 # args.punctaSigma = [1] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
406 # args.punctaSD = [3] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
407 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
408 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
409 #plate |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
410 # imagePath = 'Y:/sorger/data/computation/Jeremy/caitlin-ddd-cycif-registered/Plate1/E3_fld_1/registration/E3_fld_1.ome.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
411 # outputPath = 'Y:/sorger/data/computation/Jeremy/caitlin-ddd-cycif-registered/Plate1/E3_fld_1/segmentation' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
412 # nucleiClassProbPath = 'Y:/sorger/data/computation/Jeremy/caitlin-ddd-cycif-registered/Plate1/E3_fld_1/prob_maps/E3_fld_1_NucleiPM_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
413 # contoursClassProbPath = 'Y:/sorger/data/computation/Jeremy/caitlin-ddd-cycif-registered/Plate1/E3_fld_1/prob_maps/E3_fld_1_ContoursPM_1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
414 # maskPath = 'D:/LSP/cycif/testsets/exemplar-001/dearray/masks/A1_mask.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
415 # args.crop = 'plate' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
416 # args.cytoMethod ='hybrid' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
417 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
418 #large tissue |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
419 # imagePath = 'D:/WD-76845-097.ome.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
420 # outputPath = 'D:/' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
421 ## nucleiClassProbPath = 'D:/WD-76845-097_NucleiPM_28.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
422 # contoursClassProbPath = ""#'D:/WD-76845-097_ContoursPM_28.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
423 # stackProbPath = 'D:/ilastik/WD-76845-097_Probabilities_0.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
424 # maskPath = 'D:/LSP/cycif/testsets/exemplar-001/dearray/masks/A1_mask.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
425 # args.nucleiRegion = 'localThreshold' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
426 # args.crop = 'autoCrop' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
427 # args.TissueMaskChan =[0] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
428 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
429 #maskRCNN |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
430 # imagePath = 'D:/Seidman/s3segtest/registration/1.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
431 # outputPath = 'D:/Seidman/s3segtest/segmentation' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
432 # stackProbPath = 'D:/Seidman/s3segtest/1_Probabilities_0.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
433 # contoursClassProbPath = '' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
434 # maskPath = 'D:/LSP/cycif/testsets/exemplar-001/dearray/masks/A1_mask.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
435 # args.nucleiRegion = 'bypass' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
436 # args.crop = 'noCrop' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
437 # args.TissueMaskChan =[0] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
438 # args.logSigma = [45,300] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
439 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
440 # #pixellevel |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
441 # imagePath = 'D:/Olesja/D2107_spleen_DAPI-EdU_01/Layer0/D2107_spleen_DAPI-EdU_01.btf' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
442 # outputPath = 'D:/Olesja/D2107_spleen_DAPI-EdU_01/segmentation' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
443 # stackProbPath = 'D:/Seidman/s3segtest/1_Probabilities_0.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
444 # contoursClassProbPath = 'D:/Olesja/D2107_spleen_DAPI-EdU_01/prob_maps3Class/D2107_spleen_DAPI-EdU_01_ContoursPM_0.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
445 # nucleiClassProbPath = 'D:/Olesja/D2107_spleen_DAPI-EdU_01/prob_maps3Class/D2107_spleen_DAPI-EdU_01_NucleiPM_0.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
446 # maskPath = 'D:/LSP/cycif/testsets/exemplar-001/dearray/masks/A1_mask.tif' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
447 # args.nucleiRegion = 'pixellevel' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
448 # args.crop = 'noCrop' |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
449 # args.TissueMaskChan =[0] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
450 # args.pixelThreshold = 0.06 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
451 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
452 imagePath = args.imagePath |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
453 outputPath = args.outputPath |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
454 nucleiClassProbPath = args.nucleiClassProbPath |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
455 contoursClassProbPath = args.contoursClassProbPath |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
456 stackProbPath = args.stackProbPath |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
457 maskPath = args.maskPath |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
458 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
459 fileName = os.path.basename(imagePath) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
460 filePrefix = fileName[0:fileName.index('.')] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
461 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
462 if not os.path.exists(outputPath): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
463 os.makedirs(outputPath) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
464 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
465 # get channel used for nuclei segmentation |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
466 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
467 if len(contoursClassProbPath)>0: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
468 legacyMode = 1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
469 probPrefix = os.path.basename(contoursClassProbPath) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
470 nucMaskChan = int(probPrefix.split('ContoursPM_')[1].split('.')[0]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
471 elif len(stackProbPath)>0: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
472 legacyMode = 0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
473 probPrefix = os.path.basename(stackProbPath) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
474 index = re.search('%s(.*)%s' % ('Probabilities', '.tif'), stackProbPath).group(1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
475 if len(index)==0: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
476 nucMaskChan = args.probMapChan |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
477 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
478 nucMaskChan = int(re.sub("\D", "", index)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
479 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
480 print('NO PROBABILITY MAP PROVIDED') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
481 if args.probMapChan ==-1: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
482 if nucMaskChan ==-1: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
483 sys.exit('INVALID NUCLEI CHANNEL SELECTION. SELECT CHANNEL USING --probMapChan') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
484 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
485 print('extracting nuclei channel from filename') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
486 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
487 nucMaskChan = args.probMapChan |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
488 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
489 if args.TissueMaskChan==-1: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
490 TissueMaskChan = copy.copy(args.CytoMaskChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
491 TissueMaskChan.append(nucMaskChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
492 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
493 TissueMaskChan = args.TissueMaskChan[:] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
494 TissueMaskChan.append(nucMaskChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
495 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
496 #crop images if needed |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
497 if args.crop == 'interactiveCrop': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
498 nucleiCrop = tifffile.imread(imagePath,key = nucMaskChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
499 r=cv2.selectROI(resize(nucleiCrop,(nucleiCrop.shape[0] // 30, nucleiCrop.shape[1] // 30))) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
500 cv2.destroyWindow('select') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
501 rect=np.transpose(r)*30 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
502 PMrect= [rect[1], rect[0], rect[3], rect[2]] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
503 nucleiCrop = nucleiCrop[int(rect[1]):int(rect[1]+rect[3]), int(rect[0]):int(rect[0]+rect[2])] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
504 elif args.crop == 'noCrop' or args.crop == 'dearray' or args.crop == 'plate': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
505 nucleiCrop = tifffile.imread(imagePath,key = nucMaskChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
506 rect = [0, 0, nucleiCrop.shape[0], nucleiCrop.shape[1]] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
507 PMrect= rect |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
508 elif args.crop == 'autoCrop': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
509 nucleiCrop = tifffile.imread(imagePath,key = nucMaskChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
510 rect = [np.round(nucleiCrop.shape[0]/3), np.round(nucleiCrop.shape[1]/3),np.round(nucleiCrop.shape[0]/3), np.round(nucleiCrop.shape[1]/3)] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
511 PMrect= rect |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
512 nucleiCrop = nucleiCrop[int(rect[0]):int(rect[0]+rect[2]), int(rect[1]):int(rect[1]+rect[3])] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
513 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
514 if legacyMode ==1: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
515 nucleiProbMaps = tifffile.imread(nucleiClassProbPath,key=0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
516 nucleiPM = nucleiProbMaps[int(PMrect[0]):int(PMrect[0]+PMrect[2]), int(PMrect[1]):int(PMrect[1]+PMrect[3])] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
517 nucleiProbMaps = tifffile.imread(contoursClassProbPath,key=0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
518 PMSize = nucleiProbMaps.shape |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
519 nucleiPM = np.dstack((nucleiPM,nucleiProbMaps[int(PMrect[0]):int(PMrect[0]+PMrect[2]), int(PMrect[1]):int(PMrect[1]+PMrect[3])])) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
520 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
521 nucleiProbMaps = imread(stackProbPath) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
522 nucleiPM = nucleiProbMaps[int(PMrect[0]):int(PMrect[0]+PMrect[2]), int(PMrect[1]):int(PMrect[1]+PMrect[3]),0:2] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
523 PMSize = nucleiProbMaps.shape |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
524 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
525 # mask the core/tissue |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
526 if args.crop == 'dearray': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
527 TMAmask = tifffile.imread(maskPath) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
528 elif args.crop =='plate': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
529 TMAmask = np.ones(nucleiCrop.shape) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
530 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
531 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
532 tissue = np.empty((len(TissueMaskChan),nucleiCrop.shape[0],nucleiCrop.shape[1]),dtype=np.uint16) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
533 count=0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
534 if args.crop == 'noCrop': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
535 for iChan in TissueMaskChan: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
536 tissueCrop =tifffile.imread(imagePath,key=iChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
537 tissue_gauss = gaussian(tissueCrop,1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
538 #tissue_gauss[tissue_gauss==0]=np.nan |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
539 tissue[count,:,:] =np.log2(tissue_gauss+1)>threshold_otsu(np.log2(tissue_gauss+1)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
540 count+=1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
541 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
542 for iChan in TissueMaskChan: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
543 tissueCrop = tifffile.imread(imagePath,key=iChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
544 tissue_gauss = gaussian(tissueCrop[int(PMrect[0]):int(PMrect[0]+PMrect[2]), int(PMrect[1]):int(PMrect[1]+PMrect[3])],1) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
545 tissue[count,:,:] = np.log2(tissue_gauss+1)>threshold_otsu(np.log2(tissue_gauss+1)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
546 count+=1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
547 TMAmask = np.max(tissue,axis = 0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
548 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
549 # tissue_gauss = tissueCrop |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
550 # tissue_gauss1 = tissue_gauss.astype(float) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
551 # tissue_gauss1[tissue_gauss>np.percentile(tissue_gauss,99)]=np.nan |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
552 # TMAmask = np.log2(tissue_gauss+1)>threshold_otsu(np.log2(tissue_gauss+1)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
553 #imshow(TMAmask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
554 del tissue_gauss, tissue |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
555 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
556 # nuclei segmentation |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
557 if args.nucleiRegion == 'pixellevel': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
558 pixelTissue = np.empty((len(args.pixelMaskChan),nucleiCrop.shape[0],nucleiCrop.shape[1]),dtype=np.uint16) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
559 count=0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
560 for iChan in args.pixelMaskChan: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
561 pixelCrop = tifffile.imread(imagePath,key=iChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
562 pixelTissue[count,:,:] = pixelCrop[int(PMrect[0]):int(PMrect[0]+PMrect[2]), int(PMrect[1]):int(PMrect[1]+PMrect[3])] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
563 count+=1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
564 nucleiMask = S3AreaSegmenter(nucleiPM, pixelTissue, TMAmask,args.pixelThreshold,outputPath) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
565 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
566 nucleiMask = S3NucleiSegmentationWatershed(nucleiPM,nucleiCrop,args.logSigma,TMAmask,args.nucleiFilter,args.nucleiRegion) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
567 del nucleiPM |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
568 # cytoplasm segmentation |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
569 if args.segmentCytoplasm == 'segmentCytoplasm': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
570 count =0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
571 if args.crop == 'noCrop' or args.crop == 'dearray' or args.crop == 'plate': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
572 cyto=np.empty((len(args.CytoMaskChan),nucleiCrop.shape[0],nucleiCrop.shape[1]),dtype=np.uint16) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
573 for iChan in args.CytoMaskChan: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
574 cyto[count,:,:] = tifffile.imread(imagePath, key=iChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
575 count+=1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
576 elif args.crop =='autoCrop': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
577 cyto=np.empty((len(args.CytoMaskChan),int(rect[2]),int(rect[3])),dtype=np.int16) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
578 for iChan in args.CytoMaskChan: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
579 cytoFull= tifffile.imread(imagePath, key=iChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
580 cyto[count,:,:] = cytoFull[int(PMrect[0]):int(PMrect[0]+PMrect[2]), int(PMrect[1]):int(PMrect[1]+PMrect[3])] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
581 count+=1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
582 else: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
583 cyto=np.empty((len(args.CytoMaskChan),rect[3],rect[2]),dtype=np.int16) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
584 for iChan in args.CytoMaskChan: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
585 cytoFull= tifffile.imread(imagePath, key=iChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
586 cyto[count,:,:] = cytoFull[int(PMrect[0]):int(PMrect[0]+PMrect[2]), int(PMrect[1]):int(PMrect[1]+PMrect[3])] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
587 count+=1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
588 cyto = np.amax(cyto,axis=0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
589 cytoplasmMask,nucleiMaskTemp,cellMask = S3CytoplasmSegmentation(nucleiMask,cyto,TMAmask,args.cytoMethod,args.cytoDilation) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
590 exportMasks(nucleiMaskTemp,nucleiCrop,outputPath,filePrefix,'nuclei',args.saveFig,args.saveMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
591 exportMasks(cytoplasmMask,cyto,outputPath,filePrefix,'cyto',args.saveFig,args.saveMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
592 exportMasks(cellMask,cyto,outputPath,filePrefix,'cell',args.saveFig,args.saveMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
593 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
594 cytoplasmMask,nucleiMaskTemp,cellMask = S3CytoplasmSegmentation(nucleiMask,cyto,TMAmask,'ring',args.cytoDilation) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
595 exportMasks(nucleiMaskTemp,nucleiCrop,outputPath,filePrefix,'nucleiRing',args.saveFig,args.saveMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
596 exportMasks(cytoplasmMask,cyto,outputPath,filePrefix,'cytoRing',args.saveFig,args.saveMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
597 exportMasks(cellMask,cyto,outputPath,filePrefix,'cellRing',args.saveFig,args.saveMask) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
598 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
599 elif args.segmentCytoplasm == 'ignoreCytoplasm': |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
600 exportMasks(nucleiMask,nucleiCrop,outputPath,filePrefix,'nuclei') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
601 cellMask = nucleiMask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
602 exportMasks(nucleiMask,nucleiCrop,outputPath,filePrefix,'cell') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
603 cytoplasmMask = nucleiMask |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
604 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
605 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
606 if (np.min(args.detectPuncta)>-1): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
607 if len(args.detectPuncta) != len(args.punctaSigma): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
608 args.punctaSigma = args.punctaSigma[0] * np.ones(len(args.detectPuncta)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
609 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
610 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
611 if len(args.detectPuncta) != len(args.punctaSD): |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
612 args.punctaSD = args.punctaSD[0] * np.ones(len(args.detectPuncta)) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
613 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
614 counter=0 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
615 for iPunctaChan in args.detectPuncta: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
616 punctaChan = tifffile.imread(imagePath,key = iPunctaChan) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
617 punctaChan = punctaChan[int(PMrect[0]):int(PMrect[0]+PMrect[2]), int(PMrect[1]):int(PMrect[1]+PMrect[3])] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
618 spots=S3punctaDetection(punctaChan,cellMask,args.punctaSigma[counter],args.punctaSD[counter]) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
619 cellspotmask = nucleiMask#tifffile.imread(maskPath) #REMOVE THIS LATER |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
620 P = regionprops(cellspotmask,intensity_image = spots ,cache=False) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
621 numSpots = [] |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
622 for prop in P: |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
623 numSpots.append(np.uint16(np.round(prop.mean_intensity * prop.area))) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
624 np.savetxt(outputPath + os.path.sep + 'numSpots_chan' + str(iPunctaChan) +'.csv',(np.transpose(np.asarray(numSpots))),fmt='%10.5f') |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
625 edges = 1-(cellMask>0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
626 stacked_img=np.stack((np.uint16((spots+edges)>0)*np.amax(punctaChan),punctaChan),axis=0) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
627 tifffile.imsave(outputPath + os.path.sep + filePrefix + os.path.sep + 'punctaChan'+str(iPunctaChan) + 'Outlines.tif',stacked_img) |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
628 counter=counter+1 |
37acf42a824b
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit d89a61efd4c465a1e6bf5b99b0f78fb19be5bdea-dirty"
perssond
parents:
diff
changeset
|
629 #fix bwdistance watershed |