how to replace the center pixel of a 3X3 window with the min difference among its surronding pixels in matlab?

2 views (last 30 days)
I want to replace the center pixel of a 3x3 window filter with the minimum difference among its surrounding pixels. I want to run this process for all pixels of the image.
Then I want to calculate the mean square of the minimum differences of all pixels in the entire image.
Would you please give me some suggestion or code snippet to solve my problem. I am new in matlab.
Please response..
  2 Comments
Walter Roberson
Walter Roberson on 25 Aug 2013
If two pixels have the same value, then would the minimum difference be 0? Or should the minimum difference be only amongst the unique values (unless all the values are the same)?
Are you wanting the minimum difference comparing the center pixel with the others, or the minimum difference between all pixels in the window compared to all other pixels in the window?
shimul
shimul on 25 Aug 2013
Edited: shimul on 25 Aug 2013
Thanks for your response Walter Roberson. Actually I want to replace the center pixel with the minimum difference between its surrounding pixels. That is if the center pixel is (x,y). Then I want to find the min difference of its 8 neighbors taking two neighbors at a time. Here (x,y+1)-(x,y+2) is one such difference. But I don't want to take the difference between a neighbor and the center

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 25 Aug 2013
I think you're going to have to do it manually by using conv2() 8 times with a [-1 1] kernel that rotates around the 8 neighbors, and then take the min of the 8 images. Then square, sum, and sqrt.
image1 = conv2(grayImage, [-1, 0, 0; 0, 1, 0; 0, 0, 0], 'same');
image2 = conv2(grayImage, [0, -1, 0; 0, 1, 0; 0, 0, 0], 'same');
image3 = conv2(grayImage, [0, 0, -1; 0, 1, 0; 0, 0, 0], 'same');
image4 = conv2(grayImage, [0, 0, 0; -1, 1, 0; 0, 0, 0], 'same');
image5 = conv2(grayImage, [0, 0, 0; 0, 1, -1; 0, 0, 0], 'same');
image6 = conv2(grayImage, [0, 0, 0; 0, 1, 0; -1, 0, 0], 'same');
image7 = conv2(grayImage, [0, 0, 0; 0, 1, 0; 0, -1, 0], 'same');
image8 = conv2(grayImage, [0, 0, 0; 0, 1, 0; 0, 0, -1], 'same');
allImages = cat(3, image1, image2, image3, image4, image5, ...
image6, image7, image8);
minDiffImage = min(allImages, [], 3);
minDiffImage = minDiffImage .^2; % Square it.
mse = mean(minDiffImage (:));
Try that untested code and see how it works.
  5 Comments
shimul
shimul on 25 Aug 2013
I want to highlight the noise pixels. I have executed it for the three (R G B) different channels and I am getting a very high value, possibly my image containing a lot of noise.
Actually I am trying to implement a journal named "Reference less image evaluation for whole slide imaging" .
How can I have the implementation or the training samples, input images and corresponding results of the paper.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 25 Aug 2013
You could do it easily with blockproc()

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!