将直方图分为三个部分

时间:2017-02-28 05:24:05

标签: matlab

我想将直方图分为三个部分,并定义三个部分的范围。

minRed = min(red(:));
maxRed = max(red(:));
AvgRed = (minRed+maxRed)/3;
AvgRed2 = AvgRed+AvgRed;

但有时AvgRed的值小于minRedAvgRed2的值超过maxRed。这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

我认为这只是简单的数学:

假设minRed = 10maxRed = 100

minRed = 10;
maxRed = 100;

您希望将范围分为三个相同大小的部分:
AvgRed应为40AvgRed2应为70

%  minRed   AvgRed   AvgRed2  minRed
%  ------   ------   -------  ------
%1    10      40       70       100
%|    |        |        |        |
%     <-------------------------->
%                range

%Calculate the range:  
range = maxRed - minRed;

%Size of each part is third of the range.
thirdRange = range/3;

%Add 1/3 of range to minRed to get AvgRed (round it case value needs to be an integer).
AvgRed = minRed + round(thirdRange);

%Add 2/3 of range to minRed to get AvgRed2.
AvgRed2 = minRed + round(thirdRange*2);

画画时很简单......