How to find guassian gradient of a matrix with many Nan values

3 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Image Analyst
Image Analyst il 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 Commenti
Image Analyst
Image Analyst il 3 Dic 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.
Suchitra Ojha
Suchitra Ojha il 4 Dic 2019
In my image its like
m=
Nan 39 48 Nan 10 19 28
38 47 7 9 Nan Nan Nan
46 Nan 8 17 Nan 35 Nan
Nan Nan 16 26 34 36 Nan
Nan Nan Nan 33 42 Nan 4
21 23 Nan 41 Nan 3 Nan
22 31 Nan 49 2 Nan Nan

Accedi per commentare.

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by