资源简介

基于RGB颜色的K-means图像分割。C#工程代码。交流学习

资源截图

代码片段和文件信息

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 Color_Seg_Kmeans
{
    public partial class Form1 : Form
    {
        Graphics graph1;
        Graphics graph2;
        Kmeans img = new Kmeans();
        public static int k;


        public Form1()
        {
            InitializeComponent();
            graph1 = OldImage.CreateGraphics();
            graph2 = NewImage.CreateGraphics();
            img.SetControls(OldImage NewImage ColorPanel InfoPanel);
        }

        private void LoadBtn_Click(object sender EventArgs e)
        {
            try
            {
                ColorPanel.Controls.Clear();
                img.Clear(graph1 BackColor);
                img.Clear(graph2 BackColor);
                img.Load();
            }
            catch
            {
                MessageBox.Show(“Load file error.“ “Error“ MessageBoxButtons.OK MessageBoxIcon.Error);
            }
        }

        private void SaveBtn_Click(object sender EventArgs e)
        {
            try
            {
                if (NewImage.Image == null) throw new NullReferenceException();
                img.Save();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show(“Where an image? Load it.“ “Error“ MessageBoxButtons.OK MessageBoxIcon.Error);
            }
        }

        private void ClearBtn_Click(object sender EventArgs e)
        {
            ColorPanel.Controls.Clear();
            InfoPanel.Controls.Clear();
            img.Clear(graph1 BackColor);
            img.Clear(graph2 BackColor);
            NewImage.Image = null;

        }

        private void DoBtn_Click(object sender EventArgs e)
        {
            img.Restore1();
            InfoPanel.Controls.Clear();
            ColorPanel.Controls.Clear();
            img.Clear(graph2 BackColor);
            NewImage.Image = null;
            try
            {
                k = int.Parse(Kvalue.Text);
                if (k <= 0 || k > 20) throw new OverflowException();
                if (OldImage.Image == null) throw new NullReferenceException();
                img.ImageKmeans();
            }
            catch (FormatException)
            {
                MessageBox.Show(“Uncorrect k: k is NaN.“ “Error“ MessageBoxButtons.OK MessageBoxIcon.Error);
            }
            catch (OverflowException)
            {
                MessageBox.Show(“Uncorrect k: k is out of range (1-20).“ “Error“ MessageBoxButtons.OK MessageBoxIcon.Error);
            }
            catch (NullReferenceException)
            {
                MessageBox.Show(“For segmentation you need an image.“ “Error“ MessageBoxButtons.OK MessageBoxIcon.Error);
            }
          

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-05-15 17:24  Color_Seg_Kmeans\
     目录           0  2019-05-15 17:24  Color_Seg_Kmeans\.vs\
     目录           0  2019-05-15 17:24  Color_Seg_Kmeans\.vs\Color_Seg_Kmeans\
     目录           0  2019-05-15 17:24  Color_Seg_Kmeans\.vs\Color_Seg_Kmeans\v15\
     文件       78848  2019-05-16 21:52  Color_Seg_Kmeans\.vs\Color_Seg_Kmeans\v15\.suo
     目录           0  2019-05-15 17:24  Color_Seg_Kmeans\.vs\Color_Seg_Kmeans\v15\Server\
     目录           0  2019-05-15 17:24  Color_Seg_Kmeans\.vs\Color_Seg_Kmeans\v15\Server\sqlite3\
     文件           0  2019-05-15 17:24  Color_Seg_Kmeans\.vs\Color_Seg_Kmeans\v15\Server\sqlite3\db.lock
     文件      598016  2019-05-16 20:31  Color_Seg_Kmeans\.vs\Color_Seg_Kmeans\v15\Server\sqlite3\storage.ide
     文件       32768  2019-05-16 21:45  Color_Seg_Kmeans\.vs\Color_Seg_Kmeans\v15\Server\sqlite3\storage.ide-shm
     文件     4663872  2019-05-16 21:52  Color_Seg_Kmeans\.vs\Color_Seg_Kmeans\v15\Server\sqlite3\storage.ide-wal
     目录           0  2019-05-16 21:51  Color_Seg_Kmeans\Color_Seg_Kmeans\
     文件        1147  2019-05-15 17:24  Color_Seg_Kmeans\Color_Seg_Kmeans.sln
     文件         189  2019-05-15 17:24  Color_Seg_Kmeans\Color_Seg_Kmeans\App.config
     目录           0  2019-05-16 11:26  Color_Seg_Kmeans\Color_Seg_Kmeans\bin\
     目录           0  2019-05-15 21:12  Color_Seg_Kmeans\Color_Seg_Kmeans\bin\Debug\
     文件       20992  2019-05-16 21:51  Color_Seg_Kmeans\Color_Seg_Kmeans\bin\Debug\Color_Seg_Kmeans.exe
     文件         189  2019-05-15 17:24  Color_Seg_Kmeans\Color_Seg_Kmeans\bin\Debug\Color_Seg_Kmeans.exe.config
     文件       44544  2019-05-16 21:51  Color_Seg_Kmeans\Color_Seg_Kmeans\bin\Debug\Color_Seg_Kmeans.pdb
     目录           0  2019-05-16 11:26  Color_Seg_Kmeans\Color_Seg_Kmeans\bin\Release\
     文件       19968  2019-05-16 21:51  Color_Seg_Kmeans\Color_Seg_Kmeans\bin\Release\Color_Seg_Kmeans.exe
     文件         189  2019-05-15 17:24  Color_Seg_Kmeans\Color_Seg_Kmeans\bin\Release\Color_Seg_Kmeans.exe.config
     文件       44544  2019-05-16 21:51  Color_Seg_Kmeans\Color_Seg_Kmeans\bin\Release\Color_Seg_Kmeans.pdb
     文件        3657  2019-05-15 21:11  Color_Seg_Kmeans\Color_Seg_Kmeans\Color_Seg_Kmeans.csproj
     文件        3680  2019-05-16 21:51  Color_Seg_Kmeans\Color_Seg_Kmeans\Form1.cs
     文件       16780  2019-05-16 21:51  Color_Seg_Kmeans\Color_Seg_Kmeans\Form1.Designer.cs
     文件        6017  2019-05-16 21:51  Color_Seg_Kmeans\Color_Seg_Kmeans\Form1.resx
     文件       14625  2019-05-16 20:37  Color_Seg_Kmeans\Color_Seg_Kmeans\Kmeans.cs
     目录           0  2019-05-16 11:26  Color_Seg_Kmeans\Color_Seg_Kmeans\obj\
     目录           0  2019-05-16 21:51  Color_Seg_Kmeans\Color_Seg_Kmeans\obj\Debug\
     文件          42  2019-05-15 17:35  Color_Seg_Kmeans\Color_Seg_Kmeans\obj\Debug\Color_Seg_Kmeans.csproj.CoreCompileInputs.cache
............此处省略35个文件信息

评论

共有 条评论