필터 지우기
필터 지우기

How to smooth 2d matrix

조회 수: 88 (최근 30일)
varunesh
varunesh 2016년 5월 29일
편집: Christian Ballesteros 2021년 5월 10일
I have 2d matrix. size is give below. I want to smooth this but smooth function is not working properly with imagesc. please help me. Thank you in advance
[ch] = imagesc(all_time,height,smooth(data,1000));
all_time = 30509x1
height = 533x1
data = 533x30509

답변 (2개)

Walter Roberson
Walter Roberson 2016년 5월 29일
smooth() is only defined for a vector argument. Internally it reshapes the input to a column vector. If you want to smooth column by column, you will need to do that in a loop before you display the data.
  댓글 수: 1
varunesh
varunesh 2016년 5월 29일
I don't understand that what are you saying? can you write this in a code. please help me

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


Kristoffer Walker
Kristoffer Walker 2020년 7월 21일
Use the ":" operator to convert the matrix to a vector, use smooth() to smooth, and return the content to the original matrix format again using ":" operator. For example
A=[0 0 0; 0 0 0; 0 1 0; 0 0 0 ; 0 0 0]
A(:) = smooth(A(:),3)
No need for fancy conv2, filter, or other commands.
Kris
  댓글 수: 1
Christian Ballesteros
Christian Ballesteros 2021년 5월 10일
편집: Christian Ballesteros 2021년 5월 10일
This way you are not accounting for the effect of side-by-side (columns) samples and you smooth last data of a column with the beginning of the following one, which might not be correlated at all. A proper matrix smoothing requires a 2D filtering window.
Example:
% Input data
[P,T] = meshgrid(0:359,0:180);
A = awgn(sind(T).*cosd(P),5); % My matrix to smooth
w = 5; % Size of the sliding window (same number of cols and rows in this case)
% Extrapolate values for current window
[Nr,Nc] = size(A);
Nextra = 0.5*(w-1);
Ap = interp2(1:Nc,1:Nr,A,-Nextra+1:Nc+Nextra,(-Nextra+1:Nr+Nextra).','makima'); % 2D extrapolation must use 'spline' or 'makima' interpolation
% Smooth data with sliding window
H = ones(w)./w^2; % The 2D averaging filter
B = filter2(H,Ap,'valid'); % The smooth resulting matrix
% Visualize data
figure; pcolor(A); caxis([-1 1]); shading interp;
figure; pcolor(B); caxis([-1 1]); shading interp;

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

카테고리

Help CenterFile Exchange에서 Smoothing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by