将直方图分为两个区域
问题描述:
我想将直方图分为两个区域(通过获取直方图图像的平均强度值).
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
You are using avgRed
directly as index, whilst you should check whether a value of hR
is above or below it, using logical indexing.