2017-01-10 46 views
0

我想通過將直方圖劃分爲兩個區域(通過獲取直方圖圖像的平均強度值)並在兩個區域上執行直方圖拉伸來創建增強和增強圖像。請指導我如何做到這一點。由於直方圖分割和拉伸

rgbImage=imread('2.jpg'); 
    redChannel = rgbImage(:, :, 1); 
    hR = imhist(redChannel); 
    minRed = min(redChannel(:)); 
    maxRed = max(redChannel(:)); 
    avgRed = (minRed+maxRed)/2; 
    hlowR = hR(1:avgRed); 
    hhighR = hR(avgRed:255); 

現在我想STRETCH時都hlowRhhighR。請告訴我如何做到這一點。

+0

此代碼不能正常工作,就證明你的[前一個問題(http://stackoverflow.com/ q /5211833分之41546973)。此外,你爲什麼不嘗試任何東西,就像我在[我的評論]中問你的一樣(http://stackoverflow.com/questions/41546973/split-the-histogram-into-tworegions/41547609?noredirect=1 #comment70336374_41547609),引用幫助中心的[問]頁面? – Adriaan

回答

1

如果我明白你的問題,在這裏,可以解決你的問題代碼:

%open the image 
rgbImage=imread('image.jpg'); 
redChannel = rgbImage(:, :, 1); 

%calculate the median 
minRed = min(redChannel(:)); 
maxRed = max(redChannel(:)); 
MedRed = (minRed+maxRed)/2; 

%Histogram equalization on the first part of the histogram. 
hlowR = redChannel; 
hlowR(~ismember(redChannel,0:MedRed)) = 0; 
hlowR = double(hlowR); 
hlowR = uint8(((hlowR-min(hlowR(:)))./(max(hlowR(:))-min(hlowR(:))))*255); 

%Histogram equalization on the second half part of the histogram. 
hhighR = redChannel; 
hhighR(~ismember(redChannel,MedRed :255)) = MedRed ; 
hhighR = double(hhighR); 
hhighR = uint8(((hhighR-min(hhighR(:)))./(max(hhighR(:))-min(hhighR(:))))*255); 

%display the result 
imagesc(hhighR) 
figure 
imagesc(hlowR)