Пример #1
0
def load_scenes(filename):
    zipped_scenes = []
    print 'Working on: ' + filename
    img = data.imread('scenes/' + filename, as_grey=True)
    tmp = img
    tmp = filter.canny(tmp, sigma=2.0)
    tmp = ndimage.binary_fill_holes(tmp)
    #tmp = morphology.dilation(tmp, morphology.disk(2))
    tmp = morphology.remove_small_objects(tmp, 2000)
    contours = measure.find_contours(tmp, 0.8)
    ymin, xmin = contours[0].min(axis=0)
    ymax, xmax = contours[0].max(axis=0)
    if xmax - xmin > ymax - ymin:
        xdest = 1000
        ydest = 670
    else:
        xdest = 670
        ydest = 1000
    src = np.array(((0, 0), (0, ydest), (xdest, ydest), (xdest, 0)))
    dst = np.array(((xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)))
    tform3 = tf.ProjectiveTransform()
    tform3.estimate(src, dst)
    warped = tf.warp(img, tform3, output_shape=(ydest, xdest))
    tmp = filter.canny(warped, sigma=2.0)
    tmp = morphology.dilation(tmp, morphology.disk(2))
    descriptor_extractor.detect_and_extract(tmp)
    obj_key = descriptor_extractor.keypoints
    scen_desc = descriptor_extractor.descriptors
    zipped_scenes.append([warped, scen_desc, obj_key, filename])
    return zipped_scenes
Пример #2
0
def canny(data, sigma=1, sliceId=2):
    edges = np.zeros(data.shape, dtype=np.bool)
    if sliceId == 2:
        for idx in range(data.shape[2]):
            edges[:, :, idx] = skifil.canny(data[:, :, idx], sigma=sigma)
    elif sliceId == 0:
        for idx in range(data.shape[0]):
            edges[idx, :, :] = skifil.canny(data[idx, :, :], sigma=sigma)
    return edges
Пример #3
0
 def _canny_edge_fired(self):
     self.im = self.orig
     r,g,b = np.rollaxis(self.im,axis=-1)
     edge_r = canny(tv_denoise(r, weight=1))
     edge_g = canny(tv_denoise(g, weight=1))
     edge_b = canny(tv_denoise(b, weight=1))
     edges = edge_r + edge_g + edge_b
     self.im = np.dstack((edges,edges,edges))
     self.im[self.im > 0.] = 1.
     try:
         self.axes.imshow(self.im)
         self.figure.canvas.draw()
     except:
         pass        
Пример #4
0
    def segment(self, src):


        ndsrc = src.ndarray / 255.
        edges = canny(ndsrc,
#                      low_threshold=0.001,
#                      high_threshold=0.1,

#                      low_threshold=self.canny_low_threshold,
#                      high_threshold=self.canny_high_threshold,
                      sigma=self.canny_sigma)
        filled = ndimage.binary_fill_holes(edges)
        filled = invert(filled) * 255
#        label_objects, _ = ndimage.label(filled)
#        sizes = bincount(label_objects.ravel())
#
#        mask_sizes = sizes > 1
#        mask_sizes[0] = 0
#        cleaned = mask_sizes[label_objects]
#        cleaned = asarray(cleaned, 'uint8')
#        cleaned = closing(cleaned, square(5))

#        self._locate_helper(invert(cleaned), **kw)
        nsrc = asarray(filled, 'uint8')
        return nsrc
Пример #5
0
    def find_edges(self,sigma=None):
        if sigma is not None:
            self.sigma = sigma

        print 'Identifying edges...'
        self.edges = filter.canny(self.data,sigma=self.sigma)
        return self.edges
Пример #6
0
def getRegions():
    """Geocode address and retreive image centered
    around lat/long"""
    address = request.args.get('address')
    results = Geocoder.geocode(address)
    lat, lng = results[0].coordinates
    zip_code = results[0].postal_code

    map_url = 'https://maps.googleapis.com/maps/api/staticmap?center={0},{1}&size=640x640&zoom=19&sensor=false&maptype=roadmap&&style=visibility:simplified|gamma:0.1'
    request_url = map_url.format(lat, lng)
    req = urllib.urlopen(request_url)
    img = io.imread(req.geturl(),flatten=True)
    labels, numobjects = ndimage.label(img)
    image = filter.canny(img, sigma=3)
    thresh = threshold_otsu(image)
    bw = closing(image > thresh, square(3))

    # remove artifacts connected to image border
    cleared = bw.copy()
    clear_border(cleared)

    # label image regions
    label_image = label(cleared)
    borders = np.logical_xor(bw, cleared)
    label_image[borders] = -1
    image_label_overlay = label2rgb(label_image, image=image)

    fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
    ax.imshow(image_label_overlay)
Пример #7
0
def canny(parameters):
    """Canny edge extraction filter.

    This wraps `skimage.filter.canny`. The `low_threshold`, `high_threshold`
    and `mask` options are not supported.

    The wrapped function returns a boolean array with pixel values True or
    False. Since it is not very convenient to pass such an array to other
    functions, the return value is cast to uint8, thus containing 0 or 1
    values.

    ..warning::

        During testing there have been some issues with the results. Check the
        corresponding test function for details.

    :param parameters['data'][0]: input image
    :type parameters['data'][0]: numpy.array
    :param parameters['sigma']: standard deviation of the gaussian filter,
                                defaults to 1.0
    :type parameters['sigma']: float

    :return: numpy.array, with dtype('uint8') containing 0 or 1 values

    """
    img = parameters['data'][0]
    sigma = parameters.get('sigma', 1.0)

    result = filter.canny(img, sigma=sigma)

    return result.astype('uint8')
Пример #8
0
def auto_canny(array, average=None, gaussian_sigma=1, strongness=2.5):
    if average is None:
        average = array.size ** 0.5 / array.size
    array -= array.min()
    array /= array.max()

    def canny_average(hard_threshold):
        soft_threshold = hard_threshold / strongness
        edges = canny(array, gaussian_sigma, hard_threshold, soft_threshold)
        return edges.mean()

    hard_threshold = 0.4
    epsilon = 0.0001
    bottom, top = 0., 1.
    for iteration in xrange(20):
        current_average = canny_average(hard_threshold)
        print(hard_threshold, current_average)
        if abs(current_average - average) < epsilon:
            break
        elif current_average < average:
            top = hard_threshold   
            hard_threshold = (bottom + top) / 2
        else:
            bottom = hard_threshold
            hard_threshold = (bottom + top) / 2
    else:
        print("Agotados los intentos")

    soft_threshold = hard_threshold / strongness
    return canny(array, gaussian_sigma, hard_threshold, soft_threshold)
Пример #9
0
def CanNuc(datatype, maxrange, outputfile, outputfiletype):
	h = open(outputfile, outputfiletype)
	TC = 0	
	for i in range(0, maxrange):
		A = datatype[i][0]
		T = mahotas.thresholding.otsu(A)
		C = A.copy()
		if T < 1:
			C[ C <= T ] = 0
			C[ C > T ] = 1
		else:
			C[ C < T ] = 0
			C[ C >= T ] = 1
		filled = scipy.ndimage.morphology.binary_fill_holes(C)
		filled = filled.astype(np.uint8)
		edges1 = filter.canny(filled, sigma=1)
		edges1 = edges1.astype(np.uint8)
		edges1 = np.where(edges1 == 1)
		TC += len(edges1[0])
		XY1 = np.vstack((edges1[0], edges1[1], [i*5]*len(edges1[0])))
		for p in range(0, len(XY1[0])):
			for yel in range(0, len(XY1)):
				h.write(str(XY1[yel][p]) + '\t')
			h.write('\n')
	h.write(str(TC) + '\n')
	h.write('.' + '\n')
	h.close()
Пример #10
0
def main():
    plt.figure(figsize=(25, 24))
    planes = ['samolot00.jpg', 'samolot01.jpg', 'samolot03.jpg', 'samolot04.jpg', 'samolot05.jpg','samolot07.jpg',
              'samolot08.jpg', 'samolot09.jpg', 'samolot10.jpg', 'samolot11.jpg', 'samolot12.jpg', 'samolot13.jpg',
              'samolot14.jpg', 'samolot15.jpg', 'samolot16.jpg', 'samolot17.jpg', 'samolot18.jpg', 'samolot20.jpg']
    i = 1
    for file in planes:
        img = data.imread(file, as_grey=True)
        img2 = data.imread(file)
        ax = plt.subplot(6, 3, i)
        ax.axis('off')
        img **= 0.4
        img = filter.canny(img, sigma=3.0)
        img = morphology.dilation(img, morphology.disk(4))
        img = ndimage.binary_fill_holes(img)
        img = morphology.remove_small_objects(img, 1000)
        contours = measure.find_contours(img, 0.8)
        ax.imshow(img2, aspect='auto')
        for n, contour in enumerate(contours):
            ax.plot(contour[:, 1], contour[:, 0], linewidth=1.5)
            center = (sum(contour[:, 1])/len(contour[:, 1]), sum(contour[:, 0])/len(contour[:, 0]))
            ax.scatter(center[0], center[1], color='white')
        i += 1

    plt.savefig('zad2.pdf')
Пример #11
0
def findPlantsCanny(stackVar, stackSum, showImages=True):
    edges = canny(stackVar)
    fill_stack = ndimage.binary_fill_holes(edges)
    label_objects, nb_labels = ndimage.label(fill_stack)
    sizes = np.bincount(label_objects.ravel())
    mask_sizes = sizes > 25
    
    for label in range(len(mask_sizes)):
        '''
        Get rid of lines in addition to the straight size threshold.
        '''
        pts = np.where(label_objects == label)
        xRange = (max(pts[0]) - min(pts[0]))
        yRange = (max(pts[1]) - min(pts[1]))
        areaCovered = float(len(pts[0])) / (xRange*yRange)
        if (areaCovered < .33) or (xRange < 3) or (yRange < 3):
            mask_sizes[label] = False

    mask_sizes[0] = 0
    plants_cleaned = mask_sizes[label_objects]
    labeled_plants, numPlants = ndimage.label(plants_cleaned)
    center = findCenters(labeled_plants, stackSum)
    
    if showImages:
        fig, axs = plt.subplots(1,3, figsize=(14,4), sharey=True)
        axs[0].imshow(stackVar)
        axs[1].imshow(stackVar, cmap=plt.cm.jet, interpolation='nearest') #@UndefinedVariable
        axs[1].contour(plants_cleaned, [0.5], linewidths=1.2, colors='y')
        axs[2].imshow(labeled_plants, cmap=plt.cm.spectral, interpolation='nearest') #@UndefinedVariable
        axs[2].scatter(np.array(center.tolist())[:,1], np.array(center.tolist())[:,0], 
                       color='grey')
        for ax in axs: ax.axis('off')
        fig.subplots_adjust(wspace=.01)
       
    return labeled_plants, center
Пример #12
0
    def getVoidBorder(self):
        """Create boolean array where border points are True and all others
        False.
     
        Input:
            - none
 
        Example:
            >>> import pycoresis as pcs
            >>> fid = r'C:\YOUR\FILE\HERE.txt'
            >>> crs = pcs.corescan(fid)
            >>> crs.getVoidBorder()
            Number of border points : 2449
            Number of border points : 3245
            array([[ True,  True,  True, ...,  True,  True,  True],
                   [ True, False, False, ..., False, False,  True],
                   [ True, False, False, ..., False, False,  True],
                   ..., 
                   [ True, False, False, ..., False, False,  True],
                   [ True, False, False, ..., False, False,  True],
                   [ True,  True,  True, ...,  True,  True,  True]], dtype=bool)
        """
 
        self.voidedges = filter.canny(self.data)
        point_num = np.where(self.voidedges==True)
        self.pointnum = np.size(point_num[0])
        print "Number of border points :", self.pointnum
        return self.voidedges
Пример #13
0
def get_edge(name, sig = 8):
	im = ndimage.imread(name, True)
	edge = filter.canny(im, sigma = sig)
	modded = (255.0 / edge.max() * (edge - edge.min())).astype(np.uint8)
	edged = Image.fromarray(modded)
	edged.save("photos/edge.png")
	return edged
Пример #14
0
	def encode(self):

		data_array = np.array(self.image)#data).reshape((28,28))

		edges = filt.canny(data_array, sigma=3)

		def linear_mapping(data): # using principal components analysis
			pca = decomposition.PCA(n_components=784)
			pca.fit(data)
			mapping = pca.transform(data)

			return mapping

		# encoded = linear_mapping(edges)

		encoded = np.array(edges).reshape(784)

		# encoded = []

		# for d in self.data:
		# 	if (d > 45):
		# 		encoded.append(1)
		# 	else:
		# 		encoded.append(0)

		return encoded
Пример #15
0
 def _get_canny_image(self):
     ci = canny(
         self.original_image, sigma=self.canny_sigma,
         low_threshold=self.canny_low_threshold,
         high_threshold=self.canny_high_threshold,
     )
     return ci
def detect_edges(image_array):
    """ Detect edges in a given image
    Takes a numpy.array representing an image,
    apply filters and edge detection and return a numpy.array

    Parameters
    ----------
    image_array : ndarray (2D)
        Image data to be processed. Detect edges on this 2D array representing the image

    Returns
    -------
    edges : ndarray (2D)
        Edges of an image.
    """
    #Transform image into grayscale
    img = rgb2gray(image_array)
    #Remove some noise from the image
    img = denoise_tv_chambolle(img, weight=0.55)
    #Apply canny
    edges = filter.canny(img, sigma=3.2)
    #Clear the borders
    clear_border(edges, 15)
    #Dilate edges to make them more visible and connected
    edges = binary_dilation(edges, selem=diamond(3))
    return edges
Пример #17
0
def label_particles_edge(im, sigma=2, closing_size=0, **extra_args):
    """ Segment image using Canny edge-finding filter.

        parameters
        ----------
        im : image in which to find particles
        sigma : size of the Canny filter
        closing_size : size of the closing filter

        returns
        -------
        labels : an image array of uniquely labeled segments
    """
    from skimage.morphology import square, binary_closing, skeletonize
    if skimage_version < StrictVersion('0.11'):
        from skimage.filter import canny
    else:
        from skimage.filters import canny
    edges = canny(im, sigma=sigma)
    if closing_size > 0:
        edges = binary_closing(edges, square(closing_size))
    edges = skeletonize(edges)
    labels = sklabel(edges)
    print "found {} segments".format(labels.max())
    # in ma.array mask, False is True, and vice versa
    labels = np.ma.array(labels, mask=edges == 0)
    return labels
Пример #18
0
    def update_image(self, event=None):

        self.imgview.image = canny(self.original_image,
                                   sigma=self.sigma,
                                   low_threshold=self.low,
                                   high_threshold=self.high)
        self.imgview.redraw()
Пример #19
0
def find_iris(image, pupil, **kwargs):
    buffer = 20
    # run canny
    image = filter.canny(image, sigma=1, low_threshold=10, high_threshold=50)
    cx, cy, radius = pupil

    segments = get_segments(400, step=0.01)
    # get ray directions
    directions = zip(map(cos, segments[0]), map(sin, segments[0]))
    shape = image.shape
    points = []
    for d in directions:
        start = (cx + (radius + buffer) * d[0], cy + (radius + buffer)*d[1])
        ray = Ray(image, start, d)
        point = ray.fire()
        if point != None:
            points.append(point)

    for p in points:
        x, y = circle_perimeter(int(p[0]), int(p[1]), 3)
        x = x[x < rgb.shape[0]]
        y = y[y < rgb.shape[1]]
        rgb[x,y] = (220, 40, 40)

    e = Ellipse().fit_with_center(None, points)
    return image, points, e
Пример #20
0
def get_gravatar_array(email, sz=100, edge=(5, 20, 2, 2), mask=((0, 10), (80, 90)), shrink=0.0):
    g = hashlib.md5(email.lower()).hexdigest() + ".jpg"
    fname = "/tmp/" + g
    url = "http://www.gravatar.com/avatar/" + g
    os.system("curl -s -o %s %s" % (fname, url))
    g = scipy.misc.imread(fname, flatten=True)[5:75, 5:75]
    g = 255 - scipy.misc.imresize(g, (sz, sz))
    if edge:
        (sigma, hi, low, sigma2) = edge
        g = 255 * canny(g, sigma, hi, low)
        g = (ndimage.gaussian_filter(g, sigma=sigma2) > 25) * 255
    if mask:
        ((r1, c1), (r2, c2)) = mask
        g[r2:, :] = 0
        g[:r1, :] = 0
        g[:, :c1] = 0
        g[:, c2:] = 0
    if shrink > 0.0:
        (nx, ny) = g.shape
        px = int(nx * shrink / 2)
        py = int(ny * shrink / 2)
        g = concatenate((zeros((py, nx), dtype=g.dtype), g, zeros((py, nx), dtype=g.dtype)), axis=0)
        g = concatenate((zeros((ny + 2 * py, px), dtype=g.dtype), g, zeros((ny + 2 * py, px), dtype=g.dtype)), axis=1)
        g = scipy.misc.imresize(g, (sz, sz))
    g = g.flatten()
    return g
Пример #21
0
def path2tab(path, nbI, threshold):
    tab = []
    maxAddr = 0
    # Ouverture dossier
    dirs = os.listdir(path)
    # Pour chaque fichier
    for file in dirs:
        # Si le fichier est une image .jpg
        if file[-4:] == '.jpg':
            # Chargement image sous-forme tableau
            image = io.imread(path + file, as_grey=True)
            edges = canny(image)
            address = 0
            # Pour chaque ligne de l'image
            for ligne in edges:
                # Pour chaque pixel de la ligne
                for pix in ligne:
                    # Si le pixel est blanc (c'est un contour)
                    if pix == True:
                        # Ajout du pixel au tableau pour déclencher un influx
                        # Par le neurone correspondant
                        tab.append((address, nbI))
                        if address > maxAddr:
                            maxAddr = address
                    # Incrémentation adresse
                    address += 1
            # Incrémentation nombre d'images traitées
            nbI += 1
    print maxAddr
    return tab, nbI
Пример #22
0
 def image_filter(self, image, **kwargs):
     canny_keys = ('sigma', 'low_threshold', 'high_threshold')
     canny_kwargs = dict([(k, kwargs.pop(k)) for k in canny_keys])
     hough_kwargs = kwargs
     edges = canny(image, **canny_kwargs)
     lines = probabilistic_hough(edges, **hough_kwargs)
     self._lines = lines
     return edges
Пример #23
0
def mapEdge(req):
    """Convert img to bytearray and do edge detection
    on centered building"""
    
    img = io.imread(req.geturl(),flatten=True)
    labels, numobjects = ndimage.label(img)
    edges = filter.canny(img, sigma=3)
    return(edges)
Пример #24
0
def getArea(address):
    """Geocode address and retreive image centered
    around lat/long"""
    address = address
    results = Geocoder.geocode(address)
    lat, lng = results[0].coordinates
    zip_code = results[0].postal_code

    map_url = 'https://maps.googleapis.com/maps/api/staticmap?center={0},{1}&size=640x640&zoom=19&sensor=false&maptype=roadmap&&style=visibility:simplified|gamma:0.1'
    request_url = map_url.format(lat, lng)
    req = urllib.urlopen(request_url)
    img = io.imread(req.geturl(),flatten=True)
    labels, numobjects = ndimage.label(img)
    image = filter.canny(img, sigma=3)
    thresh = threshold_otsu(image)
    bw = closing(image > thresh, square(3))

    # remove artifacts connected to image border
    cleared = bw.copy()
    clear_border(cleared)

    # label image regions
    label_image = label(cleared)
    borders = np.logical_xor(bw, cleared)
    label_image[borders] = -1
    image_label_overlay = label2rgb(label_image, image=image)

    fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
    ax.imshow(image_label_overlay)
    dist = []
    rp = regionprops(label_image)
    rp = [x for x in rp if 100 < x.area <= 900]

    for region in rp:

        # skip small images
        #if region.area < 100:
        #    continue
        dist.append(sqrt( ( 320-region.centroid[0] )**2 + ( 320-region.centroid[1] )**2 ))
        # draw rectangle around segmented coins
        #minr, minc, maxr, maxc = region.bbox
        #rect = mpatches.Rectangle((minc, minr), maxc - minc, maxr - minr,
        #                      fill=False, edgecolor='red', linewidth=2)
        #ax.add_patch(rect)

    roof_index = dist.index(min(dist))
    minr, minc, maxr, maxc = rp[roof_index].bbox
    rect = mpatches.Rectangle((minc, minr), maxc - minc, maxr - minr,
                          fill=False, edgecolor='red', linewidth=2)
    ax.add_patch(rect)

    img = StringIO()
    fig.savefig(img)
    img.seek(0)
    session['roof_area'] = rp[roof_index].area
    roof_area = (rp[roof_index].area)*12
    return(roof_area)
Пример #25
0
def find_lines(sourcefile=SOURCEFILE, plot=PLOT, shrink=2, threshold=128,
               scale_first=True,
               **transformparams):
  """
  This function borrows from
  http://scikits-image.org/docs/0.3/auto_examples/plot_hough_transform.html
  """
  # Line finding, using the Probabilistic Hough Transform
  params = {}
  params.update(TRANSFORMPARAMS)
  params.update(transformparams)
  print params
  image_orig = imread(sourcefile)

  # scale up
  if scale_first:
    image_orig = scale_up(image_orig)
  # thin lines
  if shrink > 0:
    # note that this returns a one-bit image
    shrunk_image = shrink_lines(image_orig,threshold=threshold,
                                iterations=shrink)
  else:
    # in this case shrunk_image may still be grayscale
    shrunk_image = image_orig
  # switch the y axis
  image = shrunk_image[::-1,:]
  #edge detection
  edges = canny(image, 2, 1, 25)
  #actual transform
  lines = probabilistic_hough(edges, **params)

  if PLOT:
    plt.figure(figsize=(12, 4))

    plt.subplot(131)
    plt.imshow(image, cmap=plt.cm.gray)
    plt.title('Input image')

    plt.subplot(132)
    plt.imshow(edges, cmap=plt.cm.gray)
    plt.title('Sobel edges')

    plt.subplot(133)
    plt.imshow(edges * 0)

    for line in lines:
        p0, p1 = line
        plt.plot((p0[0], p1[0]), (p0[1], p1[1]))

    plt.title('Lines found with PHT')
    plt.axis('image')
    plt.show()
  if scale_first:
    lines = np.array(lines)/2
  return lines
Пример #26
0
def process_image(request, image):
    """Creates an edge image and calculates the values needed for the score calculation if necessary. This function is called as soon as an image is requested.

    :param request: The request object containing the user request.
    :type request: :class:`django.http.HttpRequest`.
    :param image: The image to be processed.
    :type image: :class:`models.Image`.

    """
    # detect edges
    if not image.edge_image:
        greyscale_image = io.imread(os.path.join(settings.MEDIA_ROOT, image.image.name), as_grey=True)

        # resize image
        height = len(greyscale_image)
        width = len(greyscale_image[0])
        factor = 768.0 / height
        greyscale_image = transform.resize(greyscale_image, [height * factor, width * factor])

        # detect edges
        edges = filter.canny(greyscale_image, sigma=image.canny_sigma, low_threshold=image.canny_low_threshold, high_threshold=image.canny_high_threshold)

        # save edge image
        temp_filename = '/tmp/' + request.session.session_key + '.png'
        io.imsave(temp_filename, ~edges * 1.)
        image.edge_image.save(slugify(os.path.splitext(os.path.basename(image.image.name))[0]) + '.png', File(open(temp_filename)))
        os.remove(temp_filename)

    if not image.dilated_edge_image:
        edge_image = io.imread(os.path.join(settings.MEDIA_ROOT, image.edge_image.name), as_grey=True)
        edge_image = edge_image.astype(np.float64)

        if edge_image.max() > 1.:
            edge_image /= 255.

        # map values greater .5 as edge
        edge_image = (1. - edge_image) / .5

        # save dilated edge image
        temp_filename = '/tmp/' + request.session.session_key + '.png'
        io.imsave(temp_filename, ~ndimage.binary_dilation(edge_image, iterations=2) * 1.)
        image.dilated_edge_image.save(slugify(os.path.splitext(os.path.basename(image.image.name))[0]) + '.png', File(open(temp_filename)))
        os.remove(temp_filename)

    # save maximum distance (needed for score calculation)
    if not image.max_distance:
        ones = np.ones(image.edge_image.height * image.edge_image.width).reshape((image.edge_image.height, image.edge_image.width))

        dilated_edge_image = io.imread(os.path.join(settings.MEDIA_ROOT, image.dilated_edge_image.name), as_grey=True)
        dilated_edge_image = dilated_edge_image.astype(np.float64)

        if dilated_edge_image.max() > 1.:
            dilated_edge_image /= 255.

        image.max_distance = np.sum(np.absolute(ones - dilated_edge_image))
        image.save()
Пример #27
0
    def profiling(self):
        image = resize(self.image, (257, 257))
        edges = ff.canny(image)
        edges = skeletonize(edges)
        edges = edges.astype(int)
        edges = edges[1:256, 1:256]

        lt = self.feature_extraction_profiling(edges, 2, 5)
        profiling = lt.ravel()
        return np.append(profiling, [float(self.ratio)/10])
def distinct(planes):
	for i, img in enumerate(planes):
		#contours = measure.find_contours(planes[i], 0.8)
		planes[i] = filter.canny(planes[i], sigma=3)
		#planes[i] = filter.sobel(planes[i])
		
		planes[i] = Image(morphology.dilation(planes[i], square(3)))
		#planes[i] = Image(morphology.erosion(planes[i], square(2)))
		message = "Distincted plane: " + str(i)
		print(message)
Пример #29
0
def getEdgeMatrix(img, sigpercent=.01, axis=0):
  '''Use the canny filter to produce a boolean matrix with the same dimensions
     as the image where the value True indicates an edge and False indicates
     no edge. sig is the tuning parameter for the canny filter: a higher sig
     means fewer edges detected (smoother image) '''
  # If the image is not already grayscale, scale it down
  if np.ndim(img) == 3:
    img = img.mean(axis=2)
  edgeMat = filter.canny(img, sigma=sigpercent*np.shape(img)[axis])
  return edgeMat
def edge_change_ratio(frame1, frame2, sigma=3, low_threshold=20,
                      high_threshold=80, distance=24, edge_width=10,
                      float_accuracy=3):
    """
    Calculate Edge Change Ratio for the given 2 frames (n-1, n)
    :param frame1: Frame N-1
    :param frame2: Frame N
    :param sigma: Edge detection level
    :param low_threshold: Dark threshold
    :param high_threshold: Bright threshold
    :param distance: Dialtion Distance
    :param edge_width: Distance of Edges Measured
    :param float_accuracy: Floating point precision
    :return: Float
    """
    frame1_grey = desaturate(frame1)
    frame2_grey = desaturate(frame2)

    frame1_edge = canny(frame1_grey, sigma, low_threshold, high_threshold)
    frame2_edge = canny(frame2_grey, sigma, low_threshold, high_threshold)

    frame1_inv_edge = invert(frame1_edge).astype('uint8') * 255
    frame2_inv_edge = invert(frame2_edge).astype('uint8') * 255

    frame1_contours = measure.find_contours(frame1_inv_edge, edge_width)
    frame2_contours = measure.find_contours(frame2_inv_edge, edge_width)

    frame1_dialate = dilation(frame1_edge, square(distance))
    frame2_dialate = dilation(frame2_edge, square(distance))

    frame1_comp = frame1_inv_edge + frame2_dialate
    frame2_comp = frame2_inv_edge + frame1_dialate

    frame1_comp_contours = measure.find_contours(frame1_comp, edge_width)
    frame2_comp_contours = measure.find_contours(frame2_comp, edge_width)

    try:
        return round(
            max(float(len(frame1_comp_contours)) / float(len(frame1_contours)),
                float(len(frame2_comp_contours)) / float(len(frame2_contours))),
            float_accuracy) * 100
    except ZeroDivisionError:
        return 0