Overlay of dashed cells on imagesc

조회 수: 4 (최근 30일)
simonb
simonb 2018년 4월 8일
댓글: simonb 2018년 4월 8일
I have a 20x20 matrix that I use to create a figure via imagesc which looks like this:
The matrix has numbers between 0 and 40+. I would like to be able to create an overlay such that I can automatically create a subtle pattern for cells below a threshold (e.g., 20) so that they are dashed over. Looking like this:
Instead of painfully doing this via paint (like I did for this figure), I had created something simple where thresholdmet=data<20; is a new matrix, and use that to create another imagesc. I played with transparency, and where it's not a hard black but a pattern, but could never get it to work.
It obviously does not have to be the dashes, even a subtle X or something else that does not hide the color underneath would work. Any thoughts or help would be very appreciated!

채택된 답변

Ahmet Cecen
Ahmet Cecen 2018년 4월 8일
I just answered a question like this, but you have a unique aspect with the pattern. See if you can make sense of this:
%%Inputs
A = zeros(21,21);
A(15,11) = 1;
A = 10000*imgaussfilt(A,7);
Mask = A < 20;
%%Scale the Pixels UP
ABig = repelem(A,11,11);
MaskBig = repelem(Mask,11,11); %Mask should be 1 where there will be patterns.
%%Create Diagaonal Pattern - This is a little Derp
%Someone Else might have a better way.
Pattern = diag(ones(2,1),-9) + diag(ones(5,1),-6) + diag(ones(8,1),-3) ...
+ diag(ones(8,1),3) + diag(ones(5,1),6) + diag(ones(2,1),9) ...
+ diag(ones(11,1),0);
Patterns = repmat(Pattern,size(Mask));
%%Plot Overlay
figure;
% Behind Image
a1 = axes;
h1 = imagesc(a1,ABig); colormap(a1,'parula'); c1 = colorbar; axis image;
% Forward Image
a2 = axes;
h2 = imagesc(a2,Patterns); colormap(a2,'gray'); c2 = colorbar; axis image;
% Make Forward Image Transparent at Padding
alpha(h2, (MaskBig > 0) * 0.2);
% Remove the Axes (the white canvas in a normal figure)
a1.Visible = 'off';
a2.Visible = 'off';
% Make background colorbar invisible.
% If you delete the colorbar, they will not align.
c1.Visible = 'off';
  댓글 수: 1
simonb
simonb 2018년 4월 8일
This was super helpful, and exactly what I needed. Thank you so much!

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by