Converting an algorithm that works on 2D images for 3D

Analysis goals

The analysis is a post processing step. The algorithm helps to segment region of interest by a color. However I have arounf 20 images with these colored regions and now would like to look at the result as a 3d stack and not individual images. I would like to gain some assistance on how to connect the colored regions(which have certain grouping labels) between the individual images to have a compelete stack.