Implement flood_fill(image, r, c, color): change the pixel at (r, c) and every pixel connected to it (up/down/left/right) that has the same original color to color. Return a new image (don't modify the input), and use an explicit stack so large regions don't hit the recursion limit.
Also implement count_regions(image): the number of connected same-color regions.