映像濾鏡藝術---Oilpaint油畫濾鏡,---oilpaint油畫

來源:互聯網
上載者:User

映像濾鏡藝術---Oilpaint油畫濾鏡,---oilpaint油畫
 Oilpaint油畫濾鏡    映像油畫效果實際上是將映像邊緣產生一種朦朧,霧化的效果,同時,將一定的邊緣模糊化,這樣映像整體上看去像素與像素之間就像霧一樣隨機呈現。 演算法過程如下: 假設當前像素為P(x,y),他的隨機位置為Pd(dx,dy),那麼演算法公式如下:

 其中,K(v)為最大值不大於v的隨機數正數,v為霧化閾值,v值越大,霧化程度越明顯,反之,霧化程度越小,v=0時,映像無變化效果。

 核心代碼如下:

        /// <summary>

        /// Mosaic filter.

        /// </summary>

        /// <param name="src">Source  image.</param>

        /// <param name="blockSize">The size of mosaic effect.</param>

        /// <returns>Resullt image.</returns>

        public Bitmap OilpaintFilter(Bitmap src, int intensity)

        {

            Bitmap srcBitmap = new Bitmap(src);

            int w = srcBitmap.Width;

            int h = srcBitmap.Height;

            System.Drawing.Imaging.BitmapData srcData = srcBitmap.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;

            Random ran = new Random();

            int k = 0;

            int dx = 0;

            int dy = 0;

            for (int j = 0; j < h; j++)

            {

                for (int i = 0; i < w; i++)

                {

                    k = ran.Next(intensity);

                    dx = (i + k) >= w ? w - 1 : (i + k);

                    dy = (j + k) >= h ? h - 1 : (j + k);

                    tempValues[i * 4 + j * w * 4] = (byte)srcValues[dx * 4 + dy * w * 4];

                    tempValues[i * 4 + 1 + j * w * 4] = (byte)srcValues[dx * 4 + 1 + dy * w * 4];

                    tempValues[i * 4 + 2 + j * w * 4] = (byte)srcValues[dx * 4 + 2 + dy * w * 4];

                }

            }

            srcValues = (byte[])tempValues.Clone();

            System.Runtime.InteropServices.Marshal.Copy(srcValues, 0, ptr, bytes);

            srcBitmap.UnlockBits(srcData);

            return srcBitmap;

        }

 映像油畫濾鏡效果如下:

原圖

Oilpaint濾鏡效果

最後,放上一個完整的C#版程式Demo下載連結:http://www.zealpixel.com/forum.php?mod=viewthread&tid=52&extra=page%3D1

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.