Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with output segmentation with 2D_versatile_he #233

Open
niccolo99mandelli opened this issue Jun 11, 2023 · 1 comment
Open

Problem with output segmentation with 2D_versatile_he #233

niccolo99mandelli opened this issue Jun 11, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@niccolo99mandelli
Copy link

Hi, I'm using the StarDist library for histological image segmentation in WSI format using the pre-trained model 2D_versatile_he. The model construction and segmentation process are running correctly, however, when saving the image, the output labels appear completely black, and the segmented nuclei are not present. The error occurs for both small-sized and large-sized slides, using the two provided prediction methods. The input slides I provide have a structure very similar to those in the example and refer to portions of tissues. I have also tried using different formats such as .svs and .tif, but the problem persists.
Below is the code I am using:
Note: I am using the library in Julia and invoking it with Julia's PyCall.

using PyCall

py"""
import numpy as np
import matplotlib.pyplot as plt

from tifffile import imread, imsave
from csbdeep.utils import Path, normalize
from csbdeep.utils.tf import keras_import
keras = keras_import()

from stardist import export_imagej_rois, random_label_cmap
from stardist.models import StarDist2D

np.random.seed(0)
cmap = random_label_cmap()

from zipfile import ZIP_DEFLATED


img = imread('C:/Users/nicom/Desktop/Extra/segmentation/TCGA-OR-A5J1-01A-01-TS1.CFE08710-54B8-45B0-86AE-500D6E36D8A5_004.svs')
model = StarDist2D.from_pretrained('2D_versatile_he')
from csbdeep.data import Normalizer, normalize_mi_ma

class MyNormalizer(Normalizer):
    def __init__(self, mi, ma):
            self.mi, self.ma = mi, ma
    def before(self, x, axes):
        return normalize_mi_ma(x, self.mi, self.ma, dtype=np.float32)
    def after(*args, **kwargs):
        assert False
    @property
    def do_after(self):
        return False

mi, ma = 0, 255
normalizer = MyNormalizer(mi, ma)

# labels, polys = model.predict_instances(img, normalizer=normalizer, n_tiles=(32,32,1))
labels, polys = model.predict_instances_big(img, axes='YXC', block_size=2048, min_overlap=128, context=128,
                                            normalizer=normalizer, n_tiles=(4,4,1))

imsave('labels.tif', labels, compress=ZIP_DEFLATED)
"""

What could be the possible cause of the problem?

Thanks in advance,
Niccolò Mandelli

@niccolo99mandelli niccolo99mandelli added the bug Something isn't working label Jun 11, 2023
@uschmidt83
Copy link
Member

Hi @niccolo99mandelli, sorry for the late reply!

Maybe it's just a brightness/constrast issue that the output label image appears black, but actually isn't empty.
See this form post for a similar situation.

Next time, please discuss issues like this (which likely aren't bugs) at the image.sc forum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants