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

2 ビュー (過去 30 日間)
Myra Poblete
Myra Poblete 2020 年 6 月 10 日
コメント済み: Walter Roberson 2020 年 6 月 12 日
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 件のコメント
Myra Poblete
Myra Poblete 2020 年 6 月 10 日
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 2020 年 6 月 12 日
>> 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.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by