Hi,<br><br>I have an image with masked-out (invalid) pixels. The masked-out pixels&nbsp; aren&#39;t just on the border, there are many masked pixels all over the image area.<br><br>I want to compute the gradient image of this image.<br>
<br>The standard way to compute the gradient is to convolve with a Gaussian kernel and then with a derivative kernel. This causes the invalid pixels&#39; values to &quot;leak out&quot; to nearby pixels. So if there were say 20% invalid pixels in the original image, the gradient image will have maybe 80% invalid pixels, because their values are functions of one or more nearby invalid pixels.<br>
<br>I don&#39;t know of a standard solution to this problem, but I&#39;ve thought of two ideas.<br><br>One idea is to program a smart blurring operator that is &quot;mask aware&quot;. It&nbsp; will take a weighted average each neighborhood like a Gaussian kernel, except that masked pixels won&#39;t be included in the average. Blurring with this kernel won&#39;t make the masks leak out.<br>
<br>The other idea is to do inpainting of the masked out pixels, i.e. replace the invalid pixels with valid values that are based on a smart interpolation of their neighborhood.&nbsp; Then I can apply a standard gradient filter on the resulting image.<br>
<br>I&#39;d appreciate any ideas or implementation tips.<br><br>- Aviv<br>