I want to apply watershed algorithm to an image with predefined markers using Opencv package. I have a original image for example "coffee_grains.jpg" and a marker image "coffee_markers.png". I simply applied watershed algorithm on image and its marker, similar to OpenCV documentation but I got simply a result similar to labels. Here is my code:
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure
work_dir = './'
coffi = cv.imread(work_dir+'TestImages/coffee_grains.jpg')
plt.subplot(1,3,1)
plt.imshow(coffi)
labels = cv.imread(work_dir+'TestImages/coffee_markers.png')
labels = cv.cvtColor(labels ,cv.COLOR_BGR2GRAY)
plt.subplot(1,3,2)
plt.imshow(labels)
labels = labels.astype(np.int32)
labels = cv.watershed(coffi,labels)
plt.subplot(1,3,3)
plt.imshow(labels)
plt.show()
Am I doing something wrong?!
