隐藏hist3图中的零值(计数)

时间:2013-07-04 16:26:04

标签: matlab graphics histogram

您可以隐藏zero values in a bar3 plot,但该解决方案不能直接适用hist3(),即使解决方法类似于时尚。

以下是基于imdilate()的解决方法,需要图像处理TB,我希望看到建议 独立于工具箱(只有Stats TB才行)。

% Example graph
hist3([2 0; 0 1; 1 1],[2 2])

enter image description here

% handle to graph3d.surfaceplot
h = get(gca,'child');

% retrieve the heights
heights       = get(h,'Zdata');

% Index outer heights leaving a contour of zeros
mask          = ~logical(imdilate(heights,ones(3)));

% Set the zero heights to NaN
heights(mask) = NaN;

% Final result
set(h,'ZData',heights)

enter image description here

以下是heights

的情况
heights =...
    [0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     1     1     0     0
     0     0     0     0     0     0     1     1     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     1     1     0     0     0     1     1     0     0
     0     1     1     0     0     0     1     1     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0]
mask =...
    [1     1     1     1     1     0     0     0     0     1
     1     1     1     1     1     0     0     0     0     1
     1     1     1     1     1     0     0     0     0     1
     1     1     1     1     1     0     0     0     0     1
     1     1     1     1     1     1     1     1     1     1
     0     0     0     0     1     0     0     0     0     1
     0     0     0     0     1     0     0     0     0     1
     0     0     0     0     1     0     0     0     0     1
     0     0     0     0     1     0     0     0     0     1
     1     1     1     1     1     1     1     1     1     1]
heights =...
  [NaN   NaN   NaN   NaN   NaN     0     0     0     0   NaN
   NaN   NaN   NaN   NaN   NaN     0     1     1     0   NaN
   NaN   NaN   NaN   NaN   NaN     0     1     1     0   NaN
   NaN   NaN   NaN   NaN   NaN     0     0     0     0   NaN
   NaN   NaN   NaN   NaN   NaN   NaN   NaN   NaN   NaN   NaN
     0     0     0     0   NaN     0     0     0     0   NaN
     0     1     1     0   NaN     0     1     1     0   NaN
     0     1     1     0   NaN     0     1     1     0   NaN
     0     0     0     0   NaN     0     0     0     0   NaN
   NaN   NaN   NaN   NaN   NaN   NaN   NaN   NaN   NaN   NaN]

1 个答案:

答案 0 :(得分:3)

您可以将imdilate(height, ones(3))替换为

filter2(ones(3), height)

conv2(ones(3), height, 'same') 

并且都不需要工具箱。