Finding components of an image


Here are six different versions of a function for finding components of an image, as well as two sample images (billiken.gif and billiken.png).

m-files

  1. findComponent1.m
    A "depth-first" exploration, that maintains a fringe in similar form to our maze solver, always expanding one-step from the end of the fringe, or removing that end if no further steps are possible.

  2. findComponent2.m
    The same exploration approach as findComponent1.m, but this time implemented using a recursive function, rather than an explicit management of the fringe. From each spot, we recursively explore all of its legal neighbors, in turn.

  3. findComponent3.m
    A variant of the first program in which we add all legal neighbors of a position to the fringe and the component at once (the original program would add one neighbor of a given position, then iterate an exploration of that neighbor, and then later add another neighbor of the given position).

  4. findComponent4.m
    A "breadth-first" variant of findComponenet3.m. When choosing which item of the fringe to explore next, this variants chooses the first entry of the fringe rather than the last. The first entry is the earliest fringe element to have been discovered. This breadth-first variant can be used to find shortest paths from the starting point, as it first finds all locations that are one step from the start, then all that are two steps from the start, and so on.

  5. findComponent5.m
    A variant of findComponent4.m in which we relax the requirement that a neighboring color be an exact match to be included in the component.

    This version is written for images (such as billiken.gif) that use a color map. In this case, we can not determine the similarity between colors by the color indices, but rather must go into the color map to get the (r,g,b) values associated with two different indices.


  6. findComponent6.m
    A variant of findComponent4.m in which we relax the requirement that a neighboring color be an exact match to be included in the component.

    This version is written for images (such as billiken.png) that provide full (r,g,b) color information in the image array.

Images


By:
Michael Goldwasser