Two-photon fluorescence microscopy (TPFM) allows in situ investigation of the structure and function of the brain at a cellular level, but the conventional image analyses of TPFM data are labour-intensive. Automated deep learning (DL)-based image processing pipelines used to analyze TPFM data require large labeled training datasets. Here, we developed a self supervised learning (SSL) pipeline to test whether unlabeled data can be used to boost the accuracy and generalizability of DL models for image segmentation in TPFM. We specifically developed four pretext tasks, including shuffling, rotation, axis rotation, and reconstruction, to train models without supervision using the UNet architecture. We validated our pipeline on two tasks (neuronal soma and vasculature segmentation), using large 3D microscopy datasets. We introduced a novel density-based metric, which provided more sensitive evaluation to downstream analysis tasks. We further determined the amount of labeled data required to reach performance on par with fully supervised learning (FSL) models. SSL-based models that were fine-tuned with only 50% of data were on par or superior (e.g., Dice increase of 3% for neuron segmentation and Dice score of 0.88 +/- 0.09 for vessel segmentation) to FSL models. We demonstrated that segmentation maps generated by SSL models pretrained on the reconstruction and rotation tasks can be better translated to downstream tasks than can other SSL tasks. Finally, we benchmarked all models on a publicly available out-of-distribution dataset, demonstrating that SSL models outperform FSL when trained with clean data, and are more robust than FSL models when trained with noisy data.