0

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)
D.L
  • 4,339
  • 5
  • 22
  • 45
  • Which line is giving the error? – Matt Pitkin Jan 30 '23 at 11:24
  • i have added `numpy` and `os` to the given code, but there are still a number of imports missing and also undefined variables. the question needs sufficient code for a minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example – D.L Jan 30 '23 at 11:51
  • dmap = distance.cdist(points, points, 'euclidean') @MattPitkin – bahadur ali Jan 30 '23 at 13:00
  • What is `distance`? It is not defined anywhere? – Matt Pitkin Jan 30 '23 at 13:58
  • I assume it's from the scipy.spatial module here https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html – Matt Pitkin Jan 30 '23 at 13:59
  • Try swapping `points = zip(y[:], x[:])` to instead be `points = np.vstack((y, x)).T` – Matt Pitkin Jan 30 '23 at 14:10
  • thank you @MattPitkin, but now i am stuck with another error. I don't know it is because of using vstack and transpose or something else. it says IndexError: index 915 is out of bounds for axis 0 with size 700 at line pair[i][points[min(p[0], p[1])]] = 0 – bahadur ali Jan 30 '23 at 15:14

0 Answers0