haesleinhuepf / git-bob-bioimage-analysis-example

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

[Analysis Request]: Segment cells from images with membrane staining #58

Open haesleinhuepf opened 6 days ago

haesleinhuepf commented 6 days ago

Bio-Image Analysis Support Request

Image Upload

📎 Drag & drop your microscopy image here (JPG, PNG, GIF, 512x512 or 1024x1024, 2D only).

membranes

Analysis Goal

I would like to measure shape of cells in this image.

Python Tools

Note: Your images and the text you enter here may be sent to OpenAI's online serivce where we use a large language model to answer your request. Do not upload any data you cannot share openly. Also do not enter any private or secret information. By submitting this github issue, you confirm that you understand these conditions.

Once submitted, @haesleinhuepf will review and consult git-bob, an AI-assistant for bio-image analysis suggestions.

haesleinhuepf commented 6 days ago

git-bob think about this

github-actions[bot] commented 6 days ago

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

To measure the shape of cells in the given image with membrane staining, we can use the napari-segment-blobs-and-things-with-membranes package to perform segmentation and scikit-image for measuring properties. Below is a proposed workflow:

  1. Load the Image: First, download the image and place it in a data folder within your project directory.

  2. Pre-process and Segment the Image:

    • Use a Gaussian filter to smooth the image.
    • Perform segmentation using the Voronoi Otsu labeling method.
    • Remove labels that touch the image border if undesired.
  3. Measure Cell Shape Properties:

    • Use scikit-image to calculate properties like area, perimeter, and other shape descriptors.

Here’s a sample code implementation:

import napari_segment_blobs_and_things_with_membranes as nsbatwm
import skimage.io
from skimage.measure import regionprops_table
import pandas as pd
import stackview

# Load the image
image_path = 'data/membranes.png'
image = skimage.io.imread(image_path)

# Denoise the image with Gaussian filter
smoothed_image = nsbatwm.gaussian_blur(image, sigma=2)

# Segment using Voronoi Otsu labeling
labels = nsbatwm.voronoi_otsu_labeling(smoothed_image, spot_sigma=3.5, outline_sigma=1)

# Optionally remove labels touching the image border
labels = nsbatwm.remove_labels_on_edges(labels)

# Measure properties
properties = ['label', 'area', 'perimeter', 'eccentricity', 'solidity']
measurements = regionprops_table(labels, properties=properties)
df = pd.DataFrame(measurements)

# Visualize the results
stackview.animate_curtain(image, labels)

# Display results
df.head()

This code will help segment the cells and calculate shape-related properties, allowing for cell shape analysis in the context of the given microscopy image.

haesleinhuepf commented 5 days ago

I think, the watershed algorithm using local minima is better suited, instead of voronoi-otsu labeling.

git-bob think about this

github-actions[bot] commented 5 days ago

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

To better segment the cells using the watershed algorithm with local minima, the following code can be implemented:

import napari_segment_blobs_and_things_with_membranes as nsbatwm
import skimage.io
from skimage.measure import regionprops_table
import pandas as pd
import stackview

# Load the image
image_path = 'data/membranes.png'
image = skimage.io.imread(image_path)

# Denoise the image with Gaussian filter
smoothed_image = nsbatwm.gaussian_blur(image, sigma=2)

# Perform segmentation using the watershed algorithm with local minima
labels = nsbatwm.local_minima_seeded_watershed(smoothed_image, spot_sigma=3.5)

# Optionally remove labels touching the image border
labels = nsbatwm.remove_labels_on_edges(labels)

# Measure properties
properties = ['label', 'area', 'perimeter', 'eccentricity', 'solidity']
measurements = regionprops_table(labels, properties=properties)
df = pd.DataFrame(measurements)

# Visualize the results
stackview.animate_curtain(image, labels)

# Display results
df.head()

This approach utilizes the watershed algorithm with local minima for segmentation, potentially offering enhanced accuracy in distinguishing cell shapes within the image.