Image Blur using mean of nearby pixels

7 ビュー (過去 30 日間)
Perturabo
Perturabo 2019 年 2 月 8 日
コメント済み: Shunichi Kusano 2019 年 2 月 12 日
I have a problem function that Blurs image with the following output
output = blur(img,w);
where w is a parameter used for averaging. The output pixel value is the mean of the pixels in a square submatrix of size 2w+1 where the given pixel sits in the center.
After looking on the internet I tried this
im1 = imread(img);
kernel = ones(2*n+1)/(2*n+1)^2;
output = imfilter(im1,kernel);
but it gives errors
Error using imread>parse_inputs (line 502)
The file name or URL argument must be a character vector or string scalar.
Error in imread (line 342)
[source, fmt_s, extraArgs, was_cached_fmt_used] = parse_inputs(cached_fmt, varargin{:});
Error in blur (line 2)
rgbImage = imread(Y); % Sample image.
Honestly I don't even understand what it is saying.

回答 (1 件)

Shunichi Kusano
Shunichi Kusano 2019 年 2 月 8 日
The error comes from "imread". The function expects "The file name or URL argument" as input, but "img" seems not so. "img" can be used directly in imfilter in this case. please try:
output = imfilter(img,kernel);
hope his helps.
  2 件のコメント
Perturabo
Perturabo 2019 年 2 月 8 日
If I use
output = imfilter(img,kernel);
then what would be the purpose of
im1 = imread(img);
besides using this produced an error
Undefined function 'imfilter' for input arguments of type 'uint8'.
Error in blur (line 3)
output = imfilter(img,kernel);
Shunichi Kusano
Shunichi Kusano 2019 年 2 月 12 日
I misunderstood what you want to do.
The function you made works. Note that "img" must be the filename of your image.
function output = blur(img, w);
im1 = imread(img);
kernel = ones(2*w+1)/(2*w+1)^2;
output = imfilter(im1,kernel);

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by