Making a matrix of NaN and integers

2 次查看(过去 30 天)
I'm having trouble with another assignment. We are to design a "mean filter" image processing function, where each pixel of an image is replaced with the average value of its surrounding pixels. One suggested way of doing this was to create a larger matrix where the outer rows and columns are NaN elements, and then for the image's outer rows and columns we can use the NaNMean function.
I have created a row vector of NaN the same size as my image, and a column vector the same size + 2. But I am not sure how to add them to my image matrix--I have tried just the + operator, and concatenation, but I get errors each time. What am I missing?
Thanks!

采纳的回答

Star Strider
Star Strider 2016-3-2
If I understand correctly what you want to do, this works:
Img = uint8(randi([0 255], 5, 7)); % Create ‘Image’
[R,C] = size(Img); % Get ‘Image’ Dimensions
nan_border = nan(R+2,C+2); % Create NaN Matrix
nan_border(2:R+1, 2:C+1) = Img; % Insert ‘Image’ Into NaN Matrix
nan_border =
NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN 60 23 185 253 185 201 28 NaN
NaN 245 65 58 23 142 81 69 NaN
NaN 158 219 147 82 135 115 134 NaN
NaN 153 233 207 130 212 192 248 NaN
NaN 44 179 103 15 219 28 181 NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN

更多回答(1 个)

Andrei Bobrov
Andrei Bobrov 2016-3-2
padarray (I, [1,1],nan); % I - your array

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by