How to find subgroups of nonzeros inside 2D matrix?

92 Views Asked by At

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!

0

There are 0 best solutions below