Average of pixel difference from center pixel

2 次查看(过去 30 天)
I want to replace the value of center pixel by the average value of the pixel difference of its 3x3 neighboring pixels. How to do it? Please guide me. Thanks

回答(2 个)

Image Analyst
Image Analyst 2015-9-13
Walter's right - your definition of "difference" is not precise enough. Please clarify. If you mean the color difference, delta E, then you can run the attached demo that computes the local color difference, in a moving window, between a pixel and its neighbors in a window around it.

Walter Roberson
Walter Roberson 2015-9-13
conv2(YourImage, [1 1 1;1 -8 1; 1 1 1]/8, 'same')
This might not be valid on the outside border, but you did not define the behavior for the outside border.
  2 个评论
Nataliya
Nataliya 2015-9-13
Thanks for the response. I am working with rgb images and conv2 function does not work for 3-D images. Please suggest what can I do in this case. Thanks
Walter Roberson
Walter Roberson 2015-9-13
You are going to need to write out the formula. Take the case of a 3 x 3 image that is RGB, so 3 x 3 x 3. Write out the formula you would use to calculate the average for the pixel at the center, location (2,2,:).
I need you to write out the formula because there are a lot of different possible meanings to "pixel difference" and "average" for RGB. Is the difference to be taken in Hue? In Saturation? In grayscale intensity? In a* coordinates in La*b* colorspace? In Z coordinates in XYZ colorspace? Should the RGB values be taken as representing 3 dimensional coordinates and the "pixel difference" be interpreted as the cos of the vector angle for the rays between (0,0,0) and the two different RGB triples?

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by