bahadur ali
bahadur ali

Reputation: 1

i want to calculate euclidean distance to generate the seedmaps for watershed of neural cells but got ValueError: XA must be a 2-dimensional array

while finding the euclidean distance to generate the seeds for watershed, I got an error XA must be a two dimensional array. I applied many things suggested on stack overflow but couldn't solved this error. Please help me where I'm making a mistake. thanks in advance

import numpy as np
import os

gvf = GVF(images, th)
dismap = gvf.distancemap()
newimg = gvf.new_image(0.4, dismap) # choose alpha as 0.4.
out = []
pair = []
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
for i,img in enumerate(dismap):
    neighborhood_size = 20
    data_max = ndimage.filters.maximum_filter(img, neighborhood_size)
    data_max[data_max==0] = 255
    pair.append((img == data_max).astype(np.uint8))
    y, x = np.where(pair[i]>0)
    points = zip(y[:], x[:])
    dmap = distance.cdist(points, points, 'euclidean')
    y, x = np.where(dmap<20)
    ps = zip(y[:], x[:])
    for p in ps:
        if p[0] != p[1]:
            pair[i][points[min(p[0], p[1])]] = 0
    dilation = cv2.dilate((pair[i]*255).astype(np.uint8),kernel,iterations = 1) 
    out.append(dilation)
    os.chdir(".")
    write_mask8(dilation, "seed_point", i)
out = cvt_npimg(out)
vis_square(out)

Upvotes: 0

Views: 83

Answers (0)

Related Questions