Overlay of dashed cells on imagesc

4 次查看(过去 30 天)
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 中查找有关 Data Distribution Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by