Image Blur using mean of nearby pixels

3 vues (au cours des 30 derniers jours)
Perturabo
Perturabo le 8 Fév 2019
Commenté : Shunichi Kusano le 12 Fév 2019
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.

Réponses (1)

Shunichi Kusano
Shunichi Kusano le 8 Fév 2019
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 commentaires
Perturabo
Perturabo le 8 Fév 2019
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 le 12 Fév 2019
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);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by