Get list of coordinates from pixel image

Hi,
i displayed the geomerty (grid of points) by using color (black and white from thr maze) but now i want a list of the coordinates from only the black dots to connect elements to it.
i am only a beginner in this field so i dont really know how or where to begin with it, could anyone help me pls

Get the brightness value of each color, test it for equality to zero, and filter the points list by that boolean using a List.FilterByBoolMask node.

Hi,
here is the start of a different approach using the python library scikit-image

**The process : **

  1. analyze the image and get contours (polycurves)
  2. simplify polycurves
  3. make a negative offset (until the lines are approximately in the center)

The rest of the things to do:
4. group lines by distance and direction (parallel or not)
5. get all the start and end points of the lines for each group
6. for each group of Points, draw the best Line

Code CPython3
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('Python.Included')
import Python.Included as pyInc
path_py3_lib = pyInc.Installer.EmbeddedPythonHome
sys.path.append(path_py3_lib + r'\Lib\site-packages')
 
import numpy as np
from PIL import Image
from skimage import io
from skimage.io import imread
from skimage.measure import approximate_polygon, find_contours


def get_NewLine(lstCurve):
    #draw line with the most distant points 
    return Line.ByStartPointEndPoint(lstCurve[0].StartPoint, lstCurve[-1].EndPoint) 

def simply_Curves(lstCurve):
    ## FIRST PASS -> Group curve by same Vector##
    print(f"nbr Curves before : {len(lstCurve)}") 
    outCurve = []
    itersublst = iter(lstCurve)
    #get the 1st iter
    curvStart = next(itersublst)
    groupCurv = [curvStart]
    flag = True
    while flag:
        try:
            curv = next(itersublst)
            vectora = groupCurv[-1].Direction
            vectorb = curv.Direction
            if vectora.IsAlmostEqualTo(vectorb) :
                groupCurv.append(curv)
            else:
                outCurve.append(groupCurv)
                groupCurv = [curv]
        except StopIteration:
            outCurve.append(groupCurv)
            break       
            
    print(f"nbr Group founded : {len(outCurve)}") 
    ## SECOND PASS  -> convert List of curve with same vector to Line ##
    ##              -> convert long curve  to Line                    ##
    finalCurve2 = []
    for idx, sublstCurv in enumerate(outCurve):
        subgroup = []
        if len(sublstCurv) > 1:
            newLine = get_NewLine(sublstCurv)
            finalCurve2.append(newLine)
        elif len(sublstCurv) == 1:
            #convert long curve to line
            vectorb = sublstCurv[0].Direction 
            reverseCurvZ = sublstCurv[0].Reverse()
            vectorbStEnd = reverseCurvZ.Direction 
            if vectorbStEnd.IsAlmostEqualTo(vectorb): 
                newLine = Line.ByStartPointEndPoint(sublstCurv[0].StartPoint, sublstCurv[0].EndPoint)
                finalCurve2.append(newLine)
            else:   
                subgroup.append(sublstCurv[0])
        if len(subgroup) > 0:
            finalCurve2.extend(subgroup)
    print(f"nbr Curves after : {len(finalCurve2)}") 
    return finalCurve2

img_path = IN[0]
imag = Image.open(img_path).convert('L') 
img = np.asarray(imag)
print(type(img))
print(img.shape)
contours = find_contours(img, 60.0)
# 
result_contour = np.zeros(img.shape + (3, ), np.uint8)

group_lines = []

for contour in contours:
    print('Contour shape:', contour.shape)
    templines = []
    contour = contour.astype(int).tolist()
    # draw contour lines
    for idx, coords in enumerate(contour[:-1]):
        y1, x1, y2, x2 = coords + contour[idx + 1]
        # reverse the Y coordinates because the origin of Coordinates is different on images
        pta = Point.ByCoordinates(x1, -y1, 0)
        ptb = Point.ByCoordinates(x2, -y2, 0)
        if pta.DistanceTo(ptb) > 0.5:
            line = Line.ByStartPointEndPoint(pta, ptb)
            templines.append(line)
    group_lines.append(simply_Curves(templines))

OUT = group_lines
6 Likes