2017-01-09 85 views
0

我想將直方圖分成兩個區域(通過獲取直方圖圖像的平均強度值)。將直方圖分成兩個區域

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

hlowR給出值但hhighR爲空。我不知道什麼是錯的。請幫忙。由於

+1

「avgRed」的價值是什麼? –

回答

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直接作爲指標,而你應該檢查的hR值是否高於或低於它,使用logical indexing

+0

感謝您的回答。你能告訴我如何在每個區域進行直方圖拉伸? –

+0

@BENISHAMIN這是另一個問題,所以請在Stack Overflow上做一個單獨的帖子,牢記[ask]的規則,所以在發佈之前請自己嘗試一下。 – Adriaan