# Possible to apply filter2 to only values above a limit?

조회 수: 5(최근 30일)
Josh 2014년 2월 27일
댓글: Josh 2014년 3월 6일
I have an array which I'm attempting to filter with a Gaussian blur to smooth the surface and contour plots. Without any filtering, this is the resulting contour plot:
This code:
G=fspecial('gaussian',[5 5],2);
Af=filter2(G,A,'same');
contour(X,Y,A);
Gives the following contour plot:
As you can see, the contours are nicely smoothed, but the filter has blurred the transitions too much and shifted them wider and outwards.
My Question:
Is it possible to refer to just array elements above a certain value for the filtering?
I'm sure it must be and I'm just being stupid not figuring it out.
Cheers

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

### 채택된 답변

Oliver Woodford 2014년 3월 3일
Compute the filtered version for all pixels, and simply replace the pixels above a certain value with their filtered value:
G = fspecial('gaussian',[5 5],2);
Af = filter2(G,A,'same');
M = A > thresh;
A(M) = Af(M);
contour(X,Y,A);
##### 댓글 수: 1표시 없음숨기기 없음
Josh 2014년 3월 6일
that works great!
much appreciated :)

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

### 추가 답변(1개)

Josh 2014년 3월 2일
bump
Perhaps there's a different type of filter I can use, which preserves edges better?

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

### 범주

Find more on Contour Plots in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by