Python cv2.INPAINT_TELEA Examples
The following are 9
code examples of cv2.INPAINT_TELEA().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: imgproc.py From graph_distillation with Apache License 2.0 | 6 votes |
def inpaint(img, threshold=1): h, w = img.shape[:2] if len(img.shape) == 3: # RGB mask = np.all(img == 0, axis=2).astype(np.uint8) img = cv2.inpaint(img, mask, inpaintRadius=3, flags=cv2.INPAINT_TELEA) else: # depth mask = np.where(img > threshold) xx, yy = np.meshgrid(np.arange(w), np.arange(h)) xym = np.vstack((np.ravel(xx[mask]), np.ravel(yy[mask]))).T img = np.ravel(img[mask]) interp = interpolate.NearestNDInterpolator(xym, img) img = interp(np.ravel(xx), np.ravel(yy)).reshape(xx.shape) return img
Example #2
Source File: measure.py From ambient-gan with MIT License | 6 votes |
def unmeasure_np(self, hparams, x_measured_val, theta_val): if hparams.unmeasure_type == 'medfilt': unmeasure_func = lambda image, mask: signal.medfilt(image) elif hparams.unmeasure_type == 'inpaint-telea': inpaint_type = cv2.INPAINT_TELEA unmeasure_func = measure_utils.get_inpaint_func_opencv(hparams, inpaint_type) elif hparams.unmeasure_type == 'inpaint-ns': inpaint_type = cv2.INPAINT_NS unmeasure_func = measure_utils.get_inpaint_func_opencv(hparams, inpaint_type) elif hparams.unmeasure_type == 'inpaint-tv': unmeasure_func = measure_utils.get_inpaint_func_tv() elif hparams.unmeasure_type == 'blur': unmeasure_func = measure_utils.get_blur_func() else: raise NotImplementedError x_unmeasured_val = np.zeros_like(x_measured_val) for i in range(x_measured_val.shape[0]): x_unmeasured_val[i] = unmeasure_func(x_measured_val[i], theta_val[i]) return x_unmeasured_val
Example #3
Source File: WatermarkRemover.py From nowatermark with MIT License | 6 votes |
def remove_watermark_raw(self, img, watermark_template_gray_img, watermark_template_mask_img): """ 去除图片中的水印 :param img: 待去除水印图片位图 :param watermark_template_gray_img: 水印模板的灰度图片位图,用于确定水印位置 :param watermark_template_mask_img: 水印模板的掩码图片位图,用于修复原始图片 :return: 去除水印后的图片位图 """ # 寻找水印位置 img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) x1, y1, x2, y2 = self.find_watermark_from_gray(img_gray, watermark_template_gray_img) # 制作原图的水印位置遮板 mask = np.zeros(img.shape, np.uint8) # watermark_template_mask_img = cv2.cvtColor(watermark_template_gray_img, cv2.COLOR_GRAY2BGR) # mask[y1:y1 + self.watermark_template_h, x1:x1 + self.watermark_template_w] = watermark_template_mask_img mask[y1:y2, x1:x2] = watermark_template_mask_img mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY) # 用遮板进行图片修复,使用 TELEA 算法 dst = cv2.inpaint(img, mask, 5, cv2.INPAINT_TELEA) # cv2.imwrite('dst.jpg', dst) return dst
Example #4
Source File: ImageRestoration.py From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License | 5 votes |
def main(): image = cv2.imread("../data/Damaged Image.tiff", 1) mask_image = cv2.imread("../data/Mask.tiff", 0) telea_image = cv2.inpaint(image, mask_image, 5, cv2.INPAINT_TELEA) ns_image = cv2.inpaint(image, mask_image, 5, cv2.INPAINT_NS) cv2.imshow("Orignal Image", image) cv2.imshow("Mask Image", mask_image) cv2.imshow("TELEA Restored Image", telea_image) cv2.imshow("NS Restored Image", ns_image) cv2.waitKey(0) cv2.destroyAllWindows()
Example #5
Source File: RealWorld.py From Monocular-Obstacle-Avoidance with BSD 2-Clause "Simplified" License | 5 votes |
def GetDepthImageObservation(self): # ros image to cv2 image try: cv_img = self.bridge.imgmsg_to_cv2(self.depth_image, "32FC1") except Exception as e: raise e # try: # cv_rgb_img = self.bridge.imgmsg_to_cv2(self.rgb_image, "bgr8") # except Exception as e: # raise e cv_img = np.array(cv_img, dtype=np.float32) cv_img[np.isnan(cv_img)] = 0. # cv_img/=(10./255.) cv_img/=(10000./255.) # print 'max:', np.amax(cv_img), 'min:', np.amin(cv_img) # cv_img[cv_img > 5.] = -1. # cv_img[cv_img < 0.4] = 0. # inpainting mask = copy.deepcopy(cv_img) mask[mask == 0.] = 1. mask[mask != 1.] = 0. # print 'mask sum:', np.sum(mask) mask = np.uint8(mask) cv_img = cv2.inpaint(np.uint8(cv_img), mask, 3, cv2.INPAINT_TELEA) cv_img = np.array(cv_img, dtype=np.float32) # cv_img*=(10./255.) cv_img*=(10./255.) # resize dim = (self.depth_image_size[0], self.depth_image_size[1]) cv_img = cv2.resize(cv_img, dim, interpolation = cv2.INTER_AREA) # cv2 image to ros image and publish try: resized_img = self.bridge.cv2_to_imgmsg(cv_img, "passthrough") except Exception as e: raise e self.resized_depth_img.publish(resized_img) return(cv_img/5.)
Example #6
Source File: image.py From perception with Apache License 2.0 | 5 votes |
def inpaint(self, win_size=3, rescale_factor=1.0): """ Fills in the zero pixels in the image. Parameters ---------- win_size : int size of window to use for inpainting rescale_factor : float amount to rescale the image for inpainting, smaller numbers increase speed Returns ------- :obj:`ColorImage` color image with zero pixels filled in """ # get original shape orig_shape = (self.height, self.width) # resize the image resized_data = self.resize(rescale_factor, interp='nearest').data # inpaint smaller image mask = 1 * (np.sum(resized_data, axis=2) == 0) inpainted_data = cv2.inpaint(resized_data, mask.astype(np.uint8), win_size, cv2.INPAINT_TELEA) inpainted_im = ColorImage(inpainted_data, frame=self.frame) # fill in zero pixels with inpainted and resized image filled_data = inpainted_im.resize( orig_shape, interp='bilinear').data new_data = self.data new_data[self.data == 0] = filled_data[self.data == 0] return ColorImage(new_data, frame=self.frame)
Example #7
Source File: utils.py From casme with BSD 3-Clause "New" or "Revised" License | 5 votes |
def inpaint(mask, masked_image): l = [] for i in range(mask.size(0)): permuted_image = permute_image(masked_image[i], mul255=True) m = mask[i].squeeze().byte().numpy() inpainted_numpy = cv2.inpaint(permuted_image, m, 3, cv2.INPAINT_TELEA) #cv2.INPAINT_NS l.append(transforms.ToTensor()(inpainted_numpy).unsqueeze(0)) inpainted_tensor = torch.cat(l, 0) return inpainted_tensor
Example #8
Source File: utils.py From GLCIC-PyTorch with MIT License | 4 votes |
def poisson_blend(input, output, mask): """ * inputs: - input (torch.Tensor, required) Input tensor of Completion Network, whose shape = (N, 3, H, W). - output (torch.Tensor, required) Output tensor of Completion Network, whose shape = (N, 3, H, W). - mask (torch.Tensor, required) Input mask tensor of Completion Network, whose shape = (N, 1, H, W). * returns: Output image tensor of shape (N, 3, H, W) inpainted with poisson image editing method. """ input = input.clone().cpu() output = output.clone().cpu() mask = mask.clone().cpu() mask = torch.cat((mask, mask, mask), dim=1) # convert to 3-channel format num_samples = input.shape[0] ret = [] for i in range(num_samples): dstimg = transforms.functional.to_pil_image(input[i]) dstimg = np.array(dstimg)[:, :, [2, 1, 0]] srcimg = transforms.functional.to_pil_image(output[i]) srcimg = np.array(srcimg)[:, :, [2, 1, 0]] msk = transforms.functional.to_pil_image(mask[i]) msk = np.array(msk)[:, :, [2, 1, 0]] # compute mask's center xs, ys = [], [] for j in range(msk.shape[0]): for k in range(msk.shape[1]): if msk[j, k, 0] == 255: ys.append(j) xs.append(k) xmin, xmax = min(xs), max(xs) ymin, ymax = min(ys), max(ys) center = ((xmax + xmin) // 2, (ymax + ymin) // 2) dstimg = cv2.inpaint(dstimg, msk[:, :, 0], 1, cv2.INPAINT_TELEA) out = cv2.seamlessClone(srcimg, dstimg, msk, center, cv2.NORMAL_CLONE) out = out[:, :, [2, 1, 0]] out = transforms.functional.to_tensor(out) out = torch.unsqueeze(out, dim=0) ret.append(out) ret = torch.cat(ret, dim=0) return ret
Example #9
Source File: GazeboWorld.py From Monocular-Obstacle-Avoidance with BSD 2-Clause "Simplified" License | 4 votes |
def GetDepthImageObservation(self): # ros image to cv2 image try: cv_img = self.bridge.imgmsg_to_cv2(self.depth_image, "32FC1") except Exception as e: raise e try: cv_rgb_img = self.bridge.imgmsg_to_cv2(self.rgb_image, "bgr8") except Exception as e: raise e cv_img = np.array(cv_img, dtype=np.float32) # resize dim = (self.depth_image_size[0], self.depth_image_size[1]) cv_img = cv2.resize(cv_img, dim, interpolation = cv2.INTER_AREA) cv_img[np.isnan(cv_img)] = 0. cv_img[cv_img < 0.4] = 0. cv_img/=(10./255.) # cv_img/=(10000./255.) # print 'max:', np.amax(cv_img), 'min:', np.amin(cv_img) # cv_img[cv_img > 5.] = -1. # # inpainting # mask = copy.deepcopy(cv_img) # mask[mask == 0.] = 1. # mask[mask != 1.] = 0. # mask = np.uint8(mask) # cv_img = cv2.inpaint(np.uint8(cv_img), mask, 3, cv2.INPAINT_TELEA) # # guassian noise # gauss = np.random.normal(0., 0.5, dim) # gauss = gauss.reshape(dim[1], dim[0]) # cv_img = np.array(cv_img, dtype=np.float32) # cv_img = cv_img + gauss # cv_img[cv_img<0.00001] = 0. # # smoothing # kernel = np.ones((4,4),np.float32)/16 # cv_img = cv2.filter2D(cv_img,-1,kernel) cv_img = np.array(cv_img, dtype=np.float32) cv_img*=(10./255.) # cv2 image to ros image and publish try: resized_img = self.bridge.cv2_to_imgmsg(cv_img, "passthrough") except Exception as e: raise e self.resized_depth_img.publish(resized_img) return(cv_img/5.)