将直方图拆分为两个区域

时间:2017-01-09 11:25:40

标签: matlab

我想将直方图划分为两个区域(通过获取直方图图像的平均强度值)。

hR = imhist(redChannel);
minRed = min(redChannel(:));
maxRed = max(redChannel(:));
avgRed = (minRed+maxRed)/2;
hlowR = hR(1:avgRed);
hhighR = hR(avgRed:256);

hlowR给出值,但hhighR为空。我不知道出了什么问题。请帮忙。感谢

1 个答案:

答案 0 :(得分:5)

hR = imhist(redChannel);
% minRed = min(redChannel(:));
% maxRed = max(redChannel(:));
% avgRed = (minRed+maxRed)/2;
avgRed = mean(redChannel(:)); % get mean directly
hlowR = hR(hR<=avgRed); % Logical index to find all values below the average
hhighR = hR(hR>=avgRed);% Logical index to find all values above the average

您直接使用avgRed作为索引,而您应使用logical indexing检查hR的值是高于还是低于https://codeigniter.com/userguide3/libraries/sessions.html#CI_Session::userdata