m = [ 3 4 4 2 4 6 8 6 3 2
4 5 NaN NaN 2 3 4 2 1 2
2 NaN NaN NaN 3 2 4 3 1 2
3 NaN NaN NaN 3 4 2 5 3 2
4 NaN NaN NaN 2 4 1 3 2 5
4 5 NaN NaN 2 3 4 2 1 2
2 NaN NaN NaN 3 2 4 3 1 2
3 2 NaN NaN NaN 4 2 5 3 2
4 3 2 NaN NaN NaN 4 1 3 2
4 3 2 3 NaN NaN 2 1 3 2
]
subplot(2, 2, 1);
imshow(m, [], 'InitialMagnification', 800);
title('Original Matrix');
impixelinfo
x = 2;
xImage = x * ones(size(m));
nanLocations = 2 * isnan(m)
subplot(2, 2, 2);
imshow(nanLocations, []);
title('Nan Locations');
impixelinfo
windowWidth = 3;
kernel = ones(windowWidth) / windowWidth^2;
blurred = conv2(nanLocations, kernel, 'same')
blurred = blurred / max(blurred(:));
subplot(2, 2, 3);
imshow(blurred, [], 'InitialMagnification', 800);
title('Blurred');
impixelinfo
m(isnan(m)) = 0;
output = m .* (1 - blurred) + xImage .* blurred;
subplot(2, 2, 4);
imshow(output, [], 'InitialMagnification', 800);
title('Output');
impixelinfo