-
Notifications
You must be signed in to change notification settings - Fork 0
Segment Each Structure
The instructions in this section apply to any structure that you want to segment, but I will refer to segmenting the nuclei as an example.
Here, we will use an algorithm (of the user's choosing) to guess the 2D segmentation for the structure.
-
For each structure you want to segment, make a folder called segmentations_X where X is nuclei, lumens, organoid, or buds. This folder should be in the data folder.
-
Make the segmentations folder MATLAB's working directory.
>> cd segmentations_nuclei;
-
Guess the 2D segmentation.
>> organoids2.guess_2D_segmentations;
-
Select the algorithm you want to use. Technically, you can use any algorithm for any structure (organoids, lumens, nuclei, buds), but certain algorithms are best for different structures (see below).
- Using nucleaizer - useful for nuclei - This will prepare the data so that you can run nucleaizer (on the lab GPU).
- Using flood algorithm - useful for lumens and organoids - This will attempt the guess the segmentation automatically.
- Using GUI to draw on max merge - useful for buds - This will open a GUI that allows you to draw the 2D segmentation over the max merge of the image. It is useful when the 2D segmentation does not change much throughout the stack (i.e. for buds).
-
Depending on the algorithm you selected, continue the guessing.
-
Tell the code what channel you would like to use (dapi).
-
Copy the "slices_XY" and "slices_XZ" folders from the "segmentations_nuclei" folder to a USB drive.
-
Alternatively, if you want to run nucleaizer on multiple main folders, you can run an optional script that will format the images so you need only run nucleaizer once. The input to this script should be a cell of paths to the main folders to include.
>> cd /Volumes/LAUREN_TEMP/ >> path_to_images = {'~/Desktop/well06_5ngmLHGF', '~/Desktop/well07_20ngmLHGF'}; >> run_nucleaizer_batch_preprocess(paths_to_images);
-
-
Plug that USB drive into the lab's GPU.
-
On the GPU, open the Command Prompt.
-
In the Command Prompt, change the directory to the one containing the nucleaizer code.
$ cd \Users\lab\Documents\nucleaizer\biomagdsb-master
-
In the Command Prompt, enter the virtual environment containing the relevant Python code.
$ env\Scripts\activate
-
In Notepad, open the start_prediction_fast.bat file (found in biomagdsb-master folder). Edit the line to store the path to the images to segment. Save the changes. For example, the line might read:
set "images_dir=D:\slices_XY"
-
Make sure the following folders are empty. This is important because all images in the first folder (NOT just the images in the directory you pointed the code to) are segmented.
- biomagdsb-master\kaggle_workflow\outputs\images
- biomagdsb-master\kaggle_workflow\outputs\presegment
-
In the Command Prompt, run “start_prediction_fast”.
-
Once done, copy the contents of the "presegment" folder (in biomagdsb-master/kaggle_workflow/outputs) to a folder called "results" in the folder you just worked on.
-
Repeat for the "slices_XZ" folder. This will segment the orthogonal images so we can connect the 2D segmentations into 3D segmentations.
-
Plug the USB back into your computer and copy the files from both of the "results" folders to their respective folders in the main folder.
-
Alternatively, if you ran nucleaizer on images from many main folders, run the postprocessing script to put the result images in their proper folders.
>> cd /Volumes/LAUREN_TEMP/ >> run_nucleaizer_batch_postprocess;
-
- Tell the code what tolerance you would like to use. This tolerance is the expected intensity difference between the background and the structure of interest.
- For MDCK organoids, 3000 works well for lumens and 1000 works well for organoid.
- Tell the code what channel you would like to use to guess the segmentations.
- For MDCK organoids, this is gfp for segmenting lumens and organoid.
- For Intestine organoids, this is tmr for segmenting lumens and organoid.
- Sometimes, when looking at the results from this algorithm in the next step (reviewing the guessed segmentations), I do not like the results. You can re-run the code with different tolerances to try and correct this.
- Simply using the GUI to draw the segmentations you need. Though you only see the max merge of the stack, the segmentations you draw will be applied to each slice.
-
-
Once you have finished guessing the segmentations, prepare them for review.
>> organoids2.prepare_2D_segmentations_for_review;
Here, we can review (and change, if necessary) the segmentations from the prior step.
-
Make the segmentations folder MATLAB's working directory.
>> cd segmentations_nuclei;
Here, we will convert the 2D segmentations to 3D.
-
Make the segmentations folder MATLAB's working directory.
>> cd segmentations_nuclei;
This currently does not work.
-
Make the segmentations folder MATLAB's working directory.
>> cd segmentations_nuclei;