Skip to content

Nucleus segmentation

Shijia Zhu edited this page Mar 7, 2023 · 21 revisions

Nucleus segmentation from the H&E image

STIE takes as input (but is not limited to) the nucleus segmentation implemented in the DeepImageJ, called “Multi-Organ Nucleus Segmentation model.” It is proposed by “Multi-Organ Nucleus Segmentation Challenge”, to train the generalized nucleus segmentation model in H&E stained tissue images. Following up, the nucleus location along with the nucleus morphological features were extracted for every single nucleus.

1. Installation of “Multi-Organ Nucleus Segmentation model by DeepImageJ”

With no need to install, users only need to download and unzip Fiji_MultiOrgan in one step, which works for Linux with X11.

The above file has included the following installments:

  1. download and install ImageJ/Fiji
  2. install imageJ plugin deepImageJ
  3. install imageJ plugin starDist
  4. install "Multi-Organ Nucleus Segmentation model" in deepImageJ

Thus, users can go to the folder of "Fiji_MultiOrgan", and run Fiji as a test. Please keep in mind the absolute path of Fiji_MultiOrgan/ImageJ-linux64, which will be used to run the imageJ macro below.

cd Fiji_MultiOrgan
./ImageJ-linux64
Screen Shot 2023-02-21 at 2 19 28 AM

Users may also want to tweak the memory and threads for ImageJ, in case the memory is insufficient when processing large images. Select Edit > Options > Memory&Threads... from the menu bar.

Screen Shot 2023-02-21 at 1 57 14 AM

2 Split the large image and segment the nucleus for split images

To reduce memory consumption, STIE runs the split_image() function to split the large H&E images into small images of 3000x3000 pixels. To avoid cells being split on the image boundary, each split image has four 100-pixel margins overlapping with its adjacent ones. The overlapped cells are checked from the four 100-pixel margins based on their location distance and cell diameter. The larger cell among overlapped cells was kept for the following analysis. Following up, the deepImageJ “Multi-Organ Nucleus Segmentation model” is run for each split image. The cell location and morphology features were extracted for every single cell using ImageJ ROI Manager. The imageJ macro was incorporated into run_imageJ_plugin() function to perform the nucleus segmentation. The absolute path of Fiji_MultiOrgan/ImageJ-linux64 in the above installation will be used in the run_imageJ_plugin() function to run the imageJ macro. Moreover, the user should specify a folder split_dir to save the intermediate results.

Two high-resolution images used as examples, CytAssist_FFPE_Mouse_Brain_Rep1_tissue_image.tif and CytAssist_FFPE_Mouse_Brain_Rep2_tissue_image.tif of two mouse brain consecutive sections are downloaded from the 10X Genomics public data: section 1 and section 2.

library(STIE)
library(magick)
library(EBImage)

## split image & run imageJ plugin
## image_path specifies the path to the high-resolution H&E image
split_image(image=image_path, split_dir=split_dir, 
            w=3000, h=3000, margin=100, x_scale=1 )

## if spot_coordinates specified, then only split image covered by the spots
# split_image(image=image_path, split_dir=split_dir, 
#             spot_coordinates = spot_coordinates,
#             w=3000, h=3000, margin=100, x_scale=1 )


## run imageJ macro on each split image in the split_dir
run_imageJ_plugin(
        imageJ = "/archive/SCCC/Hoshida_lab/s184554/Code/github/ImageJ/Fiji_MultiOran/ImageJ-linux64",
        plugin_macro = NULL,
        split_image_dir = split_dir, 
        pattern="tif$" )

After running the above codes, the segmentation results will be generated for each split image, including morphological values and masking images. Screen Shot 2023-02-21 at 1 50 05 AM

Screen Shot 2023-02-21 at 1 50 11 AM

3 Aggregate information from split images

Next, we aggregate the results from the split images and remove the redundancy from the overlapping margins.

cell_info <- merge_feature( split_dir )
morphology_fts <- cell_info$cell_feature
cell_contour <- cell_info$cell_contour
morphology_fts$pixel_x <- morphology_fts$X
morphology_fts$pixel_y <- morphology_fts$Y

## merge_feature may take some time, so, it is recommended to save it,
## and load it once the users rerun the STIE later on
save(cell_info, file=paste0(split_dir,"/cell_info.RData"))

Back to above