Undefined function 'padarray' for input arguments of type 'uint8'.

3 views (last 30 days)
I am doing the MATLAB for beginners in Coursera. I am supposed to blur the image provided. The code works when run in my PC but I am getting this error message on the assignment page.
Undefined function 'padarray' for input arguments of type 'uint8'.
Error in blur (line 3)
img_padded = padarray(img,[w w],0,'both');
function output = blur(img,w)
img = uint8(img);
img_padded = padarray(img,[w w],0,'both');
[row, col] = size(img_padded);
blurred = zeros (row, col);
for ii = (1+w):(row-w)
for jj = (1+w):(col-w)
submatrix = zeros(2*w + 1, 2*w + 1);
for kk = (ii-w):(ii+w)
for ll = (jj-w):(jj+w)
submatrix (kk,ll) = img_padded (kk,ll);
end
end
blurred (ii,jj) = sum (submatrix, 'all')/((2*w+1)^2);
end
end
output = blurred (w+1:row-w,w+1:col-w);
output = uint8(output);
end
  3 Comments
Myra Poblete
Myra Poblete on 10 Jun 2020
Thank you for the prompt response Walter. I have padded the matrix on my own, which worked but failed in both tests.
function output = blur(img,w)
img = uint8(img);
[a b] = size(img);
img_padded = zeros(a+2*w, b+2*w);
img_padded(1+w:a+w, 1+w:b+w) = img;
[row, col] = size(img_padded);
blurred = zeros (row, col);
for ii = (1+w):(row-w)
for jj = (1+w):(col-w)
submatrix = zeros(2*w + 1, 2*w + 1);
for kk = (ii-w):(ii+w)
for ll = (jj-w):(jj+w)
submatrix (kk,ll) = img_padded (kk,ll);
end
end
blurred (ii,jj) = sum (submatrix, 'all')/((2*w+1)^2);
end
end
output = blurred (w+1:row-w,w+1:col-w);
output = uint8(output);
end
Walter Roberson
Walter Roberson on 12 Jun 2020
>> blur(ones(10,10),3)
ans =
10×10 uint8 matrix
0 0 0 1 1 1 1 0 0 0
0 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 0
0 0 0 1 1 1 1 0 0 0
It seems unlikely that an image that is all 1 should get blurred into something that contains some 0's.
However, you did not post the problem statement of what is to happen at the boundaries.

Sign in to comment.

Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!