I've written a script based on this description.
There are few images as 2D numpy arrays, if images are big, it takes a long time to calculate each values. Is there better way do do this than my solution?
Consider three images, means vector and inverted covariance matrix:
a = image1
b = image2
c = image3 # numpy arrays, NxM size
m = np.array([m1, m2, m3]) # means vector
covariance = np.cov([a.ravel(), b.ravel(), c.ravel()])
inv_cov = np.linalg.inv(covariance) # inv. covariance matrix
I solved this problem with a double loop:
result = np.zeros((y,x)) # y,x are sizes of images
for i in xrange(y):
for j in xrange(x):
v = np.array([a[i,j], b[i,j], c[i,j]]) # array with particular pixels from each image
result[i,j] = mahalanobis(v,m,inv_cov) # calculate mahalanobis distance and insert value as a pixel
I think that there could be a better way to do this faster. Maybe without loops?