将直方图分为两个区域

问题描述:

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

I want to divide the histogram into two regions (by taking the avg intensity value of histogram image).

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

hlowR提供值,但hhighR为空.我不知道怎么了请帮忙.谢谢

hlowR is giving the values but hhighR is empty. I don't know what's wrong. Please help. Thanks

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用作索引,同时应使用

You are using avgRed directly as index, whilst you should check whether a value of hR is above or below it, using logical indexing.