Implementation of the similar logic can also be seen at https://www.academicblock.com/technology/web-tools/convert-an-image-to-black-and-white This Matlab GUI code ...
Code (in Matlab and R) to perform a spherical rotation (permutation) of a parcellated cortical map. Includes coordinates on the Freesurfer sphere of 360 regions from the Glasser et al. Nature 2016 HCP ...