Modified the loop to extract the tree of extremal regions