C#图像颜色聚类高效方法实例
作者:沧海一粟…… 时间:2021-09-29 09:14:41
本文实例讲述了C#图像颜色聚类高效方法。分享给大家供大家参考。具体分析如下:
图像颜色聚类的方法有很多,但是对于视频监控而言,现有方法很难满足实时性的要求,这里介绍一种位屏蔽压缩的方法实现颜色聚类,可以满足实时性的要求。
位屏蔽法就是在3D的RGB真彩空间中近似均匀采样的颜色压缩方法,即将屏蔽的颜色位置设置为0,具体可以采用移位运算来实现,这里我们以屏蔽RGB颜色分量末6位为例:
public Bitmap PCluster(Bitmap a)
{
try
{
Rectangle rect = new Rectangle(0, 0, a.Width, a.Height);
System.Drawing.Imaging.BitmapData bmpData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
int stride = bmpData.Stride;
unsafe
{
byte* pIn = (byte*)bmpData.Scan0.ToPointer();
byte* P;
int R, G, B;
for (int y = 0; y < a.Height; y++)
{
for (int x = 0; x < a.Width; x++)
{
P = pIn;
B = P[0];
G = P[1];
R = P[2];
P[0] = (byte)(B & 192); //屏蔽末6位
P[1] = (byte)(G & 192);
P[2] = (byte)(R & 192);
pIn += 3;
}
pIn += stride - a.Width * 3;
}
}
a.UnlockBits(bmpData);
return a;
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
return null;
}
}
原图:
效果图:
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,图像
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
c# 线程定时器 System.Threading.Timer的使用
2022-07-08 01:28:09
![](https://img.aspxhome.com/file/2023/0/92890_0s.png)
使用Spring的拦截器监测每个Controller或方法的执行时长
2021-12-19 16:36:01
一篇文章弄懂Spring MVC的参数绑定
2023-09-17 01:01:21
![](https://img.aspxhome.com/file/2023/8/104038_0s.jpg)
Android listview的滑动冲突解决方法
2022-07-19 02:50:59
Java反射 Field类的使用全方位解析
2022-09-01 13:22:45
深入了解Spring中最常用的11个扩展点
2023-07-05 17:46:40
![](https://img.aspxhome.com/file/2023/1/57531_0s.png)
Android开发获取重力加速度和磁场强度的方法
2022-05-27 23:07:09
![](https://img.aspxhome.com/file/2023/2/106022_0s.png)
Android实现界面跳转功能
2022-05-07 21:51:32
![](https://img.aspxhome.com/file/2023/9/96769_0s.jpg)
Spring Boot多个定时任务阻塞问题的解决方法
2023-09-20 11:43:36
Python调用Java可执行jar包问题
2021-06-02 10:26:26
![](https://img.aspxhome.com/file/2023/9/102899_0s.png)
在Maven下代理服务器设定的方式
2023-10-15 02:17:13
![](https://img.aspxhome.com/file/2023/9/58569_0s.png)
C# 网络编程之UDP
2021-10-02 16:06:40
Androd 勇闯高阶性能优化之布局优化篇
2023-01-22 12:12:15
![](https://img.aspxhome.com/file/2023/8/87278_0s.png)
Java实现堆排序和图解
2023-11-11 12:13:37
![](https://img.aspxhome.com/file/2023/6/59336_0s.png)
SpringBoot实现Mysql使用MD5进行密码加密的示例
2022-11-24 23:14:16
![](https://img.aspxhome.com/file/2023/6/62156_0s.png)
SpringBoot动态修改日志级别的操作
2022-10-31 05:00:30
![](https://img.aspxhome.com/file/2023/6/67116_0s.png)
Android应用APP自动更新功能的代码实现
2022-09-17 09:48:25
![](https://img.aspxhome.com/file/2023/0/87290_0s.jpg)
Java中的强引用,软引用,弱引用,虚引用的作用介绍
2023-08-27 11:03:28
![](https://img.aspxhome.com/file/2023/1/58411_0s.png)
基于struts2和hibernate实现登录和注册功能
2022-03-23 00:27:43
![](https://img.aspxhome.com/file/2023/4/70984_0s.jpg)
SpringMVC的执行流程及组件详解
2021-06-17 23:29:21