Pergunta

In my current data analysis I have some segmented Images like for example below.

My Problem is that I would like to fit a polynom or spline (s.th. one-dimensional) to a certain area (red) in the segmented image. ( the result would be the black line).

Usually i would use something like orthogonal distance regression, the problem is that this needs some kind of fit function which I don't have in this case. So what would be the best approach to do this with python/numpy? Is there maybe some standard algorithm for this kind of problem?

example

UPDATE: it seems my drawing skills are probably not the best, the red area in the picture could also have some random noise and does not have to be completely connected (there could be small gaps due to noise).

UPDATE2: The overall target would be to have a parametrized curve p(t) which returns the position i.e. p(t) => (x, y) for t in [0,1]. where t=0 start of black line, t= 1 end of black line.

Foi útil?

Solução

I used scipy.ndimage and this gist as a template. This gets you almost there, you'll have to find a reasonable way to parameterize the curve from the mostly skeletonized image.

from scipy.misc import imread
import scipy.ndimage as ndimage

# Load the image
raw = imread("bG2W9mM.png")

# Convert the image to greyscale, using the red channel
grey = raw[:,:,0]

# Simple thresholding of the image
threshold = grey>200

radius = 10
distance_img = ndimage.distance_transform_edt(threshold)
morph_laplace_img = ndimage.morphological_laplace(distance_img, 
                                                  (radius, radius))
skeleton = morph_laplace_img < morph_laplace_img.min()/2

import matplotlib.cm as cm
from pylab import *
subplot(221); imshow(raw)
subplot(222); imshow(grey, cmap=cm.Greys_r)
subplot(223); imshow(threshold, cmap=cm.Greys_r)
subplot(224); imshow(skeleton, cmap=cm.Greys_r)
show()

enter image description here

You may find other answers that reference skeletonization useful, an example of that is here:

Problems during Skeletonization image for extracting contours

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top