Possible to apply filter2 to only values above a limit?

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:
load 'A'
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
Oliver Woodford 2014 年 3 月 3 日

0 投票

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
Josh 2014 年 3 月 6 日
that works great!
much appreciated :)

サインインしてコメントする。

その他の回答 (1 件)

Josh
Josh 2014 年 3 月 2 日

0 投票

bump
Perhaps there's a different type of filter I can use, which preserves edges better?

カテゴリ

ヘルプ センター および File ExchangeContour Plots についてさらに検索

質問済み:

2014 年 2 月 27 日

コメント済み:

2014 年 3 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by