diff --git a/descriptor.json b/descriptor.json index 8fd1074..15691be 100644 --- a/descriptor.json +++ b/descriptor.json @@ -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", @@ -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" } ], diff --git a/wrapper.py b/wrapper.py index ce89194..ab4d4b0 100644 --- a/wrapper.py +++ b/wrapper.py @@ -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: @@ -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: