KvasDub
KvasDub

Reputation: 281

How to import and use scipy.spatial.distance functions correctly?

   from scipy.spatial.distance import seuclidean #imports abridged
   import scipy


   img = np.asarray(Image.open("testtwo.tif").convert('L'))

   img = 1 * (img < 127)

   area = (img == 0).sum() # computing white pixel area

   print area

   areasplit = np.split(img, 24) # splitting image array

   print areasplit


  for i in areasplit:
  result = (i == 0).sum()
  print result             #computing white pixel area for every single array

  minimal = result.min()      
  maximal = result.max()

  dist = seuclidian(minimal, maximal)

  print dist

I want to compute distances between array elements, produced from splitting an image. Python can`t recognize the name of a distance functions (I have tried several of them and variuos approaches to importing modules). How to import and call these functions correctly? Thank you

Upvotes: 0

Views: 10475

Answers (2)

julia
julia

Reputation: 11

You have to use the specific syntax from scipy import spatial in order to use those functions. Then use spatial.distance.your_distance_function in order to call the function.

Upvotes: 1

doctorlove
doctorlove

Reputation: 19232

You haven't stated what the error is, but you are using numpy as well and I can't see an import for that Try

import numpy as np
import scipy

Then try

dist = scipy.spatial.distance.euclidian(minimal, maximal)
dists = scipy.spatial.distance.seuclidian(minimal, maximal, variances)

Note - the standardised euclidean distance takes a third parameter.

Upvotes: 1

Related Questions