PhotoShop中的色调均化算法(matlab)

1. 统计直方图,对于RGB图像,三通道联合统计

2. 采用累积直方图映射

function outmat = ToneEqualization(inmat, bits)
% PhotoShop色调均化

% bits = 16;
% inmat = imgdata;
% imshow(uint8(inmat./65535.*255));

[Height, Width, plane] = size(inmat);
nbins = uint16(2^bits);
in1 = inmat(:,:,1);
in2 = inmat(:,:,2);
in3 = inmat(:,:,3);
all_in = [in1 in2 in3];
all_hist = zeros(nbins,1);
for i=1:Height
    for j=1:Width*3
        all_hist(uint16(all_in(i,j))) = all_hist(uint16(all_in(i,j))) + 1;
    end
end
% figure;plot(all_hist);

%all_hist = imhist(uint16(all_in(:)),nbins);

% 计算映射表,累积直方图
Num = 0;
for y=1:1:nbins
    Num = Num + all_hist(y);
    Lut(y) = uint32(Num / (Width * Height * 3) * nbins);   
end

outmat = zeros(Height, Width, plane);
for x=1:Height
    for y=1:Width
        outmat(x,y,1) = Lut(uint16(in1(x,y)));
        outmat(x,y,2) = Lut(uint16(in2(x,y)));
        outmat(x,y,3) = Lut(uint16(in3(x,y)));
    end
end
% imshow(uint8(outmat./65535.*255));
end

 

                                           原始图                                                                                 色调均化后

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章