def findLongestCentredSegmentinImage(imageName, gaussianKernelSize, sobelKernelSize, upperT, lowerT): # Read image into array and show inputImage, width, height = imageReadL(imageName) # Compute edges and find the segment in the image magnitude, _ = applyCannyEdgeDetector(inputImage, gaussianKernelSize, sobelKernelSize, upperT, lowerT) mainSegmentAverage = findLongestSegment(magnitude) # Compute centre numPoints = len(mainSegmentAverage) centre = [0, 0] for p in range(0, numPoints): centre[0] += (mainSegmentAverage[p])[0] centre[1] += (mainSegmentAverage[p])[1] centre[0] /= numPoints centre[1] /= numPoints # Respect to the center and convert to an image array shape = createImageF(numPoints, 2) for p in range(0, numPoints): y, x = (mainSegmentAverage[p])[0], (mainSegmentAverage[p])[1] shape[0, p] = y - centre[0] shape[1, p] = x - centre[1] return centre, shape, width, height
def findLongesSegmentinImage(imageName, gaussianKernelSize, sobelKernelSize, upperT, lowerT): # Read image into array and show inputImage, width, height = imageReadL(imageName) # Compute edges and find the segment in the image magnitude, _ = applyCannyEdgeDetector(inputImage, gaussianKernelSize, sobelKernelSize, upperT, lowerT) mainSegmentAverage = findLongestSegment(magnitude) # Convert to an image array numPoints = len(mainSegmentAverage) shape = createImageF(numPoints, 2) for p in range(0, numPoints): y, x = (mainSegmentAverage[p])[0], (mainSegmentAverage[p])[1] shape[0, p] = y shape[1, p] = x return shape, width, height
sobelKernelSize = 3 upperT = 0.4 lowerT = 0.2 kernelSize = 9 k = .02 op = "H" # Read image into array inputImage, width, height = imageReadL(pathToDir + imageName) # Show input image showImageL(inputImage) # We apply Canny to obtain the edges from the image # but also need the results of the Sobel operator (Gradient) magnitude, angle, mX, mY = applyCannyEdgeDetector(inputImage, GaussianKernelSize, sobelKernelSize, upperT, lowerT, True) \ # The center of the kernel kernelCentre = int((kernelSize - 1) / 2) # Compute curvature curvature = createImageF(width, height) for x,y in itertools.product(range(0, width), range(0, height)): # If it is an edge if magnitude[y,x] > 0: A, B, C = 0.0, 0.0, 0.0 for wx,wy in itertools.product(range(0, kernelSize), range(0, kernelSize)): posY = y + wy - kernelCentre posX = x + wx - kernelCentre if posY > -1 and posY < height and posX > -1 and posX < width:
upperT = 0.3 lowerT = 0.2 axisRange = [20, 65] angleRange = [0, 4] segmentLenghtThreshod = 0.20 pairsPerPoint = 30 # Sample points distance. Higher the eccentricity higher the distance so points give accurate positions axisRatio = float(axisRange[1]) / (2.0 * float(axisRange[0])) deltaPointRange = [int(axisRatio * axisRange[0]), int(1.2 * axisRange[1])] # Read image #49 20 0.03490658503988659 125 77 2 inputImage, width, height = imageReadL(pathToDir + imageName) # Compute edges magnitude, angle = applyCannyEdgeDetector(inputImage, gaussianKernelSize, sobelKernelSize, upperT, lowerT) showImageF(magnitude) # Find segments segmentsList = [] segmentsImage = createImageF(width, height) maxSegmentLenght = 0 for x, y in itertools.product(range(0, width), range(0, height)): if magnitude[y, x] != 0 and segmentsImage[y, x] == 0: segment = [] segmentPoints = [(y, x)] segmentsImage[y, x] = 255 while len(segmentPoints) > 0: yc = (segmentPoints[0])[0] xc = (segmentPoints[0])[1] segment.append((yc, xc))
suppWindow = Size of the window used to find maxima ''' pathToDir = "../../Images/Chapter8/Input/" imageName = "Logs.png" cannyKernelSize = 7 upperT = 0.5 lowerT = 0.1 windowDelta = 3 suppWindow = 5 # Read image into array and show inputImage, width, height = imageReadL(pathToDir + imageName) showImageL(inputImage) # Compute edges magnitude, angle = applyCannyEdgeDetector(inputImage, cannyKernelSize, cannyKernelSize, upperT, lowerT) showImageF(magnitude) # Divide pixels into edge and region pixels edgePixels = [] shapeImage = [] for x, y in itertools.product(range(0, width), range(0, height)): if magnitude[y, x] > 0: edgePixels.append((y, x)) shapeImage.append((y, x)) # Radial is the minimal distance to the edge distanceImage = createImageF(width, height) numEdges = len(edgePixels) for x in range(0, width): printProgress(x, width)