haesleinhuepf / git-bob-bioimage-analysis-example

BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Nuclei segmentation #68

Open haesleinhuepf opened 1 month ago

haesleinhuepf commented 1 month ago

This is human_mitosis.png:

human_mitosis

I would like to segment and label the bright nuclei in it, using the Voronoi-Otsu-Labeling algorithm. The resulting label image should be converted to an RGB and saved as .png file. Please write a jupyter notebook for this.

git-bob think about how to do this with Python.

github-actions[bot] commented 1 month ago

This message was generated by git-bob (version: 0.8.2, model: gpt-4o-2024-08-06, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

Sure! Below is a proposal for a Jupyter notebook that segments and labels the bright nuclei in the given image using the Voronoi-Otsu-Labeling algorithm. The result is converted to an RGB image and saved as a .png file.

# Download the image
import requests
from pathlib import Path

# Ensure the data directory exists
data_folder = Path("data")
data_folder.mkdir(exist_ok=True)

# Download the image and save it to the data folder
img_url = "https://github.com/user-attachments/assets/c1bf94c5-fe80-4ff9-a46e-d4d9cb9f276f"
img_path = data_folder / "human_mitosis.png"

response = requests.get(img_url)
with open(img_path, "wb") as file:
    file.write(response.content)

# Import necessary libraries
import napari_segment_blobs_and_things_with_membranes as nsbatwm
from skimage import color, io

# Load the image
image = io.imread(str(img_path))

# Apply Voronoi-Otsu-Labeling algorithm
labeled_image = nsbatwm.voronoi_otsu_labeling(image, spot_sigma=3.5, outline_sigma=1)

# Convert to RGB
rgb_image = color.label2rgb(labeled_image, bg_label=0)

# Save the RGB image
result_image_path = data_folder / "human_mitosis_segmented.png"
io.imsave(str(result_image_path), (rgb_image * 255).astype('uint8'))

Please put this code in a new Jupyter notebook and save it in the notebooks folder of the repository.

haesleinhuepf commented 1 month ago

Almost correct! Do not convert the rgb-image to uint8. Instead just save it as it is.

git-bob try this solution out!

github-actions[bot] commented 1 month ago

This message was generated by git-bob (version: 0.8.2, model: gpt-4o-2024-08-06, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

The changes involved downloading an image from a specified URL and saving it as data/human_mitosis.png. A new Jupyter notebook nuclei_segmentation.ipynb was created to segment and label nuclei in the downloaded image using the Voronoi-Otsu-Labeling algorithm, and it saved the resulting RGB image. Additionally, a step to convert the RGB image to uint8 before saving was removed from the notebook.

haesleinhuepf commented 1 month ago

Ok, my fault. Saving the label image did`t work.

git-bob, try it again WITH the uint8 conversion step.

github-actions[bot] commented 1 month ago

This message was generated by git-bob (version: 0.8.2, model: gpt-4o-2024-08-06, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

The recent changes involved creating a Jupyter notebook for nuclei segmentation using the Voronoi-Otsu-Labeling algorithm in notebooks/nuclei_segmentation.ipynb. A human mitosis image was downloaded from the provided URL and saved as "data/human_mitosis.png". The segmented RGB image was also saved, ensuring it is saved as uint8 for proper saving, and is stored as "data/human_mitosis_segmented.png".