<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      WPF 通過(guò) WriteableBitmap 實(shí)現(xiàn) TAGC 低光增強(qiáng)效果算法

      開(kāi)始之前,必須感謝 只(摯)愛(ài)圖像處理 - Imageshop 大佬的分享。本文將參閱 伊拉克團(tuán)隊(duì)的TAGC(低光增強(qiáng)效果)算法實(shí)現(xiàn)。 - Imageshop - 博客園 進(jìn)行實(shí)現(xiàn)

      原論文信息如下:

      論文標(biāo)題: Tuning adaptive gamma correction (TAGC) for enhancing images in low light

      發(fā)表日期: 2025年07月

      作者: Ghufran Alhamzawi, Alfoudi Ali Saeed, Suha Mohammed Hadi等

      發(fā)表單位: University of Al-Qadisiyah, University of Information Technology and Communications等

      原文鏈接: http://arxiv.org/pdf/2507.19574v1

      實(shí)現(xiàn)效果如下圖所示

      這個(gè)過(guò)程無(wú)需玄學(xué)算法參與,無(wú)需對(duì)接任何 AI 相關(guān)的算法,僅僅只是非常簡(jiǎn)單的逐個(gè)像素進(jìn)行數(shù)學(xué)計(jì)算。核心實(shí)現(xiàn)代碼如下

      /// <summary>
      /// Tuning adaptive gamma correction (TAGC) 低光增強(qiáng)效果算法
      /// </summary>
      public class TuningAdaptiveGammaCorrectionAlgorithm
      {
          public static unsafe void Enhancement(WriteableBitmap sourceBitmap, WriteableBitmap targetBitmap)
          {
              if (sourceBitmap.Format != targetBitmap.Format)
              {
                  return;
              }
      
              if (sourceBitmap.Format != PixelFormats.Bgra32)
              {
                  return;
              }
      
              float inv255 = 1.0f / 255;
      
              sourceBitmap.Lock();
              targetBitmap.Lock();
      
              byte* src = (byte*)sourceBitmap.BackBuffer;
              byte* dest = (byte*)targetBitmap.BackBuffer;
      
              var height = sourceBitmap.PixelHeight;
              var width = sourceBitmap.PixelWidth;
              var stride = sourceBitmap.BackBufferStride;
              int channel = stride / width;
      
              for (int yIndex = 0; yIndex < height; yIndex++)
              {
                  byte* linePixelSource = src + yIndex * stride;
                  byte* linePixelDest = dest + yIndex * stride;
                  for (int xIndex = 0; xIndex < width; xIndex++)
                  {
                      float blue = linePixelSource[0] * inv255;
                      float green = linePixelSource[1] * inv255;
                      float red = linePixelSource[2] * inv255;
                      double l = 0.2126f * red + 0.7152 * green + 0.0722 * blue;
                      float a = (blue + green + red) / 3;
                      double gamma = 5.0f + (0.5f - l) * (1 - a) - 2 * l;
                      double y = 2 / gamma;
      
                      byte tb = ClampToByte((int)(Math.Pow(blue, y) * 255 + 0.4999999f));
                      double y1 = 2 / gamma;
                      byte tg = ClampToByte((int)(Math.Pow(green, y1) * 255 + 0.4999999f));
                      double y2 = 2 / gamma;
                      byte tr = ClampToByte((int)(Math.Pow(red, y2) * 255 + 0.4999999f));
      
                      byte ta = 0xFF;
      
                      linePixelDest[0] = tb;
                      linePixelDest[1] = tg;
                      linePixelDest[2] = tr;
                      linePixelDest[3] = ta;
      
                      linePixelSource += channel;
                      linePixelDest += channel;
                  }
              }
      
              targetBitmap.AddDirtyRect(new Int32Rect(0, 0, targetBitmap.PixelWidth, targetBitmap.PixelHeight));
              sourceBitmap.Unlock();
              targetBitmap.Unlock();
          }
      
          private static byte ClampToByte(int value)
          {
              return (byte)Math.Clamp(value, 0, byte.MaxValue);
          }
      }
      

      具體計(jì)算的原理,如 http://www.rzrgm.cn/Imageshop/p/19025343 博客內(nèi)容所述:

      使用 Tuning adaptive gamma correction (TAGC) 確實(shí)能夠幫我將很多拍攝暗光照片進(jìn)行低光增強(qiáng)。但對(duì)于一些屏幕截圖的效果或其他非拍攝的圖片的處理效果不佳

      整個(gè)算法代碼看起來(lái)也比較清新,代碼量也少,能夠?qū)崿F(xiàn)如此好的效果,也是需要給大佬們點(diǎn)贊。如果大家對(duì)此算法效果感興趣,歡迎按照本文末尾的方法拉取我的代碼跑跑看效果,或直接從 Imageshop 大佬那下載他已經(jīng)構(gòu)建好的程序

      細(xì)心的伙伴也許看到了,在本文的 Enhancement 方法里面需要判斷圖片的格式,但并非所有的圖片都能遵循此格式。好在 WPF 里面可以非常方便地通過(guò) FormatConvertedBitmap 進(jìn)行轉(zhuǎn)換,此轉(zhuǎn)換過(guò)程都是利用 WIC 多媒體進(jìn)行轉(zhuǎn)換,性能非常高,損耗非常低。核心代碼如下

              var formatConvertedBitmap = new FormatConvertedBitmap();
              formatConvertedBitmap.BeginInit();
              formatConvertedBitmap.Source = source;
              formatConvertedBitmap.DestinationFormat = PixelFormats.Bgra32;
              formatConvertedBitmap.EndInit();
      

      使用的時(shí)候直接將 FormatConvertedBitmap 當(dāng)成 BitmapSource 傳遞就可以了。完全的從傳入的圖片文件路徑,經(jīng)過(guò) TAGC 算法,將輸出的 WriteableBitmap 給到 DestImage 控件的 Source 的代碼如下

          private void Enhancement(string filePath)
          {
              if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
              {
                  return;
              }
      
              filePath = Path.GetFullPath(filePath);
      
              var source = new BitmapImage(new Uri(filePath));
              SourceImage.Source = source;
      
              var formatConvertedBitmap = new FormatConvertedBitmap();
              formatConvertedBitmap.BeginInit();
              formatConvertedBitmap.Source = source;
              formatConvertedBitmap.DestinationFormat = PixelFormats.Bgra32;
              formatConvertedBitmap.EndInit();
      
              var sourceBitmap = new WriteableBitmap(formatConvertedBitmap);
              var targetBitmap = new WriteableBitmap(sourceBitmap.PixelWidth, sourceBitmap.PixelHeight, sourceBitmap.DpiX,
                  sourceBitmap.DpiY, sourceBitmap.Format, sourceBitmap.Palette);
      
              TuningAdaptiveGammaCorrectionAlgorithm.Enhancement(sourceBitmap, targetBitmap);
      
              var pngBitmapEncoder = new PngBitmapEncoder();
              pngBitmapEncoder.Frames.Add(BitmapFrame.Create(targetBitmap));
              using var stream = File.Create("1.png");
              pngBitmapEncoder.Save(stream);
      
              DestImage.Source = targetBitmap;
          }
      

      以上的 DestImage 就是 Image 控件,界面代碼定義如下

          <Grid RowDefinitions="Auto,*">
              <Grid>
                  <StackPanel Orientation="Horizontal">
                      <Button x:Name="OpenImageFileButton" Margin="10,10,10,0" Content="打開(kāi)圖片文件" Click="OpenImageFileButton_OnClick"/>
                  </StackPanel>
              </Grid>
              <Grid Grid.Row="1" ColumnDefinitions="*,*">
                  <Image x:Name="SourceImage" Stretch="Fill" Margin="10,10,10,10"/>
                  <Image x:Name="DestImage" Grid.Column="1" Stretch="Fill" Margin="10,10,10,10"/>
              </Grid>
          </Grid>
      

      按鈕點(diǎn)擊打開(kāi)文件,其方法實(shí)現(xiàn)如下

          private void OpenImageFileButton_OnClick(object sender, RoutedEventArgs e)
          {
              var openFileDialog = new OpenFileDialog()
              {
                  Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp;",
                  Multiselect = false,
              };
              openFileDialog.ShowDialog(this);
              var file = openFileDialog.FileName;
              Enhancement(file);
          }
      

      本文代碼放在 githubgitee 上,可以使用如下命令行拉取代碼。我整個(gè)代碼倉(cāng)庫(kù)比較龐大,使用以下命令行可以進(jìn)行部分拉取,拉取速度比較快

      先創(chuàng)建一個(gè)空文件夾,接著使用命令行 cd 命令進(jìn)入此空文件夾,在命令行里面輸入以下代碼,即可獲取到本文的代碼

      git init
      git remote add origin https://gitee.com/lindexi/lindexi_gd.git
      git pull origin 13152fb73b02bc3ec1acaca8c34ee44761fdff2c
      

      以上使用的是國(guó)內(nèi)的 gitee 的源,如果 gitee 不能訪問(wèn),請(qǐng)?zhí)鎿Q為 github 的源。請(qǐng)?jiān)诿钚欣^續(xù)輸入以下代碼,將 gitee 源換成 github 源進(jìn)行拉取代碼。如果依然拉取不到代碼,可以發(fā)郵件向我要代碼

      git remote remove origin
      git remote add origin https://github.com/lindexi/lindexi_gd.git
      git pull origin 13152fb73b02bc3ec1acaca8c34ee44761fdff2c
      

      獲取代碼之后,進(jìn)入 WPFDemo/JoyojabujeaCocherallli 文件夾,即可獲取到源代碼

      更多技術(shù)博客,請(qǐng)參閱 博客導(dǎo)航

      posted @ 2025-09-17 07:30  lindexi  閱讀(288)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 亚洲国产精品综合久久2007| 亚洲天堂激情av在线| 亚洲区综合区小说区激情区| 日产中文字幕在线精品一区| 国产精品天干天干综合网| 亚洲av乱码一区二区| 绝顶丰满少妇av无码| 女人与牲口性恔配视频免费| 精品人妻人人做人人爽| 熟妇的味道hd中文字幕| 免费a级毛片无码av| 亚洲欧美日韩久久一区二区| 中文字幕av日韩有码| 中文字幕有码高清日韩| 亚洲av综合久久成人网| 日韩欧激情一区二区三区| 蜜臀午夜一区二区在线播放| 欧美牲交a免费| 午夜福利国产区在线观看| 国产国产午夜福利视频| 日韩精品一区二区三区中文| 日韩高清砖码一二区在线| 久久99国产精一区二区三区!| 成年女人片免费视频播放A| 国产综合精品91老熟女| 亚洲中文字幕伊人久久无码| 亚洲成在人线在线播放无码| 大地资源网中文第五页| 国产精品一区中文字幕| 日本视频一区二区三区1| 国产一级二级三级毛片| 亚洲aⅴ无码专区在线观看q| 中国帅小伙gaysextubevideo| 亚洲国产亚洲综合在线尤物| 欧美成人午夜精品免费福利| 国产高清视频在线播放www色| 又大又硬又爽免费视频| 高清中文字幕一区二区| 18禁免费无码无遮挡不卡网站 | 亚洲精品日本久久久中文字幕| 国产视频不卡一区二区三区|