How to invert contourf(data,[threshold threshold],'k') and modify color

Dear Experts,
I need to make contours around significant peaks (statistical values presented with imagesc or pcolor), and whiten the thoughs between the peaks.
contourf(2Dmatrix,[threshold threshold],'k')
does almost what I want...
... but it comes the wrong way round: It makes a threshold and covers the hill of the peak with some color and encloses it with the black line.
I would need to keep the hills uncovered, but to cover the thoughs, with white color of 0.4 transparency.
Any ideas how to achieve this?
Thanks in advance!
Markus

 Accepted Answer

Perhaps
AlphaMask = double(TwoDmatrix < threshold);
whitecover = ones(size(TwoDMatrix, 1), size(TwoDMatrix, 2), 3);
image(whitecover, 'AlphaData', AlphaMask);

3 Comments

Dear Walter,
Thank you!
Is it like this? (I used peaks for illustration).
TwoDMatrix=peaks(30);
threshold = 3;
figure; hold on;
imagesc(TwoDMatrix);
[c,h]=contourf(TwoDMatrix),[threshold threshold],'k','Linewidth',2); axis([1 30 1 30])
AlphaMask = double(TwoDMatrix < threshold);
whitecover = ones(size(TwoDMatrix, 1), size(TwoDMatrix, 2), 3);
image(whitecover, 'AlphaData', AlphaMask);
The result looks as follows:
So I would be missing the transparency and also the smoothness of the black line.
I found another way as follows:
figure; hold on;
g=imagesc(TwoDMatrix);
[c,h]=contourf(TwoDMatrix,[-Inf threshold],'k','Linewidth',2); axis([1 30 1 30])
allH = allchild(h);
patchValues = cell2mat(get(allH,'UserData'));
patchesToHide = patchValues <= threshold;
set(allH(patchesToHide),'FaceColor','w','FaceAlpha',0.4);
And the result comes with some visible transparency, however all over. It doesn't spear the enclosed clusters within the black lines.
Do you know how to achieve this?
Thanks for your ideas!
Best, markus
I should have said
AlphaMask = 0.4 * double(TwoDMatrix < threshold);
whitecover = ones(size(TwoDMatrix, 1), size(TwoDMatrix, 2), 3);
image(whitecover, 'AlphaData', AlphaMask);
after which you can
contour(TwoDMatrix, [threshold threshold], 'k')
Works perfectly! Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!