Image-Py / sknw

build net work from skeleton image (2D-3D)
BSD 3-Clause "New" or "Revised" License
224 stars 48 forks source link

strange behavior with character graphs #12

Open rfeinman opened 4 years ago

rfeinman commented 4 years ago

Hi, thank you for sharing this great python code.

I am trying to compute skeleton networks for images of handwritten characters (Omniglot dataset) and I've experienced strange behavior with some images. See figure below for a few examples. It seems that the network misses important edges in some cases; e.g. for the first character (column 1), the network misses the top-right curve completely. Do you know why this might be happening?

skeleton_graphs_omniglot

yxdragon commented 4 years ago

hi, see the multi graph parameter!

yxdragon commented 4 years ago

a tips: a small hole [column 1] and little touch [columns 2] may lead small ring in the graph. you can use skimage's remove_small_objects and binary_erode befor skeleton.

rfeinman commented 4 years ago

Ah yes, multigraph is exactly what I needed. Thank you!

I was already using morphology.remove_small_holes, but now I see that morphology.binary_erosion is also useful for some cases, such as column 2. Thanks for the tip.

rfeinman commented 4 years ago

One more question/request: is there an easy way to add the "maximum circle criterion" (Liao & Huang, 1990) for removing spurious branches and duplicate fork points? See image below for example. The algorithm places the largest possible circle on each critical point, such that the circle resides within the original ink (gray regions in d).

C.-W. Liao, J. S. Huang, Stroke segmentation by bernstein-bezier curve fitting. Pattern Recognit. 23, 475–484 (1990).

maximum_circle_criterion

yxdragon commented 3 years ago

Sorry for not review this issues for a long time. I think it is not difficult.

  1. iter every edge and mark the edges whitch not reach the limit.
  2. merge the node connected by marked edge to one

if it is useful for you, we can add another file to sknw, which do some graph repair. such as:

  1. remove the isolate node
  2. remove short branch
  3. remove the node whitch has just 2 edge (and combine the two edge to one)
  4. merge small circle as one node
  5. merge the node nearby to one ...
yxdragon commented 3 years ago

In my another repo, ImagePy (a ui framework for image processing) here integrate some sknw's function, there are "remove isolate node", "remove 2 edges' node", "cut branch" a topic on image.sc, here is some demo.

rfeinman commented 3 years ago

Hi - Thank you so much for getting back to me about this! Sorry it has taken me a while to reply.

I looked at your demo and its great. I don't think I want to remove 2-edge or isolate nodes for my application. Some isolate nodes in characters are important, like dots. And corners are instances of 2-edge nodes, which I'd like to keep.

The new algorithm that you suggested sounds simple and effective. If you have a working implementation, I'd love to take a look. Otherwise I will work on crafting my own version.

yxdragon commented 3 years ago

could you share a character image with many kinds of defect?

rfeinman commented 3 years ago

Here are two demonstrative examples of the issue. I am showing the image and the current skeleton network. The L-shaped character should probably only have 1 node in the corner (rather than two). The w-shaped character should have 4 nodes total, not 6.

char_img char_img_sknw