<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                水彩畫濾鏡 水彩畫濾鏡算法如下: 1,假設原始圖像為F(x,y),灰度化得到G(x,y); 2,構建一個半徑為Radius的正方形模板M,邊長為2*Radius+1; 3,將M在F上依次遍歷每個像素,對于當前像素P(x,y): 設置一個油漆桶數N,由于圖像灰度值范圍為0-255,因此我們油漆桶的數量N要小于255,這個油漆桶是用來盛放不同類別的像素。 3.1首先按照油漆桶數N將0-255的范圍劃分為等距的N個油漆桶,對于模板中對應的像素,我們按照其灰度值,依次將其放入相應的油漆桶中; 3.2統計N個油漆桶中的像素數目,計算像素數最多的那個油漆桶內,像素的均值Mean,這個均值RGB就是模板中心像素P(x,y)的值。 示意圖如下: [![](https://box.kancloud.cn/2016-01-05_568b3324d3a94.jpg)](http://www.zealpixel.com/data/attachment/portal/201507/25/125919y9s6p02da0y6m3p3.jpg) ? ? ? ? ? ? ? ? ? ? ? ? ? ?Fig.1?油畫濾鏡示意圖(N=8) 注意:油漆桶數N可以調節圖像平滑度,模板半徑Radius用來調節水彩畫的水彩程度。 上述算法在進行模板遍歷時,可以采用快速均值濾波算法的方法來提高效率。 代碼如下: ~~~ private Bitmap OilpaintFilterProcess(Bitmap srcBitmap, int radius, int smooth) { if (radius == 0) return srcBitmap; smooth = smooth < 1 ? 1 : smooth; smooth = Math.Max(1, smooth); Bitmap a = new Bitmap(srcBitmap); int w = srcBitmap.Width; int h = srcBitmap.Height; if (radius > Math.Min(w, h) / 2) radius = (int)(Math.Min(w, h) / 2 - 0.5); System.Drawing.Imaging.BitmapData srcData = a.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); IntPtr ptr = srcData.Scan0; int bytes = h * srcData.Stride; byte[] srcValues = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(ptr, srcValues, 0, bytes); byte[] tempValues = (byte[])srcValues.Clone(); int stride = srcData.Stride; int i, j, k; int unit = 4; int[] gray_bt = new int[smooth]; int[] r_bt = new int[smooth]; int[] g_bt = new int[smooth]; int[] b_bt = new int[smooth]; int[] gray_bt_src = new int[smooth]; int[] r_bt_src = new int[smooth]; int[] g_bt_src = new int[smooth]; int[] b_bt_src = new int[smooth]; int r, g, b; int gray = 0, bt_index = 0, max = 0, maxindex = 0; i = 0; bool frist = true; int pos = 0; for (j = 0; j < h; j++) { if (frist) { for (int m = -radius; m <= radius; m++) { for (int n = -radius; n <= radius; n++) { pos = Math.Abs(n) * unit + Math.Abs(m) * stride; b = srcValues[pos++]; g = srcValues[pos++]; r = srcValues[pos]; gray = (b + g + r) / 3; bt_index = gray * smooth >> 8; gray_bt_src[bt_index]++; b_bt_src[bt_index] += b; g_bt_src[bt_index] += g; r_bt_src[bt_index] += r; } } Array.Copy(gray_bt_src, gray_bt, smooth); Array.Copy(b_bt_src, b_bt, smooth); Array.Copy(g_bt_src, g_bt, smooth); Array.Copy(r_bt_src, r_bt, smooth); max = 0; maxindex = 0; for (k = 0; k < smooth; k++) { if (max < gray_bt[k]) { max = gray_bt[k]; maxindex = k; } } pos = j * stride; tempValues[pos++] = (byte)(b_bt[maxindex] / max); tempValues[pos++] = (byte)(g_bt[maxindex] / max); tempValues[pos] = (byte)(r_bt[maxindex] / max); frist = false; } else { for (int m = -radius; m <= radius; m++) { pos = Math.Abs(m) * unit + Math.Abs(j - radius - 1) * stride; b = srcValues[pos++]; g = srcValues[pos++]; r = srcValues[pos]; gray = (b + g + r) / 3; bt_index = gray * smooth >> 8; gray_bt_src[bt_index]--; b_bt_src[bt_index] -= b; g_bt_src[bt_index] -= g; r_bt_src[bt_index] -= r; pos = Math.Abs(m) * unit + Math.Abs(j + radius) % h * stride; b = srcValues[pos++]; g = srcValues[pos++]; r = srcValues[pos]; gray = (b + g + r) / 3; bt_index = gray * smooth >> 8; gray_bt_src[bt_index]++; b_bt_src[bt_index] += b; g_bt_src[bt_index] += g; r_bt_src[bt_index] += r; } Array.Copy(gray_bt_src, gray_bt, smooth); Array.Copy(b_bt_src, b_bt, smooth); Array.Copy(g_bt_src, g_bt, smooth); Array.Copy(r_bt_src, r_bt, smooth); } for (i = 1; i < w; i++) { for (int m = -radius; m <= radius; m++) { pos = Math.Abs(i - radius - 1) * unit + Math.Abs(j + m) % h * stride; b = srcValues[pos++]; g = srcValues[pos++]; r = srcValues[pos]; gray = (b + g + r) / 3; bt_index = gray * smooth >> 8; gray_bt[bt_index]--; b_bt[bt_index] -= b; g_bt[bt_index] -= g; r_bt[bt_index] -= r; pos = Math.Abs(i + radius) % w * unit + Math.Abs(j + m) % h * stride; b = srcValues[pos++]; g = srcValues[pos++]; r = srcValues[pos]; gray = (b + g + r) / 3; bt_index = gray * smooth >> 8; gray_bt[bt_index]++; b_bt[bt_index] += b; g_bt[bt_index] += g; r_bt[bt_index] += r; } max = 0; maxindex = 0; for (k = 0; k < smooth; k++) { if (max < gray_bt[k]) { max = gray_bt[k]; maxindex = k; } } pos = i * unit + j * stride; tempValues[pos++] = (byte)(b_bt[maxindex] / max); tempValues[pos++] = (byte)(g_bt[maxindex] / max); tempValues[pos] = (byte)(r_bt[maxindex] / max); } } srcValues = (byte[])tempValues.Clone(); System.Runtime.InteropServices.Marshal.Copy(srcValues, 0, ptr, bytes); a.UnlockBits(srcData); return a; } ~~~ 效果圖如下: [![](https://box.kancloud.cn/2016-01-05_568b33241586c.jpg)](http://www.zealpixel.com/data/attachment/portal/201507/25/130152shnhd3ranthdr4wz.jpg) 原圖 [![](https://box.kancloud.cn/2016-01-05_568b3324eba0d.png)](http://www.zealpixel.com/data/attachment/portal/201507/25/130151xeuqbue4ggj68e4c.png) 水彩畫濾鏡效果圖 最后,放上一個完整的C#版程序DEMO下載地址:http://www.zealpixel.com/thread-61-1-1.html
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看