Calculate mean value on a skeleton of an image
1 次查看(过去 30 天)
显示 更早的评论
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 3x3 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).
0 个评论
采纳的回答
Image Analyst
2017-2-23
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.
3 个评论
Image Analyst
2017-2-24
OK, let's say the ground height image is called heightImage, rather than something bad like "B". So you'd do :
% Blur original height image
blurredImage = conv2(double(heightImage), ones(3)/9, 'same');
% Find out where the 1's in "A" live:
onesLocations = A == 1;
% Replace image "A" with values of the blurred image at the location of A's 1 values:
A(onesLocations) = blurredImage(onesLocations);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!