existing module for segmenting grey matter

You can search for SynthSeg either here (e.g. this post) on on google. It’s a very robust way to do brain segmentation.