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

조회 수: 3 (최근 30일)
Suchitra Ojha
Suchitra Ojha 2019년 11월 29일
댓글: Suchitra Ojha 2019년 12월 4일
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.

답변 (1개)

Image Analyst
Image Analyst 2019년 11월 29일
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
Image Analyst
Image Analyst 2019년 12월 3일
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 2019년 12월 4일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by