MATLAB: How can i blur an image where the mask is

blureyefundusImage Processing Toolboxmaskophthalmologyremoveretinavessels

Hello, currently i have these two Images:
and
What i am desperately trying to do is to get rid of most of the vessels (mainly in the lagre bright spot).
The first Image is my Mask, and it's binary. The second Image is an RBG Image.
I already looked through the Documentation and did some research in the Forums and on Google, but I did not find any possibility I can use to solve my problem.
What I then tried was:
n=0;
for i=1:size(vessels_to_remove,1);
for j=1:size(vessels_to_remove,2);
if vessels_to_remove(i,j)==1;
n=n+1;
img_original(i,j)=img_original(i,j-n);
else
n=0;
end
end
end
I am running throug all Rows and Colums and check whether the Mask is white. If so I increase n by one to remember where the last non-white pixel was. Then i set the value current pixel of the RBG image to the value of the remembered pixel. The result is not what i expected. I wanted the vessels to dissapear, by setting their pixels to the values of their neighbours.
Somehow this weird alpha-mixed image comes out for me if I use the code from above:
Thank you very much in advance.

Best Answer

That way is not good. A better way would be to split the image up into individual color channels.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then call imdilate on each one to replace the dark pixels with the local max pixel.
dilatedRed = imdilate(redChannel, true(11));
Then use the mask to assign only the pixels under the mask.
redChannel(vessels_to_remove) = dilatedRed(vessels_to_remove);
Then do the same for the other colors and recombine.
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);