stardist / stardist

StarDist - Object Detection with Star-convex Shapes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An error in 2D_versatile_he

HectorTo opened this issue · comments

Hello, I have encountered a problem while using Stardist. When I try to use the pre-trained model for HE slice(2D_versatile_he), an error message is displayed stating that "axes='YXC'" even though the input image has been processed using grayscale on the color HE slice. How should I handle this situation? Thank you!

though the input image has been processed using grayscale on the color HE slice

The 2D_versatile_he model expect a RGB (3 color) input image, so converting to grayscale should not work

Thank you, but I get an error when directly passing in an RGB image: "axes (YXC) must be of length 2". How should I handle it?

Can you provide a code example that shows the error?

import cv2
import numpy as np

from stardist.models import StarDist2D

prints a list of available models

StarDist2D.from_pretrained()

creates a pretrained model

model = StarDist2D.from_pretrained('2D_versatile_he')

Load image with OpenCV

img = cv2.imread('image.png')

Convert to NumPy array

img = np.array(img)

Normalize the image

img_normalized = normalize(img)

Predict instances with the model

labels, _ = model.predict_instances(img_normalized)

Display the original image and the predicted instances

plt.subplot(1,2,1)
plt.imshow(img, cmap="gray")
plt.axis("off")
plt.title("input image")

plt.subplot(1,2,2)
plt.imshow(render_label(labels, img=img))
plt.axis("off")
plt.title("prediction + input overlay")

can you print img.shape?

sure,it's(600,718,3)

That should work. Can you provide a complete example (e.g. with some empty dummy image) that can be run and that shows the error?

I tried using the random official example "img = test_image_nuclei_2d()" but it didn't work. After I forced the HE slices to be converted to grayscale images, the error disappeared and a empty "ValueError" was displayed.

can you post minimal example with img = test_image_nuclei_2d() that fails for you?

The image generated by "img = test_image_nuclei_2d()" is not a HE slice image. Even after I used a pre-trained model with HE slices, the error was still an empty "ValueError". If I input a non-grayscale image, an error will occur saying that the length of "axes" should be 2.

The image generated by "img = test_image_nuclei_2d()" is not a HE slice image.

I don't really understand what you mean by that. Can you please post a minimal example, otherwise its impossible for me to help you.

Sure, let me organize it and thank you very much.

Thank you for your help. I rewrote the code and ran it on Jupyter. The error has been resolved, although I'm still not entirely sure what caused the error in the first place.

The image generated by "img = test_image_nuclei_2d()" is not a HE slice image.

I don't really understand what you mean by that. Can you please post a minimal example, otherwise its impossible for me to help you.

Hi there! I am interested in training a new StarDist model using my own dataset. Can you please point me to the relevant documentation or resources that I can refer to for guidance? Thank you!

I suggest to look at our README first. For model training specifically, please follow the example Jupyter notebooks here (replace the test data with your own).

I suggest to look at our README first. For model training specifically, please follow the example Jupyter notebooks here (replace the test data with your own).

OK,thanks a lot

Hello, I would like to ask how to modify the script when exporting HE slices from qupath so that the exported pictures are in color instead of black and white.

plt.imshow(img, cmap="gray")
just remove the cmap in this line

Please continue this discussion (and others like it) in the image.sc forum (as instructed in our Readme).