MATLAB: Calculate mean value on a skeleton of an image

Image Processing Toolboximage skeletonmean value

Hi everyone! I'm working on a skeleton of an image and I found some errors on it. I marked them with ones, so I can identify them easily. I had introduced data in the positions of the original skeleton, that's why most of the values are different to 1 and 0. I'd like to change the value of the ones by the mean value of the 3×3 neighbours of that position, that are different to 0 or 1. For example:
A = [0 0 0 265 0 ; 0 1 260 0 0 ; 0 250 0 0 0 ; 251 250 0 0 0 ; 251 0 0 0 0];
I'd like to change the 1 by 255, the mean (average) value of 260 and 250 (neighbours of 1 and with a different value of 1 and 0).

Best Answer

What is A? The modified skeleton or the original image? A skeleton is a binary image of type logical. Ignoring your A, what I'd do is this:
% Blur image
blurredImage = conv2(double(grayImage), ones(3)/9, 'same');
% Replace image "B" with values of the blurred image at the location of the skeleton 1 values:
B(skelImage) = blurredImage(skelImage);
That's the best I can do because I can't follow what you're saying. You have a gray scale image, a logical skeleton image, and you even have a third image that I guess is the skeleton image converted from logical to gray scale and some "data" from the gray scale image has replaced some pixels (or something like that). So, with these 3 images, you only give the one, very-badly-named "A" image, and don't say exactly what it is. Please give all 3 matrices plus a fourth one that is your desired output image.
Related Question