def display_artifact(self, prediction, artifact, color, title): im = self._image im_art = im.copy() im_art [prediction == artifact] = color show_images([im, im_art], ["original", title], scale = 0.8)
def display_artifact(self, prediction, artifact, color, title): im = self._image im_art = im.copy() im_art[prediction == artifact] = color show_images([im, im_art], ["original", title], scale=0.8)
def display_contours(image, contours, color=(255, 0, 0), thickness=-1, title=None): imShow = image.copy() for i in range(0, len(contours)): cv2.drawContours(imShow, contours, i, color, thickness) show_images([imShow], scale=0.7, titles=title)
def display_average_pixels(self): if len(self.avg_pixels) == 0: self._get_initial_classes() def stretch_image(i): pixel = self._avg_pixels[i] stretch = np.zeros((10, 10, 3), dtype='uint8') stretch[:, :] = pixel return stretch images = [stretch_image(i) for i in range(0, self._n_objects)] show_images(images, scale = 2.5)
def orb_show(img): orb = cv2.ORB_create() # find the keypoints with ORB kp = orb.detect(img,None) # compute the descriptors with ORB kp, des = orb.compute(img, kp) img2 = np.zeros_like(img) # draw only keypoints location,not size and orientation img3 = cv2.drawKeypoints(img, kp, img2, color=(0,255,0), flags=0) show_images([img3])
def display_average_pixels(self): if len(self.avg_pixels) == 0: self._get_initial_classes() def stretch_image(i): pixel = self._avg_pixels[i] stretch = np.zeros((10, 10, 3), dtype='uint8') stretch[:, :] = pixel return stretch images = [stretch_image(i) for i in range(0, self._n_objects)] show_images(images, scale=2.5)
# remove the whale root = "/kaggle/whales/imgs" img_file = "w_686.jpg" img_ = path.join(root, img_file) img = cv2.imread(img_) img_shift = img ### preprocess #pyramid down img_shift = cv2.pyrDown(img) img_shift = cv2.pyrDown(img_shift) # convert to np.float32 Z = img_shift.reshape((-1,3)) Z = np.float32(Z) # define criteria, number of clusters(K) and apply kmeans() criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0) K = 3 ret,label,center=cv2.kmeans(Z,K,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS) # Now convert back into uint8, and make original image center = np.uint8(center) res = center[label.flatten()] res2 = res.reshape((img_shift.shape)) res2 = cv2.pyrUp(cv2.pyrUp(res2)) show_images([img, res2])
def display_contours(image, contours, color = (255, 0, 0), thickness = -1, title = None): imShow = image.copy() for i in range(0, len(contours)): cv2.drawContours(imShow, contours, i, color, thickness) show_images([imShow], scale=0.7, titles=title)
def show_detected_mask(self): mask = self.mask_off_od() mask = cv2.resize(mask, (540, 540)) im = self._img.copy() im[mask == 0] = 0 show_images([self._img, im])
def show_detected(self, ctr): pr = self._processed.copy().astype('uint8') cv2.circle(pr, ctr, 50, 0, 3) cv2.circle(self.image, ctr, 50, (0, 0, 0), 3) show_images([self.image, pr])