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

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 commentaires

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 le 25 Août 2013
Modifié(e) : shimul le 25 Août 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

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaires

Thanks for your response Sir. I think I made a little mistake to ask the question. It should be how to replace the center pixel of a 3X3 window with the min difference between its surrounding pixels in matlab? 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.
shimul
shimul le 25 Août 2013
Modifié(e) : shimul le 25 Août 2013
I think I have got the solution. Now how can I do the same process on Red, Green and Blue channels independently. And then I want to take the average value of the three color channels
What kind of image is this supposed to produce? Why are you doing this operation? What good is it? What effect does it produce?
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by