I was wondering if anyone can help me. My ultimate aim is to take an image like the one shown and draw line between the white and black blobs that show a direction and output the coordinates in the image. However, blobs should only be connected if they are on the adjacent vertex and blobs on the same vertex should not be connected i.e. a white blob should only connect to a black blob on its nearest neighbour.

enter image description here

Currently, I have been able to draw lines between blobs and give them a colour depending on their direction. I have also been able to exclude diagonal lines.

My current problem is my code is still drawing vertical and horizontal lines across the same vertex. I cannot use a distance limit as some of the nearest neighbour blobs are the same distance away as the ones on the same vertex.

I have managed to map the coordinates of the vertices using mouse clicks and store those in a list and I also have a list for the centre point between two blobs so I was hoping I'd be able to say - if the centre point of the line is too close to the vertex coordinate then don't draw a line.

for dark in keypoints_dark:
    xd = int(dark.pt[0]) #assigns x and y values and puts them as a coordinate
    yd = int(dark.pt[1])
    cd = (xd,yd)
      for light in keypoints_light:
        xl = int(light.pt[0])
        yl = int(light.pt[1])
        cl = (xl,yl)
        xa, ya = (xd+xl)/2, (yd+yl)/2
          for vertices in C:
            point_1 = geometry.Point(xa,ya)
            vertex = geometry.Point(vertices[0],vertices[1])

In the code, light and dark are the lists for all the light and dark blobs, C is a list with all of the vertex coordinates so I'm running through all of the dark and light coordinate pairs, calculating the centre point between the two and I'm then trying to compare the centre coordinates to all of the vertex coordinates however I can't seem to figure out a way to say if the centre matches any one of the vertex, then end the loop.

Thanks in advance for any help!


Here is an example of a before and after that is hand done. enter image description here

Currently what I'm getting for the first image is this. Some of the blobs arent being recognised but I can sort that. The issue is, for example, on the left vertical edge there are two blue lines going over two of the vertices which I don't want.

enter image description here

  • $\begingroup$ Can you please provide an additional image that shows the desired end result even if it had to be manually painted? Just to show what you are after better. $\endgroup$ – A_A Oct 12 '18 at 8:38
  • $\begingroup$ I've added an example image and what I'm currently getting. I can send the whole code if necessary but its a bit of a mess. $\endgroup$ – Kilian Oct 12 '18 at 9:41
  • $\begingroup$ Alright, is this electrophoresis? Or in any case, are the bright and dark spots supposed to have a specific relationship between them? (e.g, the dark spot, started as the bright spot but propagated to the left (or vice versa)). $\endgroup$ – A_A Oct 12 '18 at 14:08
  • $\begingroup$ No these are images from a magnetic force microscope. We have magnetized bars that are arranged in a square lattice. The magnetization runs from the dark spot to the light spot so the arrow represents the magnetization for a single bar. $\endgroup$ – Kilian Oct 13 '18 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.