在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#图形和图像处理 → 基于MATLAB混合编程图像分析及数据处理

基于MATLAB混合编程图像分析及数据处理

C#图形和图像处理

下载此实例
  • 开发语言:C#
  • 实例大小:1.92KB
  • 下载次数:92
  • 浏览次数:574
  • 发布时间:2016-01-04
  • 实例类别:C#图形和图像处理
  • 发 布 人:清风茶语
  • 文件格式:.sln
  • 所需积分:3

实例介绍

【基于C#语言开发人脸皮肤图像分析软件】

【     
     
        #region  截图方法
        /// <summary> 
        /// 剪裁 -- 用GDI  
        /// </summary> 
        /// <param name="b">原始Bitmap</param> 
        /// <param name="StartX">开始坐标X</param> 
        /// <param name="StartY">开始坐标Y</param> 
        /// <param name="iWidth">宽度</param> 
        /// <param name="iHeight">高度</param> 
        /// <returns>剪裁后的Bitmap</returns> 
        public static Bitmap CutImage(Image b, int StartX, int StartY, int iWidth, int iHeight)
        {
            if (b == null)
            {
                return null;
            }
            int w = b.Width;
            int h = b.Height;
          
            Bitmap bmpOut = null;
            try
            {
                bmpOut = new Bitmap(iWidth, iHeight);
                Graphics g = Graphics.FromImage(bmpOut);
                g.Clear(System.Drawing.Color.Transparent);
                g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
                g.Dispose();
                return bmpOut;
             
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message);
                return null;
            }
            finally
            {
                b.Dispose();
               // bmpOut.Dispose();
            }
        }
        /// <summary> 
        /// 按照指定大小缩放图片,但是为了保证图片宽高比自动截取 
        /// </summary> 
        /// <param name="srcImage"></param> 
        /// <param name="iWidth"></param> 
        /// <param name="iHeight"></param> 
        /// <returns></returns> 
        public static  Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
        {
            Bitmap cutedImage=null;
            try
            {
                int newW = 1000;
                int newH = 1000;
                int newX = 0;
                int newY = 0;
                //取得符合比例的临时文件 
                 cutedImage = CutImage(ImageLocation1, newX, newY, newW, newH);
                // 保存到的文件 
                // Bitmap b = new Bitmap(iWidth, iHeight);
                cutedImage.Save(path3, System.Drawing.Imaging.ImageFormat.Bmp);
             
                return cutedImage;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return null;
            }
            finally
            {
                ImageLocation1.Dispose();
                cutedImage.Dispose();
            }
        }
        #endregion  


        void UsingFileSystemWatcher()
        {
            FileSystemWatcher fswWatcher = new FileSystemWatcher();

            fswWatcher.Path = path;
          
            fswWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.LastAccess;
 
            fswWatcher.Filter = "*.*";

            fswWatcher.IncludeSubdirectories = true;


            #region 实例化触发的事件(已定)


            fswWatcher.Created = new FileSystemEventHandler(fswWatcher_Created);

            fswWatcher.Changed = new FileSystemEventHandler(fswWatcher_Changed);

            fswWatcher.Renamed = new RenamedEventHandler(fswWatcher_Renamed);

            fswWatcher.Deleted = new FileSystemEventHandler(fswWatcher_Deleted);

            #endregion

            //获取或设置一个值,该值指示是否启用此组件。
            fswWatcher.EnableRaisingEvents = true;

        }//定义监控文件夹的方法

        #region  监控图片传入

        void fswWatcher_Created(object sender, FileSystemEventArgs e)
        {
           
           
            #region 修改图片名称并转存
            System.Drawing.Image ImageLocation1=null;
            try
            {
                string path2 = @"C:\copy2\" newName;
                System.IO.File.Copy(e.FullPath, path2, true);
                path3 = path2.Replace("copy2", "copy");
                //Bitmap SizeImageWithOldPercent(Image ImageLocation1, int iWidth, int iHeight)
                ImageLocation1 = System.Drawing.Image.FromFile(path2);

                SizeImageWithOldPercent(ImageLocation1, ImageLocation1.Width, ImageLocation1.Height);//单独做成方法
               
               

            }
            catch
            {
                //
            }
            finally {
                if (ImageLocation1 != null)
                {
                    ImageLocation1.Dispose();
                }
            }

           
            #endregion

        }
        #region  监控备用
        private void ModifyFileName(string p, string p_2)
        {
            throw new NotImplementedException();
        }

        void fswWatcher_Changed(object sender, FileSystemEventArgs e)
        {
        }

        void fswWatcher_Renamed(object sender, RenamedEventArgs e)
        {
        }

        void fswWatcher_Deleted(object sender, FileSystemEventArgs e)
        {
            //DirectoryInfo dir = new DirectoryInfo(path);
            //dir.Create();//自行判断一下是否存在。
        }
        #endregion
        #endregion
       

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        #region 皮肤算法集



        private void 光泽度(object sender, EventArgs e)
        {
            try
            {
                test6.Class6 exp6 = new test6.Class6();
                MWArray[] t = exp6.guangzedu(1);

                MWNumericArray t1 = (MWNumericArray)t[0];
                double[,] t2 = (double[,])t1.ToArray(MWArrayComponent.Real);
                double t3 = t2[0, 0];
                str6 = t3.ToString("N");
                textBox6.Text = str6;
                str6 = null;
               
            }
            catch (Exception)
            {
               // MessageBox.Show("图片错误,请重新选择!");
                //Close();
            }
            finally
            {
              
            }
           

        }
        private void 粗糙度(object sender, EventArgs e)
        {
            try
            {
            test1.Class1 exp1 = new test1.Class1();
            MWArray[] x = exp1.cucaodu(1);
            MWNumericArray x1 = (MWNumericArray)x[0];
            double[,] x2 = (double[,])x1.ToArray(MWArrayComponent.Real);
            double x3 = x2[0, 0];
            str1= x3.ToString("N");//将隐式int转换为string类型
            textBox1.Text = str1;
            str1 = null;
            
            
            }
            catch (Exception )
            {
               //MessageBox.Show("图片错误,请重新选择!");
               // Close();
            }
            finally
            {
                MWArray.DisposeArray(e);
            }
        }

        private void 纹理(object sender, EventArgs e)
        {
            try
            {
            test2.Class2 exp2 = new test2.Class2();
            MWArray[] a = exp2.wenli(1);
            MWNumericArray a1 = (MWNumericArray)a[0];
            double[,] b2 = (double[,])a1.ToArray(MWArrayComponent.Real);
            double b3 = b2[0, 0];
            str2 = b3.ToString("N");
            textBox2.Text = str2;
            str2 = null;

            }
            catch (Exception )
            {
               // MessageBox.Show("图片错误,请重新选择!" );
               // Close();
            }
            finally
            {
                MWArray.DisposeArray(e);
            }
        }
        private void 色泽(object sender, EventArgs e)
        {
            try
            {
            test3.Class3 exp3 = new test3.Class3();
            MWArray[] q = exp3.seze(1);
            MWNumericArray q1 = (MWNumericArray)q[0];
            double[,] q2 = (double[,])q1.ToArray(MWArrayComponent.Real);
            double q3 = q2[0, 0];
            str3 = q3.ToString("N");
            textBox3.Text = str3;
            str3 = null;
            }
            catch (Exception )
            {
               // MessageBox.Show("图片错误,请重新选择!" );
               // Close();
            }
            finally
            {
                MWArray.DisposeArray(e);
            }

        }
        private void 弹性(object sender, EventArgs e)
        {
            try
            {
            test4.Class4 exp4 = new test4.Class4();
            MWArray[] w = exp4.tanxing(1);
            MWNumericArray w1 = (MWNumericArray)w[0];
            double[,] w2 = (double[,])w1.ToArray(MWArrayComponent.Real);
            double w3 = w2[0, 0];
            str4 = w3.ToString("N");
            textBox4.Text = str4;
            str4 = null;
            }
            catch (Exception )
            {
              //  MessageBox.Show("图片错误,请重新选择!");
               // Close();
            }
            finally
            {
                MWArray.DisposeArray(e);
            }
        }
        private void 水份(object sender, EventArgs e)
        {
            try
            {
            test5.Class5 exp5 = new test5.Class5();
            MWArray[] r = exp5.water(1);
            MWNumericArray r1 = (MWNumericArray)r[0];
            double[,] r2 = (double[,])r1.ToArray(MWArrayComponent.Real);
            double r3 = r2[0, 0];
            str5 = r3.ToString("N");
            textBox5.Text = str5;
            str5 = null;
            }
            catch (Exception )
            {
               //MessageBox.Show("图片错误,请重新选择!");
               // Close();
            }
            finally
            {
                MWArray.DisposeArray(e);
            }

        }
        #endregion 

        private void button2_Click_1(object sender, EventArgs e)
         {
   
                 if (qq == 0)
                 {

                     Thread t = new Thread(DoWork);
                     t.Start();
                     

                     粗糙度(sender, e);
                     纹理(sender, e);
                     色泽(sender, e);
                     光泽度(sender, e);
                     弹性(sender, e);
                     水份(sender, e);
                     str1 = null;
                     str2 = null;
                     str3 = null;
                     str4 = null;
                     str5 = null;
                     str6 = null;
                     string a = textBox6.Text.ToString();

                     ProgressBar1.ActiveForm.Close();
                     if (a == "100.00")

                         MessageBox.Show("光泽度有误,请重新上传!");
                     else if (a == "")
                         MessageBox.Show("结果不能为空,请重新选取图片");
                     else
                         MessageBox.Show("图片分析结果正确");
                     t.Abort();
                     qq ;
                 }
                 else
                 {

                     Thread l = new Thread(DoWork1);
                     l.Start();
                     textBox1.Text = first.ToString("G");
                     textBox2.Text = first.ToString("G");
                     textBox3.Text = first.ToString("G");
                     textBox4.Text = first.ToString("G");
                     textBox5.Text = first.ToString("G");
                     textBox6.Text = first.ToString("G");
                     粗糙度(sender, e);
                     纹理(sender, e);
                     色泽(sender, e);
                     光泽度(sender, e);
                     弹性(sender, e);
                     水份(sender, e);
                     str1 = null;
                     str2 = null;
                     str3 = null;
                     str4 = null;
                     str5 = null;
                     str6 = null;
                     string zz = textBox6.Text.ToString();
                     ProgressBar2.ActiveForm.Close();

                     if (zz == "100.00")

                         MessageBox.Show("光泽度有误,请重新上传!");
                     else if (zz == "")
                         MessageBox.Show("结果不能为空,请重新选取图片");
                     else
                         MessageBox.Show("图片分析结果正确");
                     l.Abort();
                 }  
            }


实例下载地址

基于MATLAB混合编程图像分析及数据处理

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警