フィルターのクリア

Consider a 3 × 3 spatial mask that averages the intensity of all neighbours of a pixel (x, y) in this 3 × 3 neighbourhood, but excluding the point itself.

4 ビュー (過去 30 日間)
How to make a function that applies this filter to an image and displays the original image and the filtered image?
Thanks.
  2 件のコメント
Image Analyst
Image Analyst 2021 年 9 月 9 日
Ben, stop destroying your questions or people will stop helping you.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2021 年 9 月 8 日
Make a kernel that has all 1's except for the center, then divide by 8:
kernel = ones(3,3) / 8;
kernel(2, 2) = 0;
blurredImage = conv2(double(grayImage), kernel, 'same');
There will be some slight errors in the very top, left, top, and bottom row. If you need to correct those you can use two calls to conv2() - one to count pixels and one to sum up values, then divide those two images pixel-by-pixel.
  3 件のコメント
Image Analyst
Image Analyst 2021 年 9 月 8 日
Yes, though imfilter will round to the nearest gray level if it's a uint8 image. You won't get fractional numbers.
Image Analyst
Image Analyst 2021 年 9 月 9 日
Ben:
For your original question where you wanted the pixel to be replaced by the average of the 8 surrounding neighbors, you'd divide by 8.
For your edited question, which does not specify which pixels to include in the average (Why did you change your question???) you should divide by the number of pixels in the averaging window. If it's a 3x3 window and includes the central pixel, that's 9 pixels so you should divide the sum by 9. For a 5x5 using all pixels, divide by 5x5 = 25.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by