Main Content

inpaintCoherent

使用基于相干传输的图像镶嵌恢复特定的图像区域

Description

例子

j= InPaintCoherent(,,,,面具使用基于相干传输的介入方法来恢复输入图像中的特定区域。面具是一个逻辑图像,表示图像中的目标区域要通过镶嵌填充。

例子

j= InPaintCoherent(,,,,面具,,,,姓名,,,,Value使用一个或多个名称值参数指定附加的入藏选项。

Examples

collapse all

阅读要涂成工作空间的图像。此图像包含要删除的文本叠加层。

i = imread('Overlayimage.png');

Read the mask image into the workspace. This mask image contains the overlayed text regions present in the image to be inpainted.

mask = imread('text.png');

Display the image to be inpainted and its corresponding mask image.

蒙太奇({i,mask});标题([“要被涂上的图像”,,,,'|',,,,“掩盖涂涂”])

图包含一个轴对象。带有标题图像的轴对象|用于内部的掩码包含类型图像的对象。

我npaint the original image by removing the text overlays.

J = InpaintCoherent(i,蒙版);

Display the original image and the inpainted image.

montage({I,J}); title([“要被涂上的图像”,,,,'|',,,,'我npainted Image'])

图包含一个轴对象。带有标题图像的轴对象|Intrainted图像包含类型图像的对象。

阅读要涂成工作空间的图像。

i = imread('coloredchips.png');

Display the image.

figure imshow(I,[])

使用drawcirclefunction to select a circular region of interest (ROI) for inpainting. Use the中心andRadiusname-value pairs to specify the location of an ROI.

h = drawcircle('中心',[130,42],,'Radius',40);

图包含一个轴对象。轴对象包含2个类型图像的对象,images.roi.circle。

选择多个ROI进行涂料

您还可以迭代地选择多个ROI。

将要覆盖的区域的数量设置为6。

numRegion = 6;

为每个区域指定中心和半径。

roiCenter = [130 42;433 78;208 108;334 124;434 167;273 58]; roiRadius = [40 50 40 40 40 30];

通过指定多个圆形ROI迭代drawcircle中心andRadiusname-value pairs.

roi = cell([numRegion,1]);为了i = 1:numegion c = roicenter(i,:);r = roiradius(i);h = drawcircle('中心',,,,c,'Radius',r);ROI {i} = h;结尾

图包含一个轴对象。The axes object contains 8 objects of type image, images.roi.circle.

使用createMaskfunction to generate a mask from the selected ROIs.

面具= zeros(size(I,1),size(I,2));为了i = 1:numRegion newmask = createMask(ROI {i});mask = XOR(Mask,NewMask);结尾

Display the image to be inpainted and its corresponding mask image.

蒙太奇({i,mask});标题([“要被涂上的图像”,,,,'|',,,,“掩盖涂涂”])

图包含一个轴对象。带有标题图像的轴对象|用于内部的掩码包含类型图像的对象。

Remove objects in the ROIs through inpainting. Specify a standard deviation of 0.5 and an inpainting radius of 1.

j = indpaintcoherent(i,面具,'SmoothingFactor',,,,0.5,'Radius',,,,1);

Display the original image and the inpainted image.

montage({I,J}); title([“要被涂上的图像”,,,,'|',,,,'我npainted Image');

图包含一个轴对象。带有标题图像的轴对象|Intrainted图像包含类型图像的对象。

输入参数

collapse all

我mage to inpaint, specified as a grayscale image of sizem-by-n或大小的RGB颜色图像m-by-n-by-3.

数据类型:单身的|double|int8|int16|int32|UINT8|uint16|UINT32

目标区域的空间面具,,,,specified as a 2-D binary image of sizem-by-n,,,,wheremandnare the dimensions of input image。The nonzero pixels in面具constitute the target regions to be filled through inpainting.

笔记

数据类型:逻辑

名称值参数

Specify optional pairs of arguments asname1 = value1,...,namen = valuen,,,,where姓名是参数名称和Valueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名用引号。

Example:j = indpaintcoherent(i,面具,'Radius',7)

高斯过滤器的标准偏差,指定为逗号分隔对'SmoothingFactor'和一个正数。该值用于计算高斯过滤器的尺度,同时估计相干方向。

覆盖半径,指定为逗号分隔对'Radius'and a positive integer. The inpainting radius denotes the radius of the circular neighborhood region centered on the pixel to be inpainted.

输出参数

collapse all

我npainted image, returned as a grayscale image or RGB color image of the same size and data type as input image

Tips

  • 介入结果取决于名称值对规范。您可以修改值'Radius'and'SmoothingFactor'对于各种结果。

  • Each ROI in the binary mask image must be sufficiently large to enclose the corresponding region in the image to be inpainted.

Algorithms

基于连贯运输的涂漆方法是一种基于像素的方法,用于删除对象和填充图像中的区域[1]。从目标区域的边界像素开始对内部进行介入。像素的覆盖值是根据其相干相邻像素估计的,具有已知值。所涉及的步骤总结如下:

  1. 我dentify target regions from the input image to be filled or inpainted. Generate a binary mask of the size same as the input image. The nonzero pixels in the mask image must contain the target regions to be inpainted.

    The order in which the pixels in the target region are inpainted is calculated from their Euclidean distance to the boundary of the target region.

  2. 目标区域中像素的覆盖值是其内部半径内已知像素值的加权平均值。沿相干方向的已知像素比不一致的相邻像素更高。通过使用结构张量来估计相干方向。

References

[1] F. Bornemann and T. März. "Fast Image Inpainting Based on Coherence Transport."数学成像和视觉杂志。卷。28,2007,第259–278页。

扩展功能

版本历史记录

在R2019a中引入