Questions tagged [connected-components]

Connected-component labeling (alternatively connected-component analysis, blob extraction, region labeling, blob discovery, or region extra

Connected-component labeling (alternatively connected-component analysis, blob extraction, region labeling, blob discovery, or region extra

274 questions
58
votes
3 answers

How to use openCV's connected components with stats in python?

I am looking for an example of how to use OpenCV's ConnectedComponentsWithStats() function in python, note this is only available with OpenCV 3 or newer. The official documentation only shows the API for C++, even though the function exists when…
Zack Knopp
  • 2,207
  • 2
  • 10
  • 13
48
votes
14 answers

Merge lists that share common elements

My input is a list of lists. Some of them share common elements, eg. L = [['a','b','c'],['b','d','e'],['k'],['o','p'],['e','f'],['p','a'],['d','g']] I need to merge all lists, that share a common element, and repeat this procedure as long as there…
WlJs
  • 787
  • 1
  • 7
  • 12
24
votes
2 answers

connected component labeling in python

How to implement connected component labeling in python with open cv? This is an image example: I need connected component labeling to separate objects on a black and white image.
21
votes
3 answers

Detecting object regions in image opencv

We're currently trying to detect the object regions in medical instruments images using the methods available in OpenCV, C++ version. An example image is shown below: Here are the steps we're following: Converting the image to gray…
Maystro
  • 2,767
  • 6
  • 29
  • 68
17
votes
4 answers

How to aggregate matching pairs into "connected components" in Python

Real-world problem: I have data on directors across many firms, but sometimes "John Smith, director of XYZ" and "John Smith, director of ABC" are the same person, sometimes they're not. Also "John J. Smith, director of XYZ" and "John Smith, director…
Ian Gow
  • 2,036
  • 1
  • 18
  • 26
13
votes
4 answers

Python connected components

I'm writing a function get_connected_components for a class Graph: def get_connected_components(self): path=[] for i in self.graph.keys(): q=self.graph[i] while q: print(q) v=q.pop(0) if…
fege
  • 519
  • 2
  • 6
  • 18
10
votes
1 answer

Obtaining connected components in R

I have a matrix with values 0 or 1 and I would like to obtain a list of groups of adjacent 1's. For example, the matrix mat = rbind(c(1,0,0,0,0), c(1,0,0,1,0), c(0,0,1,0,0), c(0,0,0,0,0), …
Instanton
  • 359
  • 3
  • 12
9
votes
0 answers

Connected components on Pandas DataFrame with Networkx

Action To cluster points based on distance and label using connected components. Problem The back and forth switching between NetworkX nodes storage of attributes and Pandas DataFrame Seems too complex Index/key errors when looking up…
Tom Hemmes
  • 1,498
  • 1
  • 13
  • 19
9
votes
2 answers

Spark: What is the time complexity of the connected components algorithm used in GraphX?

GraphX comes with an algorithm for finding connected components of a graph. I did not find a statement about the complexity of their implementation. Generally, finding connected components can be done in linear time, for instance by a breadth-first…
9
votes
1 answer

get connected components using igraph in R

I would like to find all the connected components of a graph where the components have more than one element. using the clusters gives the membership to different clusters and using cliques does not give connected components. This is a follow up…
Dinesh
  • 2,104
  • 2
  • 24
  • 44
9
votes
1 answer

How to find all connected components in a binary image in Matlab?

I have been trying to find all connected components using 8 neighbors in a binary image, without using the function "bwlabel". For example, my input matrix is: a = 1 1 0 0 0 0 0 1 1 0 0 1 1 …
7
votes
1 answer

OpenCV Python cv2.connectedComponentsWithStats

Is it by design that you must pass cv2.connectedComponentsWithStats a white-on-black image as opposed to a black-on-white image? I get different results doing one versus the other. Example Code: import os import cv2 root = r'pth/to/img' fl =…
A. Hendry
  • 1,521
  • 2
  • 11
  • 19
6
votes
2 answers

Python iterate through connected components in grayscale image

I have a gray scale image with values between 0 (black) and white (255). I have a target matrix of the same size as the gray scale image. I need to start at a random pixel in the gray scale image and traverse through the image one pixel at a time…
RaviTej310
  • 1,345
  • 2
  • 19
  • 46
6
votes
3 answers

python find connected components in a 3D graph / tuple with three elements?

I have a binary 3D numpy array, for which I would like to find connected components, i.d. neighbor elements with value 1. data = np.random.binomial(1, 0.4, 1000) data = data.reshape((10,10,10)) Alternatively I can get the coordinates for each…
hirschme
  • 518
  • 1
  • 5
  • 21
6
votes
3 answers

How to count all the connected nodes (rows) in a graph on Postgres?

My table has account_id and device_id. One account_id could have multiple device_ids and vice versa. I am trying to count the depth of each connected many-to-many relationship. Ex: account_id | device_id 1 | 10 1 | 11 1 | 12 2 | 10 3 | 11 3 | 13 3 |…
cvax
  • 346
  • 4
  • 10
1
2 3
18 19