Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

the "posterized" image output is only a visualization for humans, for a program rather use the index version.

each "blob" is numbered, and has its own index, you can access the corresponding pixels from python like:

mask = img[img==17] # True/False mask for blob 17, same size as original image

if you really need contours:

mask = np.astype(np.uint8) # bool -> binary image
cnt,hier = cv2.findContours(mask, .....)

the "posterized" image output is only a visualization for humans, for a program rather use the index version.

each "blob" is numbered, and has its own index, you can access the corresponding pixels from python like:

mask = img[img==17] cv2.compare(res, 17, cv2.CMP_EQ)  # True/False 0/1 mask for blob 17, same size as original input image

if you really need contours:

mask = np.astype(np.uint8) # bool -> binary image
cnt,hier = cv2.findContours(mask, .....)

the "posterized" image output is only a visualization for humans, for a program rather use the index version.

im = cv2.imread("some.png")
h  = cv2.hfs.HfsSegment_create(im.shape[0],im.shape[1])
res = h.performSegmentCpu(im, False) # False -> indexed

each "blob" is numbered, and has its own index, you can access the corresponding pixels from python like:

mask = cv2.compare(res, 17, cv2.CMP_EQ)  # 0/1 mask for blob 17, same size as input image

if you really need contours:

cnt,hier = cv2.findContours(mask, .....)

the "posterized" image output is only a visualization for humans, for a program rather use the index version.

im = cv2.imread("some.png")
h  = cv2.hfs.HfsSegment_create(im.shape[0],im.shape[1])
res = h.performSegmentCpu(im, False) # False -> indexed

each "blob" is numbered, and has its own index, you can access the corresponding pixels make a binary mask from it in python like:

mask = cv2.compare(res, 17, cv2.CMP_EQ)  # 0/1 mask for blob 17, same size as input image

if you really need contours:

cnt,hier = cv2.findContours(mask, .....)

the "posterized" image output is only a visualization for humans, for a program rather use the index version.

im = cv2.imread("some.png")
h  = cv2.hfs.HfsSegment_create(im.shape[0],im.shape[1])
res = h.performSegmentCpu(im, False) # False -> indexed
indexed (16U)

each "blob" is numbered, and has its own index, you can make a binary mask from it in python like:

mask = cv2.compare(res, 17, cv2.CMP_EQ)  # 0/1 mask for blob 17, same size as input image

if you really need contours:

cnt,hier = cv2.findContours(mask, .....)