• Delphi图像处理之饱和度调节


    --------开发环境Delphi7

    ----效果图:
    image

    -----Unit开始
    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, ExtDlgs, ExtCtrls, ComCtrls, Math;

    type
    TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Label1: TLabel;
    OpenPictureDialog1: TOpenPictureDialog;
    Button1: TButton;
    TrackBar1: TTrackBar;
    Label2: TLabel;
    procedure TrackBar1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    private
    procedure SetImageSaturation(sValue: Byte);
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.TrackBar1Change(Sender: TObject);
    begin
    SetImageSaturation(TrackBar1.Position);
    Label2.Caption:='饱和度:'+Inttostr(TrackBar1.Position);
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    if OpenPictureDialog1.Execute then
    begin
    Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
    Label1.Caption:='图片宽x高:'+inttostr(Image1.Picture.Width)+'x'+inttostr(Image1.Picture.Height);
    end;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    OpenPictureDialog1.Filter:='Bitmaps (.bmp)|.bmp';
    self.DoubleBuffered:=true;
    end;

    procedure TForm1.SetImageSaturation(sValue: Byte);
    const
    vThresholdValue:Byte=128;
    var
    vP:PByteArray;
    x,y:Integer;
    vBmp:TBitmap;
    vGray:Integer;
    begin
    {
    饱和度又称为纯度,即色彩的纯净程度。某一纯净色加上白或者黑,可降低其纯度,或趋于柔和或趋于沉重。饱和度调节可以在RGB颜色空间和
    HSL颜色空间,这里是GRB颜色空间的例子

    //设定一个阈值,颜色分量大于此阈值时颜色分量加上一个设定值,颜色分量小于此阈值时颜色分量减去一个设定值

    GRB分量说的就是R、G、B 这个三个分量!

    }
    if Image1.Picture.Graphic =nil then
    begin
    Label2.Caption:='请加载图片!';
    Exit;
    end;
    vBmp:=TBitmap.Create;
    vBmp.Assign(Image1.Picture.Bitmap);
    vBmp.PixelFormat:=pf24bit;
    for y:=0 to vBmp.Height-1 do
    begin
    vP:=vBmp.ScanLine[y];
    for x:=0 to vBmp.Width-1 do
    begin
    //R //红色分量大于阈值的时候
    if vP[3x+2]>vThresholdValue then
    vP[3
    x+2]:=Min(255,vP[3x+2]+sValue)
    else
    vP[3
    x+2]:=Max(0,vP[3x+2]-sValue);
    //G //绿色分量大于阈值的时候
    if vP[3
    x+1]>vThresholdValue then
    vP[3x+1]:=Min(255,vP[3x+1]+sValue)
    else
    vP[3x+1]:=Max(0,vP[3x+1]-sValue);
    //B //蓝色分量大于阈值的时候
    if vP[3x]>vThresholdValue then
    vP[3
    x]:=Min(255,vP[3x]+sValue)
    else
    vP[3
    x]:=Max(0,vP[3*x]-sValue);
    end;
    end;
    Image2.Picture.Assign(vBmp);
    vBmp.Free;
    end;

    end.

    -----unit结束

    -------Form开始
    object Form1: TForm1
    Left = 364
    Top = 187
    BorderStyle = bsDialog
    Caption = 'Form1'
    ClientHeight = 485
    ClientWidth = 886
    Color = clBtnFace
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    OldCreateOrder = False
    OnCreate = FormCreate
    PixelsPerInch = 96
    TextHeight = 13
    object Image1: TImage
    Left = 8
    Top = 16
    Width = 425
    Height = 337
    Center = True
    Proportional = True
    Stretch = True
    end
    object Image2: TImage
    Left = 448
    Top = 16
    Width = 425
    Height = 337
    Center = True
    Proportional = True
    Stretch = True
    end
    object Label1: TLabel
    Left = 16
    Top = 360
    Width = 385
    Height = 25
    AutoSize = False
    Caption = '图片宽x高:'
    end
    object Label2: TLabel
    Left = 272
    Top = 424
    Width = 297
    Height = 25
    Alignment = taCenter
    AutoSize = False
    end
    object Button1: TButton
    Left = 16
    Top = 416
    Width = 161
    Height = 25
    Caption = 'Button1_加载图片'
    TabOrder = 0
    OnClick = Button1Click
    end
    object TrackBar1: TTrackBar
    Left = 8
    Top = 448
    Width = 873
    Height = 33
    Max = 127
    TabOrder = 1
    OnChange = TrackBar1Change
    end
    object OpenPictureDialog1: TOpenPictureDialog
    Filter = 'Bitmaps (.bmp)|.bmp'
    Left = 72
    Top = 368
    end
    end

    ------Form结束

  • 相关阅读:
    视觉里程计VO-直接法
    Linux安装libcholmod-dev找不到的解决方法
    Levenberg-Marquadt Method
    Gauss-Newton Method
    CMake
    方差 标准差 协方差
    SFM
    矩阵分解
    kvm学习笔记
    python学习笔记
  • 原文地址:https://www.cnblogs.com/dmqhjp/p/15146288.html
Copyright © 2020-2023  润新知