2017-01-10 56 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)