Skip to content

Commit

Permalink
Added channel parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lopaavol committed Mar 5, 2021
1 parent b909b2a commit f3038a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 12 additions & 1 deletion descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"image": "neubiaswg5/w_nucleisegmentation-cellpose",
"type": "singularity"
},
"command-line": "python wrapper.py CYTOMINE_HOST CYTOMINE_PUBLIC_KEY CYTOMINE_PRIVATE_KEY CYTOMINE_ID_PROJECT CYTOMINE_ID_SOFTWARE DIAMETER PROB_THRESHOLD",
"command-line": "python wrapper.py CYTOMINE_HOST CYTOMINE_PUBLIC_KEY CYTOMINE_PRIVATE_KEY CYTOMINE_ID_PROJECT CYTOMINE_ID_SOFTWARE DIAMETER PROB_THRESHOLD NUC_CHANNEL",
"inputs": [
{
"id": "cytomine_host",
Expand Down Expand Up @@ -73,6 +73,17 @@
"set-by-server": false,
"optional": true,
"type": "Number"
},
{
"id": "nuc_channel",
"value-key": "@ID",
"command-line-flag": "--@id",
"name": "Nuclei channel",
"description": "Use default 0 for grayscale and RGB that should be converted to grayscale based on luminance. Use 1, 2 or 3 to select a specific RGB channel",
"default-value": 0,
"set-by-server": false,
"optional": true,
"type": "Number"
}
],

Expand Down
10 changes: 6 additions & 4 deletions wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ def main(argv):

# Make sure all images have at least 224x224 dimensions
# and that minshape / maxshape * minshape >= 224
nuc_channel = 0 # 0 = Grayscale, 1,2,3 = rgb channel
# 0 = Grayscale (if input RGB, convert to grayscale)
# 1,2,3 = rgb channel
nuc_channel = bj.parameters.nuc_channel
resized = {}
for bfimg in in_imgs:
fn = os.path.join(in_path, bfimg.filename)
img = imageio.imread(fn)
if len(img.shape) > 2:
nuc_channel = 3
if len(img.shape) > 2 and nuc_channel == 0:
img = skimage.color.rgb2gray(img)
minshape = min(img.shape[:2])
maxshape = max(img.shape[:2])
if minshape != maxshape or minshape < 224:
Expand All @@ -49,7 +51,7 @@ def main(argv):

# Add here the code for running the analysis script
#"--chan", "{:d}".format(nuc_channel)
cmd = ["python", "-m", "cellpose", "--dir", tmp_path, "--pretrained_model", "nuclei", "--save_tif", "--no_npy", "--all_channels", "--diameter", "{:f}".format(bj.parameters.diameter), "--cellprob_threshold", "{:f}".format(bj.parameters.prob_threshold)]
cmd = ["python", "-m", "cellpose", "--dir", tmp_path, "--pretrained_model", "nuclei", "--save_tif", "--no_npy", "--chan", "{:d}".format(nuc_channel), "--diameter", "{:f}".format(bj.parameters.diameter), "--cellprob_threshold", "{:f}".format(bj.parameters.prob_threshold)]
status = subprocess.run(cmd)

if status.returncode != 0:
Expand Down

0 comments on commit f3038a9

Please sign in to comment.