我想将直方图分为三个部分,并定义三个部分的范围。
minRed = min(red(:));
maxRed = max(red(:));
AvgRed = (minRed+maxRed)/3;
AvgRed2 = AvgRed+AvgRed;
但有时AvgRed
的值小于minRed
,AvgRed2
的值超过maxRed
。这样做的正确方法是什么?
答案 0 :(得分:0)
我认为这只是简单的数学:
假设minRed = 10
和maxRed = 100
minRed = 10;
maxRed = 100;
您希望将范围分为三个相同大小的部分:
AvgRed
应为40
,AvgRed2
应为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);
画画时很简单......