原文:Win8 Metro(C#)数字图像处理--2.43图像马赛克效果算法



[函数名称]

图像马赛克效果        MosaicProcess(WriteableBitmap src, int v)

[算法说明]

图像马赛克效果其实就是将图像分成大小一致的图像块,每一个图像块都是一个正方形,并且在这个正方形中所有像素值都相等。我们可以将这个正方形看作是一个模板窗口,模板中对应的所有图像像素值都等于该模板的左上角第一个像素的像素值,这样的效果就是马赛克效果,而正方形模板的大小则决定了马赛克块的大小,即图像马赛克化的程度。

[函数代码]

<strong>       /// <summary>
/// Mosaic process.
/// </summary>
/// <param name="src">The source image.</param>
/// <param name="v">The threshould to control the result of mosaic process.</param>
/// <returns></returns>
public static WriteableBitmap MosaicProcess(WriteableBitmap src, int v)////图像马赛克效果
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap srcImage = new WriteableBitmap(w, h);
byte[] temp = src.PixelBuffer.ToArray();
byte[] tempMask = (byte[])temp.Clone();
int dR = 0;
int dG = 0;
int dB = 0;
int dstX = 0;
int dstY=0;
dR = tempMask[2];
dG = tempMask[1];
dB = tempMask[0];
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
dstX = i;
dstY = j;
if (j % v == 0)
{
if (i % v == 0)
{
dB = tempMask[dstX * 4 + dstY * w * 4];
dG = tempMask[dstX * 4 + 1 + dstY * w * 4];
dR = tempMask[dstX * 4 + 2 + dstY * w * 4];
}
else
{
temp[dstX * 4 + dstY * w * 4] = (byte)dB;
temp[dstX * 4 + 1 + dstY * w * 4] = (byte)dG;
temp[dstX * 4 + 2 + dstY * w * 4] = (byte)dR;
}
}
else
{
temp[dstX * 4 + dstY * w * 4] = temp[dstX * 4 + (dstY - 1) * w * 4];
temp[dstX * 4 + 1 + dstY * w * 4] = temp[dstX * 4 + 1 + (dstY - 1) * w * 4];
temp[dstX * 4 + 2 + dstY * w * 4] = temp[dstX * 4 + 2 + (dstY - 1) * w * 4];
}
}
}
Stream sTemp = srcImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return srcImage;
}
else
{
return null;
}
}</strong>

[图像效果]

Win8 Metro(C#)数字图像处理--2.43图像马赛克效果算法的更多相关文章

  1. Win8 Metro(C#)数字图像处理--2.44图像油画效果算法

    原文:Win8 Metro(C#)数字图像处理--2.44图像油画效果算法  [函数名称]   图像油画效果      OilpaintingProcess(WriteableBitmap src ...

  2. Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法

    原文:Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法  [函数名称]   高斯平滑滤波器      GaussFilter(WriteableBitmap src,int r ...

  3. Win8 Metro(C#)数字图像处理--2.51图像统计滤波算法

    原文:Win8 Metro(C#)数字图像处理--2.51图像统计滤波算法  [函数名称]   图像统计滤波   WriteableBitmap StatisticalFilter(Writeab ...

  4. Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法

    原文:Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法  [函数名称] 肤色检测函数SkinDetectProcess(WriteableBitmap src) [算法说明] ...

  5. Win8 Metro(C#)数字图像处理--3.2图像方差计算

    原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...

  6. Win8 Metro(C#)数字图像处理--3.3图像直方图计算

    原文:Win8 Metro(C#)数字图像处理--3.3图像直方图计算 /// <summary> /// Get the array of histrgram. /// </sum ...

  7. Win8 Metro(C#)数字图像处理--3.4图像信息熵计算

    原文:Win8 Metro(C#)数字图像处理--3.4图像信息熵计算 [函数代码] /// <summary> /// Entropy of one image. /// </su ...

  8. Win8 Metro(C#)数字图像处理--3.5图像形心计算

    原文:Win8 Metro(C#)数字图像处理--3.5图像形心计算 /// <summary> /// Get the center of the object in an image. ...

  9. Win8 Metro(C#)数字图像处理--3.1图像均值计算

    原文:Win8 Metro(C#)数字图像处理--3.1图像均值计算 /// <summary> /// Mean value computing. /// </summary> ...

随机推荐

  1. 下载的pod链接失效,build diff: /../Podfile.lock: No such file or directory解决办法

    build diff: /../Podfile.lock: No such file or directory 1.终端进入文件路径,执行pod install 2.在工程设置中的Build Phas ...

  2. 【u239】整数分解

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 某些数能表示成为一些互不相同的整数的阶乘之和.如9=l!+2! +3!. 现在给定一个非负整数n,要求 ...

  3. 【a601】雇佣计划

    Time Limit: 1 second Memory Limit: 32 MB [问题描述] 一位管理项目的经理想要确定每个月需要的工人,他知道每月所需的最少工人数.当他雇佣或解雇一个工人时,会有一 ...

  4. 小强的HTML5移动开发之路(22)—— Adobe DreamWeaver CS6安装与破解

    首先说明一下,这里介绍Adobe DreamWeaver CS6的安装与破解是为了后面的jQuery Mobile框架使用做好准备. 一.首先去Adobe官网下载:http://www.adobe.c ...

  5. jQuery实现复选框的全选、反选、并且根据复选框的<checked属性>控制多个对应div的显示/隐藏

    <!doctype html><html> <head> <meta charset="utf-8"> <title>j ...

  6. 一个自己犯的react错误

    在看<react小书>高阶组件一节的时候,看到如下代码 import React, { Component } from 'react' export default (WrappedCo ...

  7. 多线程中的lock,Monitor.Wait和Monitor.Pulse

    我们知道lock实际上一个语法糖糖,C#编译器实际上把他展开为Monitor.Enter和Monitor.Exit,即: lock(lockObj) { //... } ////相当于(.Net4以前 ...

  8. wxWindows

    用C++编写跨平台程序 中文版说明 本教程由Gxl117翻译并将继续维护,这是本教程的第一稿,假设发现错误请与我(Email:gxl117@yahoo.com.cn)联系让我能及时修正它.之后还会对这 ...

  9. Apache Cordova开发环境搭建(二)VS Code

    原文:Apache Cordova开发环境搭建(二)VS Code 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u011127019/articl ...

  10. 实用的 Matlab

    activecontour:前景背景分离,Segment image into foreground and background using active contour 该函数返回的是一副 bin ...