Image Blur using mean of nearby pixels

조회 수: 8 (최근 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