Making a matrix of NaN and integers
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Janell Lopez
le 1 Mar 2016
Réponse apportée : Andrei Bobrov
le 2 Mar 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!
0 commentaires
Réponse acceptée
Star Strider
le 2 Mar 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
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!