How to find guassian gradient of a matrix with many Nan values
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a matrix with 40 x 60 pixels with many Nan values ,When I applied guassian gradient ,result is Nan matrix.
GHow to ignore Nan values for applying guassian gradient.
0 Kommentare
Antworten (1)
Image Analyst
am 29 Nov. 2019
I'd use a modified median filter. So
% Set all nan values to inf, take the median filter of the array.
nanIndexes = isnan(m);
m(nanIndexes) = inf;
mfm = medfilt2(m, [3,3]); % Make window big enough to cover any nan regions.
% Then replace nan's in the original matrix with the median filtered values:
m(nanIndexes) = mfm(nanIndexes)
Then do your gradient operation, like with imgradient() or whatever. Try that and see if it works. If it doesn't, attach your data and code.
3 Kommentare
Image Analyst
am 3 Dez. 2019
I don't know how. m and nanIndexes are both 2-D matrices, not vectors of zero, as long as there are nan's in the m matrix. Here's a small example
m = magic(7);
m(4,4) = nan % Set the middle pixel to nan.
% Set all nan values to inf, take the median filter of the array.
nanIndexes = isnan(m)
m(nanIndexes) = inf
mfm = medfilt2(m, [3,3]) % Make window big enough to cover any nan regions.
% Then replace nan's in the original matrix with the median filtered values:
m(nanIndexes) = mfm(nanIndexes)
First you'll see
m =
30 39 48 1 10 19 28
38 47 7 9 18 27 29
46 6 8 17 26 35 37
5 14 16 NaN 34 36 45
13 15 24 33 42 44 4
21 23 32 41 43 3 12
22 31 40 49 2 11 20
then after repair you'll see
m =
30 39 48 1 10 19 28
38 47 7 9 18 27 29
46 6 8 17 26 35 37
5 14 16 26 34 36 45
13 15 24 33 42 44 4
21 23 32 41 43 3 12
22 31 40 49 2 11 20
Save your original matrix in a .mat file
save('answers.mat', 'm');
then attach here with the paper clip icon.
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!