Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1.     # Sets up vars needed
  2.     meanSum, meanTotal, count = 0.0, 0.0, 0
  3.     hc, hd, m, sdc, sdd = 4, 4, 20, 3, 3
  4.     hci, hdi = 1.0/hc**2, 1.0/hd**2
  5.    
  6.     # Sets current pixel and compares against rest
  7.     x = img[i,j,0]
  8.     for k in range(img.shape[0]):
  9.         for l in range(img.shape[1]):
  10.             # Gets next pixel intensity
  11.             xi = img[k,l,0]
  12.            
  13.             # Calculates spatial and intensity distances
  14.             magHc = abs(x-xi)
  15.             magHd = math.sqrt(math.pow(i-k, 2) + math.pow(j-l, 2))
  16.  
  17.             # If within distances
  18.             if magHc <= sdc*hc and magHd <= sdd*hd:
  19.                 count += 1
  20.  
  21.                 # Calculates
  22.                 xxia, xxib, xxic = (x-xi)**2, (i-k)**2, (j-l)**2
  23.                 xxi = xxia*hci + xxib*hdi + xxic*hdi
  24.                 exp = math.exp(-0.5 * xxi)
  25.                 # magxi = math.sqrt(math.pow(xi, 2) + math.pow(k, 2) + math.pow(l, 2))
  26.  
  27.                 # Adds to sums
  28.                 meanSum += xi * exp
  29.                 meanTotal += exp
  30.    
  31.     # Clustering
  32.     if m < count:
  33.         newImg[i,j,0] = meanSum / meanTotal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement