BiomedSciAI/histocartography

Extract coordinates of nuclei in image

hossam-zaki opened this issue · 4 comments

Hello!

Hope all is well. I have two images. One with the H+E staining, and another one, which is the exact same, but is colored by cell label. I'm wondering if it is possible to extract the coordinates of each nuclei in the input image? I would like to go from the nuclei in one picture to its label in the other using the coordinates. Is this possible?

See the two images below (this is from an open source dataset):

Screen Shot 2021-06-10 at 11 40 33 PM

Screen Shot 2021-06-10 at 11 40 48 PM

Hi,

I guess you can try something like that:

from histocartography.preprocessing import NucleiExtractor
from PIL import Image
import numpy as np

# 1. load image 
image = np.array(Image.open(image.png)) # or whatever your image name is 

# 2. extract nuclei as an instance map & centroids (coords)
extractor = NucleiExtractor(pretrained_data='monusac')  # you can try another checkpoint with 'pannuke'
instance_map, instance_centroids = extractor.process(image)  # instance_centroids is what you look for     

Keeping in mind that Monusac and PanNuke datasets include mostly high magnification images. Your image seems to be at low magnification, so maybe try to run the algo with a better resolution, if possible.

Hi! Thanks a lot for the response..

I ended up trying this out, but it outputted some centroids that were outside of the image, as seen in this screenshot.

Screen Shot 2021-06-18 at 2 09 35 AM

Any advice with this? Am I getting the centroids properly? Really appreciate your help and love the package

Can you print the image size?

Numpy and image-based packages use different indexing conventions, (row,col) for numpy and (x,y) for PIL, cv2 etc.

Sure. Check this out.

I was thinking it could be reversed, but wanted to double check. Really appreciate your help!
Screen Shot 2021-06-18 at 2 59 04 AM