Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
Ajuste de curvas en imágenes 2D con datos faltantes

Tengo contornos divididos en una imagen y quiero conectarlos asumiendo que son curvas parametrizadas. Estaba considerando algún ajuste de curva o trazado de curvas, pero no sé cómo puedo implementarlo.

Tengo exactamente contornos divididos de 1 px de ancho:

 import itertools import cv2 # Get all pixel directions directions = list(itertools.product([-1, 0, 1], repeat=2)) directions.remove((0, 0)) # Load image img = cv2.imread("image.png", cv2.IMREAD_COLOR) gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) cv2.imshow("Input", img) # Find contours _, thresh = cv2.threshold(gray, 25, 255, cv2.THRESH_BINARY) contours, _ = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)

contornos

Sé dónde están los extremos de todos los contornos:

 for cnt in contours: ends = [] # Get ends of contour # - first pixel is not always the first pixel of open contour # - last pixel is not mostly the last pixel in contour for pix in cnt: pixel = tuple(pix[0]) pixel_x, pixel_y = pixel total_neighbours = 0 # Count pixel neighbours for plus_x, plus_y in directions: current_x = pixel_x + plus_x current_y = pixel_y + plus_y if current_y < 0 or current_y >= gray.shape[0]: continue if current_x < 0 or current_x >= gray.shape[1]: continue if gray[current_y][current_x]: total_neighbours += 1 # If it is end pixel if total_neighbours == 1: ends.append(pixel) cv2.circle(img, pixel, 3, (0, 255, 255), 1)

ingrese la descripción de la imagen aquí

Como ser humano, sé dónde están las curvas y qué contornos forman parte de cada curva única:

extremos de contornos

Para la buena imaginación humana, hay imágenes en bruto:

Imagen de origen 1 Imagen de origen 2

Pero no sé, ¿cómo puedo conectar estos contornos divididos mediante programación ? Intenté usar la primera y la segunda derivada para predecir, pero no fue lo suficientemente bueno:

 # Make contour "predictions" by first derivative # - go from end to second end and calculate first derivative # - "predict" on second end contour connection for end in ends: pixel_x, pixel_y = end def predict(pixel_x, pixel_y, was): for plus_x, plus_y in directions: current_x = pixel_x + plus_x current_y = pixel_y + plus_y if current_y < 0 or current_y >= gray.shape[0]: continue if current_x < 0 or current_x >= gray.shape[1]: continue if (current_x, current_y) not in ends: if (current_x, current_y) not in was: if gray[current_y][current_x]: was.append((current_x, current_y)) predict(current_x, current_y, was) else: derivatives_x = [] derivatives_y = [] # Calculate derivative for pix in range(len(was) - 3): x1, y1 = was[pix] x2, y2 = was[pix + 3] derivatives_x.append(x1 - x2) derivatives_y.append(y1 - y2) if not derivatives_x: continue # Get last N derivatives and average them avg_x = derivatives_x[-20:] avg_y = derivatives_y[-20:] avg_x = sum(avg_x) / len(avg_x) avg_y = sum(avg_y) / len(avg_y) # Predict N pixels for i in range(7): pos = round(x2 - avg_x * i), round(y2 - avg_y * i) cv2.circle(img, pos, 1, (0, 0, 255), cv2.FILLED) predict(pixel_x, pixel_y, []) cv2.imshow("First derivative", img) cv2.waitKey(0)

primera derivada segunda derivada

¿Alguien sabe cómo ajustarle alguna curva/spline/Bezier/.. y reconocer las curvas como un ser humano?

Hay más imágenes fuente binarizadas:

otra imagen binarizada 1 otra imagen binarizada 2

otra imagen binarizada 5 otra imagen binarizada 4 otra imagen binarizada 3

Gracias.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!