how to replace the center pixel of a 3X3 window with the min difference among its surronding pixels in matlab?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2013년 8월 25일
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?
채택된 답변
Image Analyst
2013년 8월 25일
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
추가 답변 (1개)
Walter Roberson
2013년 8월 25일
You could do it easily with blockproc()
댓글 수: 1
Walter Roberson
2013년 8월 25일
If Px is the 3 x 3 pixel array, then
min(diff(sort(Px([1:4, 6:9]))))
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!