How to use the gradient.gradient function in gradient

To help you get started, we’ve selected a few gradient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sebasvega95 / Canny-edge-detector / double_thresholding.py View on Github external
if px >= hi:
                thres[i][j] = strong
                strongs.append((i, j))
            elif px >= lo:
                thres[i][j] = weak
    return thres, strongs

if __name__ == '__main__':
    from sys import argv
    if len(argv) < 2:
        print "Usage: python %s <img>" % argv[0]
        exit()
    im = array(Image.open(argv[1]))
    im = im[:, :, 0]
    gim = gaussian(im)
    grim, gphase = gradient(gim)
    gmax = maximum(grim, gphase)
    thres = thresholding(gmax)
    gray()

    subplot(1, 2, 1)
    imshow(im)
    axis('off')
    title('Original')

    subplot(1, 2, 2)
    imshow(thres[0])
    axis('off')
    title('Double thresholding')

    show()
github sebasvega95 / Canny-edge-detector / nonmax_suppression.py View on Github external
gmax[i][j] = det[i][j]
        # 135 degrees
        if (phase[i][j] &gt;= 112.5 and phase[i][j] &lt; 157.5) or (phase[i][j] &gt;= 292.5 and phase[i][j] &lt; 337.5):
          if det[i][j] &gt;= det[i - 1][j - 1] and det[i][j] &gt;= det[i + 1][j + 1]:
            gmax[i][j] = det[i][j]
  return gmax

if __name__ == '__main__':
  from sys import argv
  if len(argv) &lt; 2:
      print "Usage: python %s <img>" % argv[0]
      exit()
  im = array(Image.open(argv[1]))
  im = im[:, :, 0]
  gim = gaussian(im)
  grim, gphase = gradient(gim)
  gmax = maximum(grim, gphase)

  gray()

  subplot(2, 2, 1)
  imshow(im)
  axis('off')
  title('Original')

  subplot(2, 2, 2)
  imshow(gim)
  axis('off')
  title('Gaussian')

  subplot(2, 2, 3)
  imshow(grim)
github Dynetics / Malfunction / malfunction / malfunction.py View on Github external
def output(cursor, by_binary_list, whitelist_avg, blacklist_avg):
    """ Print out a report for the output of malfunction

    cursor - database cursor
    by_binary_list - list of strong matching binaries
    whitelist_avg - the whitelist score
    blacklist_avg - the blacklist score"""

    score = whitelist_avg - blacklist_avg

    print("Whitelist Average: " + str(whitelist_avg))
    print("Blacklist Average: " + str(blacklist_avg))
    print("            Score: " + str(score))
    gradient.gradient(score)

    possible_filenames = []
    possible_authors = []
    comments = []
    for binary_id in by_binary_list:
        cursor.execute("SELECT author,filenames,comment FROM "
                       "binaries WHERE binaryID=?", (binary_id, ))
        binary_entry = cursor.fetchone()
        if binary_entry[0] not in possible_authors and binary_entry[0]:
            possible_authors.append(binary_entry[0])
        if binary_entry[1] not in possible_filenames and binary_entry[1]:
            possible_filenames.append(binary_entry[1])
        if binary_entry[2] not in comments and binary_entry[2]:
            comments.append(binary_entry[2])
    if possible_authors:
        print("***Possible Authors of this binary***")