zoukankan      html  css  js  c++  java
  • PS 图像调整算法——自动对比度 (Auto Contrast)

    PS 给出的定义:

    Enhance Monochromatic Contrast: Clips all channels identically. This preserves the overall color relationship while making highlights appear lighter and shadows appear darker. The Auto Contrast command uses this algorithm.

    和自动色阶不一样的地方在于,自动对比度不是三个通道分别调整,而是三个通道同时调整,可以先获取图像的亮度信息,然后根据 clipping percentage 对亮度进行动态范围的拉伸,根据拉伸前后亮度的比率,可以同比例调整R,G,B 三个通道,这样调整的图像不会出现色偏的问题。

    先拉伸亮度的动态范围,可以借用自动色阶里的函数。

    function I_out=F_color(I, percent)
    %%% the tonal range of the input image is 0-1.
    [row, col]=size(I);
    I_sort=sort(I(:));
    I_out=I;
    %%% based on the clipping percentage, 
    %%% compute the upper and lower boundaries 

    if (percent==0)
        I_min=min(I_sort)
        I_max=max(I_sort)
    else
        I_min=I_sort(floor(row*col*percent))
        I_max=I_sort(floor(row*col*(1-percent)))
    end

    for i=1:row
        for j=1:col
                if(I(i,j)<I_min)
                    I_out(i,j)=I_min;
                elseif(I(i,j)>I_max)
                    I_out(i,j)=1;
                else
                    I_out(i,j)=(I(i,j)-I_min)*(1-I_min)/(I_max-I_min)+I_min;
                end
        end 
    end


    利用拉伸前后亮度的比率,同比例调整R,G,B三个通道。

    clc;
    clear all;
    Image=imread('8.jpg');
    Image=double(Image)/255;
    imshow(Image);
    R=Image(:,:,1);
    G=Image(:,:,2);
    B=Image(:,:,3);
    I=R*0.2989+G*0.5871+0.1140*B;
    I=I/(max(I(:)));
    percent=0.001;
    I_out=F_color(I, percent);
    delta=0.0001;
    K=(I_out+delta)./(I+delta);
    Image_out(:,:,1)=R.*K;
    Image_out(:,:,2)=G.*K;
    Image_out(:,:,3)=B.*K;
    figure, imshow(Image_out);


    原图:



    调整后的图:


  • 相关阅读:
    angularjs中设置select的选中项
    axios 下载文件
    解决Springboot集成ActivitiModel提示输入用户名密码的问题
    VMWare14 安装Mac OS系统(图解)
    hexo 搜索功能
    Nginx禁止IP直接访问网站
    不确定理论与多传感器数据融合
    Bayes理论与多传感器数据融合
    从“中英文思维回译法”看中英思维差异
    不确定理论与多传感器数据融合
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412725.html
Copyright © 2011-2022 走看看