Filter löschen
Filter löschen

Making a matrix of NaN and integers

2 Ansichten (letzte 30 Tage)
Janell Lopez
Janell Lopez am 1 Mär. 2016
Beantwortet: Andrei Bobrov am 2 Mär. 2016
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!

Akzeptierte Antwort

Star Strider
Star Strider am 2 Mär. 2016
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

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 2 Mär. 2016
padarray (I, [1,1],nan); % I - your array

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by