def constructMarkers4(request): markers = constructMarkers3(request) if markers is not None: markers = imtransform.setMarkersValues(markers, black=cv2.GC_FGD, gray=cv2.GC_BGD, white=cv2.GC_PR_BGD) current_mask = getMask(request) if current_mask is not None: # set to probable foreground where the mask is white markers[(current_mask >= 250) & (markers == cv2.GC_PR_BGD)] = cv2.GC_PR_FGD if cv2.GC_FGD not in markers and cv2.GC_PR_FGD not in markers: markers[markers == cv2.GC_PR_BGD] = cv2.GC_PR_FGD return markers
def watershed2(img, markers): markers = np.int8(imtransform.setMarkersValues(markers, black=1, gray=-1, white=0)) # markers2 = np.zeros(markers.shape, np.uint8) # markers2[markers == 1] = 0 # markers2[markers ==-1] = 127 # markers2[markers == 0] = 255 # imsave(settings.UPLOAD_FOLDER + '/markers222222.png', markers2) greyImg = imtransform.rgb_2_greyscale(img) mask = watershed_ift(greyImg, markers) mask[mask < 0] = 0 mask = 255 * mask return np.array(mask, dtype=np.uint8)
def watershed2(img, markers): markers = np.int8( imtransform.setMarkersValues(markers, black=1, gray=-1, white=0)) # markers2 = np.zeros(markers.shape, np.uint8) # markers2[markers == 1] = 0 # markers2[markers ==-1] = 127 # markers2[markers == 0] = 255 # imsave(settings.UPLOAD_FOLDER + '/markers222222.png', markers2) greyImg = imtransform.rgb_2_greyscale(img) mask = watershed_ift(greyImg, markers) mask[mask < 0] = 0 mask = 255 * mask return np.array(mask, dtype=np.uint8)
def constructMarkers4(request): markers = constructMarkers3(request) if markers is not None: markers = imtransform.setMarkersValues(markers, black=cv2.GC_FGD, gray=cv2.GC_BGD, white=cv2.GC_PR_BGD) current_mask = getMask(request) if current_mask is not None: # set to probable foreground where the mask is white markers[(current_mask >= 250) & (markers == cv2.GC_PR_BGD)] = cv2.GC_PR_FGD if cv2.GC_FGD not in markers and cv2.GC_PR_FGD not in markers: markers[markers == cv2.GC_PR_BGD] = cv2.GC_PR_FGD return markers