Hair Loss Considered Useful #
I've been working on removing the aforementioned "hairs" that can result when thinning an image. I chose to use the graph-based algorithm that I described earlier, and its implementation turned out to be very straightforward (the Liu paper did use graphs for something like this, but they seemed to be more concerned with merging points rather than deleting pixels outright).
The upper left image shows the original thinned image, with the pixels corresponding to edges (random colors) and vertices (endpoint ones in red, inner crossings in green). The first step in extracting these to features is to get the vertices. They can be determined by looking at the number of white to black crossings that a circular iteration over a pixel's neighborhood encounters (this method was also previously used to determine the number of times a pixel can be visited in the stroke extraction phase). Once we have the vertices, we can go out from each one, following non-background pixels until we reach another vertex. These pixels that are traversed make up an edge.
The image in the upper right corner shows the result of stroke extraction when the hairs have not been removed. As it can be seen, the rectangle is decomposed into three strokes, which isn't very helpful when trying to categorize the shape by looking at individual ones. The lower left corner shows the thinned image with the hairs removed. Currently, any edge that has at least one vertex be an endpoint (as opposed to a crossing) and is made up of less than half the average number of pixels per edge is declared to be a hair, and all of its constituent pixels are replaced with the background color. Finally, the lower right image shows the strokes extracted from this "hairless" image. As expected, the entire rectangle is made up of one stroke.
I've also tweaked the despeckling so that it now does hole filling if a pixel has at least 6 of its neighbors of a non-background color (as opposed to requiring that all of them be so). Not that this is of earth-shattering importance, but writing it down will hopefully remind of this change in the future, so that things like forgetting that I turned off despeckling for an entire month won't happen again.
Finally, I've been implementing the cleaner and more maintainable way of doing resampling. Ironically enough, it's also giving me trouble, but it seems like it's the way to go, I just need to sleep first.
Post a Comment