TITLE: Neuromelanin quantification in stained brain slices of the Locus coeruleus 
AUTHORS: Csilla Novák, Maria P. Contreras, Matthias Prigge

[DESCRIPTION]
This protocol describes an automatizable pipeline for cell counting based on fluorescent stainings with the help of CellPose. Additionally, it describes the entire generation process of plots that show the intensity of neuromelanin per cell based on bright-field images. The protocol includes Fiji macro codes for data analysis and an R code for plot generation. This pipeline has been used for the analysis of locus coeruleus data.

[STEPS]
SECTION: Image optimization and cropping
1. Start with images of 35μm thick slices of one z-plane and merged channels. In case of several z-planes, create a Maximum Intensity or a Sum Slices projection in ImageJ/Fiji. 
SECTION: Image optimization and cropping
3. Crop the area that you would like to analyze.
SECTION: Image optimization and cropping
2. Separate the channels and save each channel with an informative title in TIFF format (eg. channel_mouse-id_slice-info_side.tif). It is useful to use the same type of separator between each piece of information.
SECTION: Fluorescent image analysis with CellPose
4. Install CellPose following these steps: https://pypi.org/project/cellpose/. You can use Nvidia GPUs to make the software more efficient.
SECTION: Fluorescent image analysis with CellPose
5. Open CellPose and drag a fluorescent image over the gui to open it.
SECTION: Fluorescent image analysis with CellPose
6. Estimate your average cell size; you can do it with the help of Fiji.
 
 
 Press enter. On the bottom left of the picture you will see a pink circle which has the diameter that you have specified.
SECTION: Fluorescent image analysis with CellPose
7. Choose which channel to segment. (Gray works for any image with only one channel.)
SECTION: Fluorescent image analysis with CellPose
8. Find a reliable model.
SECTION: Fluorescent image analysis with CellPose
8.1. Try pretrained models. You can do it by clicking on any of these. The compute style and run suggested model will suggest a model for you. Try cyto2 - this is probably the most robust model so far.
 
 
 

SECTION: Fluorescent image analysis with CellPose
8.2. If the pretrained models do not give a reliable segmentation, choose the pretrained model that works the best and train it to become better. You can remove unnecessary masks by holding Ctrl and clicking on the mask. If you want to draw more masks, go to the edge of a cell, right click, and then you can draw the outline of the cell. The resulting image+masks will be automatically saved in the folder of the image in an *.npy format.
SECTION: Fluorescent image analysis with CellPose
9. Segment your images. That is: drag each image to the gui, run the model that you chose, take note of the number of identified ROIs and save your masks. Save them in one folder in PNG format for further analysis. It is possible to automate this step in 
 
, but only with pretrained models.
SECTION: Fluorescent image analysis with CellPose
8.3. Create your training dataset. You should have at least 20 reliable *.npy files saved in the same folder.
SECTION: Fluorescent image analysis with CellPose
8.4. Train a model (Ctrl+T). You have to choose the initial (pretrained) model, you can specify the learning rate, the weight decay and the number of epochs. ~500 epochs can give a reliable, but not overfitted model. Give a name to your network. On the right, you can see all the *.npy files in your folder which will be used as the training dataset.
 
 
 
SECTION: Neuromelanin quantification per cell (based on TH staining and bright-field)
10. Save your bright-field images and the CellPose masks based on the TH staining images in two separate folders. Make sure that the two folders contain the same amount of images, and the images are in the correct order (so that the first bright-field image corresponds to the first CellPose mask, the 2nd to the 2nd and so on).
SECTION: Neuromelanin quantification per cell (based on TH staining and bright-field)
11. Open ImageJ/Fiji. Go to Analyze > Set measurements, and untick every option, except for Mean gray value.
SECTION: Neuromelanin quantification per cell (based on TH staining and bright-field)
12.  Then go to Plugins > New > Macro and copy the following macro:
 
This macro loops over the two folders and saves the mean gray value of each TH+ ROI identified by CellPose on each bright-field image. Each line corresponds to one image, and each cell is an ROI. The values are distributed between 0 and 255, where 255 is white, and 0 is black.
If you use Excel to open the *.csv file, you might have to set the separator to be a semicolon.
SECTION: Neuromelanin quantification per cell (based on TH staining and bright-field)
14. Add a few columns to the beginning of the csv. Copy and paste all your image paths from one folder (select all files in your file manager, and copy path) and convert these paths into useful columns. Ctrl+H helps to delete unnecessary information (eg. folder info). In Excel or in LibreOffice, go to Data and Text to columns, and choose the separator which you use in your file names. Name your columns. If it is necessary, add a column which contains information about the experimental group.
SECTION: Neuromelanin quantification per cell (based on TH staining and bright-field)
15. In ImageJ/Fiji, Go to Analyze > Set measurements, and untick every option, except for Modal gray value.
SECTION: Neuromelanin quantification per cell (based on TH staining and bright-field)
16.  Then go to Plugins > New > Macro and copy the following macro:
 
Run this macro, and copy the results into one empty column of your csv. This is the modal gray value of each bright-field image, which is important for the normalization of the data.
At this point, your csv should look approximately like this:

 
In this example, ap refers to the approximate anterioposterior position of each slice calculated from Bregma.


SECTION: Neuromelanin quantification per cell (based on TH staining and bright-field)
13. Name every column starting with v1.
SECTION: Neuromelanin quantification per cell (based on TH staining and bright-field)
17. 
 
Open RStudio, create a new R notebook and copy the following code to visualize the distribution of the ROI intensities. This code presupposes a dataset with two experimental groups ('side' variable) and four different time points ('time' variable). However, you can adjust this code to your needs, for example, if you do not have a 'time' variable, you can remove it from the code.
 

SECTION: Neuromelanin quantification per cell (based on TH staining and bright-field)
18. Calculate statistics.