2

I'm currently working with Luajit Torch and I ran into a problem. I have a Tensor (2D matrix) whose numbers can be any positive integer or zero. I need to group all values that are not zero and find the center of mass of each of these groups. I'm trying to work the problem as it was a greyscale image, (where 0s would be black regions) and trying to find the non-black regions first and afterwards compute the center of mass of these regions, but I couldn't figure out the algorithm yet.

I'm still struggling on how to find the indices of the subgroups, thanks in advance!

  • 1
    That's basic connected components. Here's a good link on how you'd do it on a graph where an image is simply a 2D graph with the edges that connect to each of the pixels (or nodes in this case) in a 4 or 8 connected fashion: http://stackoverflow.com/questions/21078445/find-connected-components-in-a-graph. Failing that, you can use this package I found on graph algorithms with Lua: https://github.com/clementfarabet/lua---imgraph – rayryeng Dec 20 '16 at 15:36
  • I don't know much about Union-Find to I'd rather use imgraph, I'm still trying to figure out how it works exactly, as far as I can tell I should call .graph function to retrieve the graphs from the image and the call connectcomponents on the graph, is that right? – Eduardo Morgan Dec 20 '16 at 20:27
  • That's exactly it! – rayryeng Dec 20 '16 at 20:31
  • Thanks! I figured out I should turn my matrix into a graph, segment it and extract its components, which gives me a table contaning all the bounding boxes of the segments. However, something weird is happening, if I convolve my input matrix with a gaussian kernel, the bigger the kernel, less segments should be generated right? The thing is, the exactly opposite is happening, I am looking at this the wrong way? – Eduardo Morgan Dec 21 '16 at 12:03
  • Gaussian blurring tends to smooth edges and so to me it makes sense that more segments are generated. I really can't tell you unless I see an image. This is going beyond your question now. – rayryeng Dec 21 '16 at 16:12

0 Answers0