将中值滤镜应用于指纹图像 [英] Apply median filter to fingerprint image

查看:57
本文介绍了将中值滤镜应用于指纹图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿朋友请帮我编码中值滤波器,使用指针从指纹图像中去除噪音。我做了这么多......



Hey friends please help me in coding median filter to remove noise from the fingerprint image using pointers. I have done this much...

byte* imgPtr = (byte*)(void*)(data.Scan0);
               byte* src = (byte*)(void*)(data.Scan0);
               int sOffset = stride - 9;
               int nOffset = stride - image.Width * 3;
               int i,j,v = 0,h=0;
               for ( i = 0; i < image.Width; i++)
               {
                   for ( j = 1; j < image.Height; j++)
                   {
                       imgPtr = src;
                       for(x=0;x<3;x++)
                       {
                           for (y = 0; y <3; y++)
                           {
                               red[x, y] = imgPtr[0];
                               r1[h] = imgPtr[0];
                               green[x, y] = imgPtr[1];
                               g1[h] = imgPtr[1];
                               blue[x, y] = imgPtr[2];
                               b1[h] = imgPtr[2];
                               imgPtr += 3;
                               h++;
                           }
                           imgPtr += sOffset;
                       }
                       src += 3;
                               Array.Sort(r1);
                               r[v] = r1[4];
                               Array.Sort(g1);
                                 g[v] = g1[4];
                               Array.Sort(b1);
                               b[v] = b1[4];
                               //MPtr += 3;
                               v++;

推荐答案

使用中位数滤波器在C#中降噪图片

Noise Reduction of an Image in C# using Median Filters
One of the main issues when trying to do image processing is the simple fact that images usually contain some degree of noise. This noise can in turn cause issues. For instance if you're doing edge detection, a spot on the image may cause the algorithm to detect edges that it shouldn't. One of the easiest ways to fix this issue is to use a median filter on an image. Unlike box blurs and gaussian blurs, we're not looking for the average of the pixels. In the case of a median filter, we're looking for the median (sort the values, take the one in the middle). We're still looking at a set of pixels around each pixel but we're simply taking the median instead of the mean.  The advantage of this approach is that it keeps the edges of an image but simply degrades the details a bit, unlike a box blur which will slowly bleed the edges.
Unfortunately in C# there is no built in function to do this (or at least none that I'm aware of) and as such I wrote code to accomplish it and as always I'm sharing it with you:




1: public static Bitmap MedianFilter(Bitmap Image, int Size)
  2: {
  3:     System.Drawing.Bitmap TempBitmap = Image;
  4:     System.Drawing.Bitmap NewBitmap = new System.Drawing.Bitmap(TempBitmap.Width, TempBitmap.Height);
  5:     System.Drawing.Graphics NewGraphics = System.Drawing.Graphics.FromImage(NewBitmap);
  6:     NewGraphics.DrawImage(TempBitmap, new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), System.Drawing.GraphicsUnit.Pixel);
  7:     NewGraphics.Dispose();
  8:     Random TempRandom = new Random();
  9:     int ApetureMin = -(Size / 2);
 10:     int ApetureMax = (Size / 2);
 11:     for (int x = 0; x < NewBitmap.Width; ++x)

 12:     {

 13:         for (int y = 0; y < NewBitmap.Height; ++y)

 14:         {

 15:             List<int> RValues = new List<int>();
 16:             List<int> GValues = new List<int>();
 17:             List<int> BValues = new List<int>();
 18:             for (int x2 = ApetureMin; x2 < ApetureMax; ++x2)

 19:             {

 20:                 int TempX = x + x2;

 21:                 if (TempX >= 0 && TempX < NewBitmap.Width)

 22:                 {

 23:                     for (int y2 = ApetureMin; y2 < ApetureMax; ++y2)

 24:                     {

 25:                         int TempY = y + y2;

 26:                         if (TempY >= 0 && TempY < NewBitmap.Height)

 27:                         {

 28:                             Color TempColor = TempBitmap.GetPixel(TempX, TempY);

 29:                             RValues.Add(TempColor.R);

 30:                             GValues.Add(TempColor.G);

 31:                             BValues.Add(TempColor.B);

 32:                         }

 33:                     }

 34:                 }

 35:             }

 36:             RValues.Sort();

 37:             GValues.Sort();

 38:             BValues.Sort();

 39:             Color MedianPixel = Color.FromArgb(RValues[RValues.Count / 2],

 40:                 GValues[GValues.Count / 2],

 41:                 BValues[BValues.Count / 2]);

 42:             NewBitmap.SetPixel(x, y, MedianPixel);

 43:         }

 44:     }

 45:     return NewBitmap;

 46: }


这篇关于将中值滤镜应用于指纹图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆