Used to detect connected groups of pixels in a black and white image.
bwconncomp.label
- Labels the connected componentsbwconncomp.centroids
- Identifies the centres (mean of pixels) of the labelled components.
$ git clone https://github.com/AaronJackson/torch-bwconncomp.git bwconncomp
Below we create a small 8x8 Tensor and use bwconncomp
to label the
connected groups of one:
th> bwconncomp = require('bwconncomp') [0.0007s] th> Z = torch.rand(8,8):gt(0.8) [0.0001s] th> Z 0 0 0 0 0 1 0 0 1 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 [torch.ByteTensor of size 8x8] [0.0031s] th> bwconncomp.label(Z) 0 0 0 0 0 1 0 0 2 0 3 3 3 0 0 0 0 0 0 0 3 0 0 4 0 0 0 0 3 0 0 0 0 5 0 0 0 0 6 7 8 0 0 0 0 9 0 0 0 0 0 10 10 0 0 0 11 0 0 0 0 0 0 12 [torch.IntTensor of size 8x8] [0.0033s] th>
Just a quick hack for work. :)