当前位置: 首页 > news >正文

高端网站建设域名注册网站开发课设心得

高端网站建设域名注册,网站开发课设心得,龙华做棋牌网站建设多少钱,怎么做pp网站#xff08;1#xff09;创建一个名为SplitImage的窗体的应用程序#xff0c;将窗体改名为FormSplitImage。 #xff08;2#xff09;创建一个名为ImageProcessingLibrary的类库程序#xff0c;为该工程添加名为ImageProcessing的静态类 #xff08;3#xff09;为Imag…1创建一个名为SplitImage的窗体的应用程序将窗体改名为FormSplitImage。 2创建一个名为ImageProcessingLibrary的类库程序为该工程添加名为ImageProcessing的静态类 3为ImageProcessing类添加统计直方图的静态函数 4在ImageProcessing类中添加二值化处理函数BinaryImage 5在SplitImage工程中引用ImageProcessingLibrary工程并添加ImageProcessingLibrary, System.Drawing命名空间。 6在窗体中重写OnPaint事件函数并在函数中添加绘制原始图像、显示直方图和图像分割与提取后的图像 程序框架 : 被窗体的应用程序引用的类库代码: using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks;namespace ImageProcessingLibrary {public static class ImageProcessing{/// 获取直方图数组并绘制直方图/// param nameimage需要处理的图像/param/// param nameindexColor处理的颜色索引值Blue0Green1Red2/param/// param namehistogram直方图统计数组/param/// returns绘制好的直方图/returnspublic static Bitmap GetHistogram(Bitmap image, int indexColor, out int[] histogram){histogram new int[256]; //直方图统计数组BitmapData data image.LockBits(new Rectangle(new Point(), image.Size),ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); //将图像锁定到内存中byte[] datas new byte[data.Stride * image.Height]; //图像数组Marshal.Copy(data.Scan0, datas, 0, datas.Length); //将图像在内存中的数据复制到图像数组中for (int y 0; y image.Height * data.Stride; y data.Stride) //data.Stride代表图像一行数据的字节总数/步长为data.Stride{//外层循环是遍历行for (int x 0; x image.Width * 3; x 3)//遍历当前行中的每个像素/每个像素由三个字节RGB组成//每个颜色分量红色、绿色或蓝色可以有的不同强度级别就是2^8即256个级别{int index y x; //颜色在内存中的索引/每个索引偏移量3字节(对应R,G,B)histogram[datas[index indexColor]];//增加直方图中对应颜色分量出现的次数}}image.UnlockBits(data);byte maxValue 0; //直方图中的最大值for (int value 1; value 256; value){if (histogram[value] histogram[maxValue]) maxValue (byte)value;}Bitmap imageHistogram new Bitmap(256, 256);Graphics GHistogram Graphics.FromImage(imageHistogram);GHistogram.Clear(Color.Blue);for (int value 1; value 256; value){int length byte.MaxValue * histogram[value] / histogram[maxValue];GHistogram.DrawLine(new Pen(Color.FromArgb(value, value, value), 1f), value,256, value, 256 - length); //绘制直方图}Font font new Font(宋体, 9f);//绘制统计标识for (int value 32; value 256; value 32){int count histogram[maxValue] / 8 * value / 32;Pen pen new Pen(Color.Lime);pen.DashStyle DashStyle.DashDot;SizeF sizeCount GHistogram.MeasureString(count.ToString(), font);GHistogram.DrawLine(pen, 0, 255 - value, 255, 255 - value);//绘制数量等级线GHistogram.DrawString(count.ToString(), font, Brushes.Red, 5, 255 - value - sizeCount.Height / 2);SizeF sizeValue GHistogram.MeasureString(value.ToString(), font);GHistogram.DrawLine(Pens.Red, value, 250, value, 255);//绘制颜色值等级线GHistogram.DrawString(value.ToString(), font, Brushes.Red, value - sizeValue.Width / 2, 240);}font.Dispose();return imageHistogram;}/// 将图像进行二值化处理/// param nameimage需要处理的图像/param/// param nameindexColor处理的颜色索引值Blue0Green1Red2/param/// param namethresholdMin阈值下限/param/// param namethresholdMax阈值上限/parampublic static void BinaryImage(Bitmap image, int indexColor, int thresholdMin, int thresholdMax){//将图像锁定到内存中BitmapData data image.LockBits(new Rectangle(new Point(), image.Size), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);byte[] datas new byte[data.Stride * image.Height]; //图像数组Marshal.Copy(data.Scan0, datas, 0, datas.Length); //将图像在内存中的数据复制到图像数组中for (int y 0; y image.Height * data.Stride; y data.Stride){for (int x 0; x image.Width * 3; x 3){int index y x;//根据阈值将图像分成黑色和白色其中阈值内的为黑色阈值外的为白色if (datas[index indexColor] thresholdMin datas[index indexColor] thresholdMax)datas[index] datas[index 1] datas[index 2] 0;elsedatas[index] datas[index 1] datas[index 2] 255;}}Marshal.Copy(datas, 0, data.Scan0, datas.Length); //将图像数组复制到内存中image.UnlockBits(data); //将图像从内存中解锁}}} /*假设颜色分量是8位的那么每个颜色分量红色、绿色或蓝色可以有的不同强度级别就是2^8即256个级别。* 这是因为8位可以表示从0到255的整数总共256个不同的数值。在数字图像处理中8位颜色深度是常见的* 因为它提供了足够的动态范围来表示大多数自然和人工颜色的细微差别同时保持数据量相对较小。当你说“直方图大小为256”时你指的是直方图的横坐标即颜色强度的可能值有256个不同的条目 每个条目对应一个特定的颜色强度值从0到255。直方图的纵坐标通常表示该颜色强度值在图像中出现的频率或像素数量。因此如果我们想为8位颜色分量的图像构建直方图我们将创建一个大小为256的数组数组的每个元素初始化为0。 然后我们遍历图像的每个像素对于每个像素的特定颜色分量如红色、绿色或蓝色我们增加直方图中对应颜色强度值的计数。 这个过程最终会给我们一个表示图像中每个颜色强度出现频率的直方图。*/ 窗体的应用程序,重写OnPaint事件函数代码: using ImageProcessingLibrary; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace SplitImage {public partial class FormSplitImage : Form{public FormSplitImage(){InitializeComponent();}protected override void OnPaint(PaintEventArgs e)//重写OnPaint事件函数{Graphics G e.Graphics;Bitmap image new Bitmap(123456.jpg); //加载图像Rectangle rectImage new Rectangle(new Point(), image.Size);G.DrawImage(image, rectImage); //绘制原始图像int[] histogram; //直方图统计数组Rectangle rectHistogram new Rectangle(rectImage.Width, 0, 256, 256); //获取图像的灰度直方图(起始点X,Y,像素大小x,y)Bitmap imageHistogram ImageProcessing.GetHistogram(image, 0, out histogram);//这里out返回了直方图数组histogramG.DrawImage(imageHistogram, rectHistogram); //绘制直方图rectImage.Offset(0, image.Height);//矩形位置调整指定的量,即往下(y)移一个图片高度,定义了绘制分割后的图像的rectImageImageProcessing.BinaryImage(image, 1, 0, 150); //通过二值化将目标分割出来()G.DrawImage(image, rectImage); //绘制分割后的图像image.Dispose(); //释放图像imageHistogram.Dispose(); //释放直方图图像}} }在程序路径下准备图片:123456.jpg  运行SplitImage窗体的应用程序:
http://www.w-s-a.com/news/374144/

相关文章:

  • 厦门国外网站建设公司郑州核酸点推vip服务
  • 免费网线seo外链怎么做
  • 宽带技术网网站wordpress widget hook
  • 山西省住房和城乡建设厅网站报名wordpress添加标签插件
  • 网站怎么自己做外贸网站案例
  • 做网站的优势公司网站怎么做站外链接
  • 海城网站制作建设精准营销的营销方式
  • 北京短视频拍摄公司重庆网站seo推广公司
  • 广州免费推广网站建设4399网页游戏大全
  • 网站的构架与组成建站公司兴田德润
  • php网站部署步骤邯郸哪有做网站的
  • 做设计什么设计比较好的网站南充市住房和城乡建设局考试网站
  • 郑州做系统集成的公司网站龙岩
  • 厦门SEO_厦门网站建设网络营销课程视频
  • vs 2015 网站开发开网店在线咨询
  • 前端如何优化网站性能大学学校类网站设计
  • 中国铁路建设投资公司网站熊学军中国it外包公司排名前50
  • 房产网站的建设广州推广排名
  • 湟源县网站建设wordpress删除未分类
  • 营销型网站开发推广厦门百度seo公司
  • 遵义网站开发培训上海中高风险地区名单最新
  • 禹州市门户网站建设做网站可以申请个体户么
  • 大良营销网站建设效果彩票网站搭建 做网站
  • 做网站的公司为什么人少了在中国如何推广外贸平台
  • 盘锦网站制作工业电商网站怎么配色
  • 白云企业网站建设seo排名点击软件
  • wordpress跨站脚本攻击漏洞国外注册的域名国内能用吗
  • 西部数码网站管理助手2工信部资质查询网站
  • 公司网站哪个建的好吉林网站制作
  • 视频网站怎么引流wordpress私人玩物