<div dir="ltr">Hi,<div style> I&#39;d like to run convolutions at locations of a mask while limiting the kernel to the pixels inside the mask. For example:</div><div style>Mask</div><div style>1 1 0</div><div style>1 1 1</div>

<div style>1 1 1</div><div style><br></div><div style>kernel:</div><div style>1/9 1/9 1/9</div><div style>1/9 1/9 1/9 </div><div style>1/9 1/9 1/9</div><div style><br></div><div style>Source image:</div><div style>0.5 0.5 0.2</div>

<div style>0.5 0.5 0.5<br></div><div style>0.5 0.5 0.5<br></div><div style><br></div><div style>In this case I&#39;d like the convolution results for pixel [1,1] (center in this example) to be </div><div style>8*0.5*1/(8) = 0.5</div>

<div style>My kernels will always have mean 1.</div><div style><br></div><div style>So effectively the kernel is adapted at each iteration based on the mask. (Rationale is that only valid pixels contribute to the smoothed result).</div>

<div style>I have usually achieved this in Matlab by filling the non mask pixels with nanmean and nansum.</div><div style><br></div><div style>I am not sure of the best way to achieve this in ITK - I can&#39;t see an obvious way of doing it.</div>

<div style>It seems I need to recalculate the kernel for each iteration - am I looking at implementing a new filter or can I use an existing filter for this?</div><div style><br></div><div style>Thanks,</div><div style>Soren</div>

<div style><br></div></div>