Image Blur using mean of nearby pixels
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
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
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);
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!