python - Finding patters in multi dimensional arrays -
i've got 4 dimensional array in need find patters. patter evaluated in last 2 dimensions, scanning across first two. using hit or miss function on image, instead of evaluating across 2 dimensions of image patters on values of these points, need scan across 2 dimensions looking pattern in 2 other dimensions of point , surroundings. current code looks this, considering patterns other 2 ones described bellow, run in real time, need make in run faster.
image = np.empty((240,320,2,3), np.bool) # image receive data y in range(1, 239): x in range(1, 319): if image[y][x-1][1][1] , image[y][x][1][2]: findpattern1[y][x] = true if image[y-1][x][0][1] , image[y][x][0][2]: findpattern2[y][x] = true
i thought using hit or miss transform multidimensional structure scan across image[y][x]
, unable working perfectly. guys have idea solving problem?
seems need fancy indexing , logical_and
.
find_pattern_1 = np.logical_and(image[1:, :-1, 1, 1], image[1:, 1:, 1, 2]) find_pattern_2 = np.logical_and(image[:-1, 1:, 0, 1], image[1:, 1:, 0, 2])
Comments
Post a Comment