使内部矩形适合关节
Fit internal rectangles to joints
使用关节数组,如下所示:
如何调整内部矩形,使矩形不重叠并使用所有点?基本上将 table 个细胞拟合到点上。
我试过抓住轮廓,效果很好:
找到 22 个点。我如何将这些点拟合到内部多边形?例如。找到这张图片中的 21 个矩形。
我找到了the joint array through this method,我猜这是续篇
我想出了一个快速而肮脏的解决方案。这只适用于完全 horizontal/vertical 对齐,如果列中有间隙,则不会处理。
# First dilate the image
kernel = np.ones((5,5),np.uint8)
dilation = cv.dilate(img,kernel,iterations = 1)
# Find contours then points
(img, contours, hierarchy) = cv.findContours(dilation, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
points = []
for con in contours:
if (cv.contourArea(con)>0):
M = cv.moments(con)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
points.append([cY, cX])
# attempt at finding rectangles
map = {}
for p in points:
map[p[1]] = []
for p in points:
map[p[1]].append(p[0])
# Check for rectangles
keys = sorted(map.keys(), key=int)
for i in range(len(keys)-1):
one = np.array(map[keys[i]])
two = np.array(map[keys[i+1]])
intersect = np.in1d(one,two)
intersect2 = np.in1d(two,one)
# If two horizontal collections have an intersection it's likely a cell
if (sum(intersect) >= 2):
intersects = sorted(one[intersect], key=int)
for x in range(len(intersects)-1):
rect = [keys[i], intersects[x],keys[i+1], intersects[x+1]]
showimg(rois[numimg][rect[1]:rect[3],rect[0]:rect[2]])
使用关节数组,如下所示:
如何调整内部矩形,使矩形不重叠并使用所有点?基本上将 table 个细胞拟合到点上。
我试过抓住轮廓,效果很好:
找到 22 个点。我如何将这些点拟合到内部多边形?例如。找到这张图片中的 21 个矩形。
我找到了the joint array through this method,我猜这是续篇
我想出了一个快速而肮脏的解决方案。这只适用于完全 horizontal/vertical 对齐,如果列中有间隙,则不会处理。
# First dilate the image
kernel = np.ones((5,5),np.uint8)
dilation = cv.dilate(img,kernel,iterations = 1)
# Find contours then points
(img, contours, hierarchy) = cv.findContours(dilation, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
points = []
for con in contours:
if (cv.contourArea(con)>0):
M = cv.moments(con)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
points.append([cY, cX])
# attempt at finding rectangles
map = {}
for p in points:
map[p[1]] = []
for p in points:
map[p[1]].append(p[0])
# Check for rectangles
keys = sorted(map.keys(), key=int)
for i in range(len(keys)-1):
one = np.array(map[keys[i]])
two = np.array(map[keys[i+1]])
intersect = np.in1d(one,two)
intersect2 = np.in1d(two,one)
# If two horizontal collections have an intersection it's likely a cell
if (sum(intersect) >= 2):
intersects = sorted(one[intersect], key=int)
for x in range(len(intersects)-1):
rect = [keys[i], intersects[x],keys[i+1], intersects[x+1]]
showimg(rois[numimg][rect[1]:rect[3],rect[0]:rect[2]])