Average of pixel difference from center pixel

10 views (last 30 days)
Nataliya
Nataliya on 13 Sep 2015
Answered: Image Analyst on 13 Sep 2015
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

Answers (2)

Image Analyst
Image Analyst on 13 Sep 2015
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 on 13 Sep 2015
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 Comments
Walter Roberson
Walter Roberson on 13 Sep 2015
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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!