#include <windows.h>
#include <tchar.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <stdio.h>
#include "resource.h"

#pragma once

IplImage *vst_obr, *vst_obr1, *vst_obr_seg, *vys_seg, *anaglyf;

//seminko
CvScalar puv, ozn, mez;
IplImage *pom_sem1,*pom_sem2;
int bod_okoli;
//kontury
IplImage *obr_kont;
int _prah = 1, _min_obsah=0, _vypln=0;
CvMemStorage* storage=0;
CvSeq* kontury = 0;

void show_histogram(char* popis_okna, IplImage* src, char* nazev_kanalu)
{
  IplImage* img, * pom_hist;
  int       hod_pix = 256;
  int       hist[256];
  double    scale;
  int       i, j, channel, max = 0;

  CvScalar   colors[] = { CV_RGB(0,0,255), CV_RGB(0,255,0),
                          CV_RGB(255,0,0), CV_RGB(0,0,0) };

  channel = strcmp(nazev_kanalu, "blue")  == 0 ? 0
          : strcmp(nazev_kanalu, "green") == 0 ? 1
          : strcmp(nazev_kanalu, "red")   == 0 ? 2
          : strcmp(nazev_kanalu, "gray")  == 0 ? 3 : 0;

  if (src->nChannels == 3 && channel == 3)
  {
    img = cvCreateImage(cvGetSize(src), 8, 1);
    cvCvtColor(src, img, CV_BGR2GRAY);
  }
  else if (channel > src->nChannels)
    return;
  else
    img = cvCloneImage(src);

  pom_hist = cvCreateImage(cvSize(256, 125), IPL_DEPTH_8U, 3);
  cvSet(pom_hist, CV_RGB(255,255,255), NULL);

  
  for (j = 0; j < hod_pix-1; hist[j]=0, j++);
  for (i = 0; i < img->height; i++)
  {
    uchar* ptr = (uchar*)(img->imageData + i * img->widthStep);
    for (j = 0; j < img->width; j+=img->nChannels)
      hist[ptr[j+(channel == 3 ? 0 : channel)]]++;
  }

  
  for (i = 0; i < hod_pix-1; i++)
    max = hist[i] > max ? hist[i] : max;

  
  scale = max > pom_hist->height ? (double)pom_hist->height/max : 1.;

  
  for (i = 0; i < hod_pix-1; i++)
  {
    CvPoint pt1 = cvPoint(i, pom_hist->height - (hist[i] * scale));
    CvPoint pt2 = cvPoint(i, pom_hist->height);
    cvLine(pom_hist, pt1, pt2, colors[channel], 1, 8, 0);
  }

  cvShowImage(popis_okna, pom_hist);
  cvReleaseImage(&img);
}


int Dop_bar_schem(IplImage *inimg)
{
	float range[] = { 0, 255 };
	float* Ranges[] = { range };
	int HistSize[] = { 256 }; 
	IplImage* Images[] = { inimg };
	CvHistogram* Hist;
	Hist = cvCreateHist(1, HistSize, CV_HIST_ARRAY, Ranges, 1);
    cvCalcHist(Images, Hist, 0);
	float max_hod = 0;
	cvGetMinMaxHistValue( Hist, 0, &max_hod);
	int soucet=0;
	for(int i=0;i<255;i++)
	{
		float roz_hist1 = cvQueryHistValue_1D(Hist, i);
		float roz_hist2 = cvQueryHistValue_1D(Hist, i+1);
		int roz_hist = abs((cvRound(roz_hist2)*double(100)/max_hod)-(cvRound(roz_hist1)*double(100)/max_hod)); 
		soucet = soucet + roz_hist;
	}

	return soucet;
}

void do_kontury(float prah, float min_obsah, int vypln)
{
	IplImage *gray = cvCreateImage(cvSize(vst_obr->width,vst_obr->height), IPL_DEPTH_8U, 1);
	cvCvtColor(vst_obr, gray, CV_RGB2GRAY);
	IplImage *hrany = cvCreateImage(cvSize(vst_obr->width,vst_obr->height), IPL_DEPTH_8U, 1);
    cvSmooth( gray, hrany, CV_BLUR, 3, 3, 0, 0 );

    cvNot(gray,gray);
    cvThreshold( gray, hrany, prah, 255, CV_THRESH_BINARY );
    
    cvFindContours( hrany, storage, &kontury, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
    cvZero( obr_kont );
	cvReleaseImage(&hrany);
	cvReleaseImage(&gray);
    //! pro vsechny kontury vypocitej obsah a obvod a jak je obsah vetsi jak 3xmin_obsah tak ju vykresli nahodnou barvou
    for(int i=0 ; kontury != 0; i++, kontury = kontury->h_next )
    {
        //! vypocitej obsah kontury
        double obsah = fabs(cvContourArea(kontury));
        //! zobraz kontury, ktere maji obsah vetsi jak prah*4
        if (obsah>min_obsah*30.f)
        {
            CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
            
            cvDrawContours( obr_kont, kontury, color, color, -1, CV_FILLED, 8 );
        }
    }
	vys_seg = cvCloneImage(vst_obr);
	cvAdd(obr_kont,vst_obr,vys_seg,0);
    cvShowImage( "kont", vys_seg );

}

void on_trackbar2(int h)
{
	do_kontury((float)_prah, (float)_min_obsah, _vypln);
}

void on_trackbar3(int h)
{
	do_kontury((float)_prah, (float)_min_obsah, _vypln);
}

void Nas_Mat(CvMat *mat, int row, int col, int channel, int val)   
{   
    ((float*)(mat->data.ptr+mat->step*row))[col*mat->step+channel] = (float)val;   
}



void mouseHandler(int event, int x, int y, int flags, void *param)
{
	CvConnectedComp comp;
	switch(event) {
        case CV_EVENT_LBUTTONDOWN:
            cvFloodFill(pom_sem1,cvPoint(x,y),CV_RGB(255,0,0),mez,mez,&comp,4);
            //cvShowImage("image", pom_sem1);
			ozn = cvGet2D(vst_obr,y,x);

			for(int i=0;i<vst_obr->height;i++)
			{
				for(int j=0;j<vst_obr->width;j++)
				{
					puv = cvGet2D(vst_obr,i,j);

					if((puv.val[0]==ozn.val[0]) & (puv.val[1]==ozn.val[1]) &(puv.val[2]==ozn.val[2]))
						cvFloodFill(pom_sem2,cvPoint(j,i),CV_RGB(255,0,0),mez,mez,&comp,4);
					
				}
			}
			break;
       
        case CV_EVENT_RBUTTONDOWN:
			pom_sem2=cvCloneImage(vst_obr);
			pom_sem1=cvCloneImage(pom_sem1);
			cvShowImage("Vstupní obraz",vst_obr);

			break;

    }
	vys_seg = cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,3);

	for(int i=0;i<vst_obr->height;i++)
	{
		for(int j=0;j<vst_obr->width;j++)
		{
			puv=cvGet2D(vst_obr,i,j);
			ozn=cvGet2D(pom_sem2,i,j);
			if(bod_okoli==1)//klikáme na predmet ktery chceme vysegmentovat
			{

				if(ozn.val[2]==255 & ozn.val[1]==0 & ozn.val[0]==0)
					cvSet2D(vys_seg,i,j,puv);
				else
					cvSet2D(vys_seg,i,j,cvScalarAll(0));
			}
			else//klikame na okolí
			{
				if(ozn.val[2]==255 & ozn.val[1]==0 & ozn.val[0]==0)
					cvSet2D(vys_seg,i,j,cvScalarAll(0));
				else
					cvSet2D(vys_seg,i,j,puv);
			}
			
		}
	}

	cvShowImage("Segmentovaný obraz",vys_seg);
	
}




namespace gui {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::OpenFileDialog^  openFileDialog1;
	private: System::Windows::Forms::PictureBox^  pictureBox1;
	private: System::Windows::Forms::ComboBox^  comboBox1;

	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::Button^  button5;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown1;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown2;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown3;
	private: System::Windows::Forms::SaveFileDialog^  saveFileDialog1;
	private: System::Windows::Forms::GroupBox^  groupBox1;

	private: System::Windows::Forms::GroupBox^  groupBox2;
	private: System::Windows::Forms::GroupBox^  groupBox3;
	private: System::Windows::Forms::GroupBox^  groupBox4;
	private: System::Windows::Forms::ComboBox^  comboBox2;


	private: System::Windows::Forms::GroupBox^  groupBox5;
	private: System::Windows::Forms::GroupBox^  groupBox6;
	private: System::Windows::Forms::PictureBox^  pictureBox3;
	private: System::Windows::Forms::ContextMenuStrip^  contextMenuStrip1;
	private: System::Windows::Forms::ToolStripMenuItem^  nahrátToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  czechEnglishToolStripMenuItem;

	private: System::Windows::Forms::ToolStripMenuItem^  konecToolStripMenuItem;





	private: System::Windows::Forms::GroupBox^  groupBox8;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown4;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::GroupBox^  groupBox9;
	private: System::Windows::Forms::Label^  label8;

	private: System::Windows::Forms::Label^  label7;

	private: System::Windows::Forms::Label^  label5;
	private: System::Windows::Forms::GroupBox^  groupBox10;
	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::GroupBox^  groupBox11;
	private: System::Windows::Forms::RichTextBox^  richTextBox1;
	private: System::Windows::Forms::Button^  button7;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown8;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown7;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown5;
	private: System::Windows::Forms::Label^  label9;
	private: System::Windows::Forms::GroupBox^  groupBox12;
	private: System::Windows::Forms::GroupBox^  groupBox7;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown6;
	private: System::Windows::Forms::Label^  label12;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown9;
	private: System::Windows::Forms::Label^  label6;
	private: System::Windows::Forms::CheckBox^  checkBox1;
	private: System::Windows::Forms::Label^  label10;
	private: System::Windows::Forms::CheckBox^  checkBox2;




	private: System::ComponentModel::IContainer^  components;

	protected: 

	protected: 
















	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
			this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
			this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->button5 = (gcnew System::Windows::Forms::Button());
			this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
			this->numericUpDown2 = (gcnew System::Windows::Forms::NumericUpDown());
			this->numericUpDown3 = (gcnew System::Windows::Forms::NumericUpDown());
			this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->button7 = (gcnew System::Windows::Forms::Button());
			this->groupBox8 = (gcnew System::Windows::Forms::GroupBox());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->numericUpDown4 = (gcnew System::Windows::Forms::NumericUpDown());
			this->groupBox11 = (gcnew System::Windows::Forms::GroupBox());
			this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
			this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
			this->checkBox2 = (gcnew System::Windows::Forms::CheckBox());
			this->groupBox3 = (gcnew System::Windows::Forms::GroupBox());
			this->groupBox4 = (gcnew System::Windows::Forms::GroupBox());
			this->comboBox2 = (gcnew System::Windows::Forms::ComboBox());
			this->groupBox5 = (gcnew System::Windows::Forms::GroupBox());
			this->groupBox10 = (gcnew System::Windows::Forms::GroupBox());
			this->groupBox6 = (gcnew System::Windows::Forms::GroupBox());
			this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox());
			this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
			this->nahrátToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->czechEnglishToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->konecToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->groupBox9 = (gcnew System::Windows::Forms::GroupBox());
			this->label10 = (gcnew System::Windows::Forms::Label());
			this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
			this->numericUpDown8 = (gcnew System::Windows::Forms::NumericUpDown());
			this->numericUpDown7 = (gcnew System::Windows::Forms::NumericUpDown());
			this->numericUpDown5 = (gcnew System::Windows::Forms::NumericUpDown());
			this->label9 = (gcnew System::Windows::Forms::Label());
			this->label8 = (gcnew System::Windows::Forms::Label());
			this->label7 = (gcnew System::Windows::Forms::Label());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->button6 = (gcnew System::Windows::Forms::Button());
			this->groupBox12 = (gcnew System::Windows::Forms::GroupBox());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->numericUpDown9 = (gcnew System::Windows::Forms::NumericUpDown());
			this->groupBox7 = (gcnew System::Windows::Forms::GroupBox());
			this->numericUpDown6 = (gcnew System::Windows::Forms::NumericUpDown());
			this->label12 = (gcnew System::Windows::Forms::Label());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown1))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown2))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown3))->BeginInit();
			this->groupBox1->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown4))->BeginInit();
			this->groupBox2->SuspendLayout();
			this->groupBox3->SuspendLayout();
			this->groupBox4->SuspendLayout();
			this->groupBox5->SuspendLayout();
			this->groupBox6->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox3))->BeginInit();
			this->contextMenuStrip1->SuspendLayout();
			this->groupBox9->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown8))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown7))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown5))->BeginInit();
			this->groupBox12->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown9))->BeginInit();
			this->groupBox7->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown6))->BeginInit();
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(26, 268);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(75, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Nahrát";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// openFileDialog1
			// 
			this->openFileDialog1->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::openFileDialog1_FileOk);
			// 
			// pictureBox1
			// 
			this->pictureBox1->Dock = System::Windows::Forms::DockStyle::Fill;
			this->pictureBox1->Location = System::Drawing::Point(3, 16);
			this->pictureBox1->Name = L"pictureBox1";
			this->pictureBox1->Size = System::Drawing::Size(305, 230);
			this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
			this->pictureBox1->TabIndex = 1;
			this->pictureBox1->TabStop = false;
			this->pictureBox1->Click += gcnew System::EventHandler(this, &Form1::pictureBox1_Click);
			// 
			// comboBox1
			// 
			this->comboBox1->FormattingEnabled = true;
			this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(7) {L"RGB", L"HSV", L"YCrCb", L"XYZ", L"Lab", L"Luv", 
				L"HLS"});
			this->comboBox1->Location = System::Drawing::Point(6, 14);
			this->comboBox1->Name = L"comboBox1";
			this->comboBox1->Size = System::Drawing::Size(85, 21);
			this->comboBox1->TabIndex = 2;
			this->comboBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox1_SelectedIndexChanged);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(142, 23);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(75, 34);
			this->button2->TabIndex = 4;
			this->button2->Text = L"Histogramy složek";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(141, 11);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(84, 23);
			this->button3->TabIndex = 5;
			this->button3->Text = L"Segmentovat";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(10, 30);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(52, 13);
			this->label1->TabIndex = 6;
			this->label1->Text = L"1. složka:";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(10, 56);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(52, 13);
			this->label2->TabIndex = 7;
			this->label2->Text = L"2. složka:";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(10, 82);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(52, 13);
			this->label3->TabIndex = 8;
			this->label3->Text = L"3. složka:";
			// 
			// button4
			// 
			this->button4->Location = System::Drawing::Point(5, 42);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(75, 23);
			this->button4->TabIndex = 9;
			this->button4->Text = L"Uložit";
			this->button4->UseVisualStyleBackColor = true;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
			// 
			// button5
			// 
			this->button5->Location = System::Drawing::Point(5, 71);
			this->button5->Name = L"button5";
			this->button5->Size = System::Drawing::Size(75, 23);
			this->button5->TabIndex = 10;
			this->button5->Text = L"Ukončit";
			this->button5->UseVisualStyleBackColor = true;
			this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
			// 
			// numericUpDown1
			// 
			this->numericUpDown1->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->numericUpDown1->Location = System::Drawing::Point(88, 28);
			this->numericUpDown1->Name = L"numericUpDown1";
			this->numericUpDown1->ReadOnly = true;
			this->numericUpDown1->Size = System::Drawing::Size(31, 20);
			this->numericUpDown1->TabIndex = 11;
			// 
			// numericUpDown2
			// 
			this->numericUpDown2->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->numericUpDown2->Location = System::Drawing::Point(88, 54);
			this->numericUpDown2->Name = L"numericUpDown2";
			this->numericUpDown2->ReadOnly = true;
			this->numericUpDown2->Size = System::Drawing::Size(31, 20);
			this->numericUpDown2->TabIndex = 12;
			// 
			// numericUpDown3
			// 
			this->numericUpDown3->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->numericUpDown3->Location = System::Drawing::Point(88, 80);
			this->numericUpDown3->Name = L"numericUpDown3";
			this->numericUpDown3->ReadOnly = true;
			this->numericUpDown3->Size = System::Drawing::Size(31, 20);
			this->numericUpDown3->TabIndex = 13;
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->button7);
			this->groupBox1->Controls->Add(this->numericUpDown3);
			this->groupBox1->Controls->Add(this->numericUpDown2);
			this->groupBox1->Controls->Add(this->numericUpDown1);
			this->groupBox1->Controls->Add(this->label3);
			this->groupBox1->Controls->Add(this->button2);
			this->groupBox1->Controls->Add(this->label2);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Controls->Add(this->groupBox8);
			this->groupBox1->Location = System::Drawing::Point(0, 20);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(228, 106);
			this->groupBox1->TabIndex = 14;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"Váhy jednotlivých složek obrazu:";
			// 
			// button7
			// 
			this->button7->Location = System::Drawing::Point(142, 72);
			this->button7->Name = L"button7";
			this->button7->Size = System::Drawing::Size(75, 23);
			this->button7->TabIndex = 25;
			this->button7->Text = L"Doporučení";
			this->button7->UseVisualStyleBackColor = true;
			this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
			// 
			// groupBox8
			// 
			this->groupBox8->Location = System::Drawing::Point(0, 96);
			this->groupBox8->Name = L"groupBox8";
			this->groupBox8->Size = System::Drawing::Size(228, 90);
			this->groupBox8->TabIndex = 16;
			this->groupBox8->TabStop = false;
			this->groupBox8->Visible = false;
			this->groupBox8->Enter += gcnew System::EventHandler(this, &Form1::groupBox8_Enter);
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(10, 145);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(72, 13);
			this->label4->TabIndex = 6;
			this->label4->Text = L"Počet shluků:";
			// 
			// numericUpDown4
			// 
			this->numericUpDown4->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->numericUpDown4->Location = System::Drawing::Point(165, 143);
			this->numericUpDown4->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {50, 0, 0, 0});
			this->numericUpDown4->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
			this->numericUpDown4->Name = L"numericUpDown4";
			this->numericUpDown4->ReadOnly = true;
			this->numericUpDown4->Size = System::Drawing::Size(31, 20);
			this->numericUpDown4->TabIndex = 11;
			this->numericUpDown4->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {5, 0, 0, 0});
			// 
			// groupBox11
			// 
			this->groupBox11->Location = System::Drawing::Point(249, 415);
			this->groupBox11->Name = L"groupBox11";
			this->groupBox11->Size = System::Drawing::Size(329, 142);
			this->groupBox11->TabIndex = 24;
			this->groupBox11->TabStop = false;
			this->groupBox11->Text = L"Průvodce:";
			// 
			// richTextBox1
			// 
			this->richTextBox1->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->richTextBox1->Location = System::Drawing::Point(253, 434);
			this->richTextBox1->Name = L"richTextBox1";
			this->richTextBox1->ReadOnly = true;
			this->richTextBox1->Size = System::Drawing::Size(319, 121);
			this->richTextBox1->TabIndex = 30;
			this->richTextBox1->Tag = L"";
			this->richTextBox1->Text = L"Nahrej obrázek.";
			// 
			// groupBox2
			// 
			this->groupBox2->Controls->Add(this->checkBox2);
			this->groupBox2->Controls->Add(this->button4);
			this->groupBox2->Controls->Add(this->button5);
			this->groupBox2->Location = System::Drawing::Point(592, 460);
			this->groupBox2->Name = L"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(90, 104);
			this->groupBox2->TabIndex = 15;
			this->groupBox2->TabStop = false;
			this->groupBox2->Text = L"Výstup";
			// 
			// checkBox2
			// 
			this->checkBox2->AutoSize = true;
			this->checkBox2->Location = System::Drawing::Point(11, 19);
			this->checkBox2->Name = L"checkBox2";
			this->checkBox2->Size = System::Drawing::Size(61, 17);
			this->checkBox2->TabIndex = 30;
			this->checkBox2->Text = L"Anaglyf";
			this->checkBox2->UseVisualStyleBackColor = true;
			// 
			// groupBox3
			// 
			this->groupBox3->Controls->Add(this->comboBox1);
			this->groupBox3->Location = System::Drawing::Point(138, 268);
			this->groupBox3->Name = L"groupBox3";
			this->groupBox3->Size = System::Drawing::Size(105, 40);
			this->groupBox3->TabIndex = 17;
			this->groupBox3->TabStop = false;
			this->groupBox3->Text = L"Barevný model";
			// 
			// groupBox4
			// 
			this->groupBox4->Controls->Add(this->comboBox2);
			this->groupBox4->Controls->Add(this->button3);
			this->groupBox4->Location = System::Drawing::Point(345, 268);
			this->groupBox4->Name = L"groupBox4";
			this->groupBox4->Size = System::Drawing::Size(233, 37);
			this->groupBox4->TabIndex = 18;
			this->groupBox4->TabStop = false;
			this->groupBox4->Text = L"Zvolit segmentační metodu";
			// 
			// comboBox2
			// 
			this->comboBox2->FormattingEnabled = true;
			this->comboBox2->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"Kmeans", L"růst ze semínka", L"Kontury"});
			this->comboBox2->Location = System::Drawing::Point(6, 13);
			this->comboBox2->Name = L"comboBox2";
			this->comboBox2->Size = System::Drawing::Size(129, 21);
			this->comboBox2->TabIndex = 1;
			this->comboBox2->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox2_SelectedIndexChanged);
			// 
			// groupBox5
			// 
			this->groupBox5->Controls->Add(this->groupBox10);
			this->groupBox5->Controls->Add(this->pictureBox1);
			this->groupBox5->Location = System::Drawing::Point(19, 9);
			this->groupBox5->Name = L"groupBox5";
			this->groupBox5->Size = System::Drawing::Size(311, 249);
			this->groupBox5->TabIndex = 21;
			this->groupBox5->TabStop = false;
			this->groupBox5->Text = L"Vstupní obrázek";
			// 
			// groupBox10
			// 
			this->groupBox10->Location = System::Drawing::Point(214, 249);
			this->groupBox10->Name = L"groupBox10";
			this->groupBox10->Size = System::Drawing::Size(247, 104);
			this->groupBox10->TabIndex = 25;
			this->groupBox10->TabStop = false;
			this->groupBox10->Text = L"groupBox10";
			// 
			// groupBox6
			// 
			this->groupBox6->Controls->Add(this->pictureBox3);
			this->groupBox6->Location = System::Drawing::Point(345, 9);
			this->groupBox6->Name = L"groupBox6";
			this->groupBox6->Size = System::Drawing::Size(318, 249);
			this->groupBox6->TabIndex = 22;
			this->groupBox6->TabStop = false;
			this->groupBox6->Text = L"Výstupní obrázek";
			// 
			// pictureBox3
			// 
			this->pictureBox3->Dock = System::Windows::Forms::DockStyle::Fill;
			this->pictureBox3->Location = System::Drawing::Point(3, 16);
			this->pictureBox3->Name = L"pictureBox3";
			this->pictureBox3->Size = System::Drawing::Size(312, 230);
			this->pictureBox3->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
			this->pictureBox3->TabIndex = 1;
			this->pictureBox3->TabStop = false;
			this->pictureBox3->Click += gcnew System::EventHandler(this, &Form1::pictureBox3_Click);
			// 
			// contextMenuStrip1
			// 
			this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {this->nahrátToolStripMenuItem, 
				this->czechEnglishToolStripMenuItem, this->konecToolStripMenuItem});
			this->contextMenuStrip1->Name = L"contextMenuStrip1";
			this->contextMenuStrip1->ShowCheckMargin = true;
			this->contextMenuStrip1->Size = System::Drawing::Size(172, 70);
			this->contextMenuStrip1->Opening += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::contextMenuStrip1_Opening);
			// 
			// nahrátToolStripMenuItem
			// 
			this->nahrátToolStripMenuItem->Name = L"nahrátToolStripMenuItem";
			this->nahrátToolStripMenuItem->Size = System::Drawing::Size(171, 22);
			this->nahrátToolStripMenuItem->Text = L"Nahrát";
			this->nahrátToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::nahrátToolStripMenuItem_Click);
			// 
			// czechEnglishToolStripMenuItem
			// 
			this->czechEnglishToolStripMenuItem->CheckOnClick = true;
			this->czechEnglishToolStripMenuItem->Name = L"czechEnglishToolStripMenuItem";
			this->czechEnglishToolStripMenuItem->Size = System::Drawing::Size(171, 22);
			this->czechEnglishToolStripMenuItem->Text = L"Czech/English";
			this->czechEnglishToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::czechEnglishToolStripMenuItem_Click);
			// 
			// konecToolStripMenuItem
			// 
			this->konecToolStripMenuItem->Name = L"konecToolStripMenuItem";
			this->konecToolStripMenuItem->Size = System::Drawing::Size(171, 22);
			this->konecToolStripMenuItem->Text = L"Konec";
			this->konecToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::konecToolStripMenuItem_Click);
			// 
			// groupBox9
			// 
			this->groupBox9->Controls->Add(this->label10);
			this->groupBox9->Controls->Add(this->checkBox1);
			this->groupBox9->Controls->Add(this->numericUpDown8);
			this->groupBox9->Controls->Add(this->numericUpDown7);
			this->groupBox9->Controls->Add(this->numericUpDown5);
			this->groupBox9->Controls->Add(this->label9);
			this->groupBox9->Controls->Add(this->label8);
			this->groupBox9->Controls->Add(this->label7);
			this->groupBox9->Controls->Add(this->label5);
			this->groupBox9->Location = System::Drawing::Point(253, 317);
			this->groupBox9->Name = L"groupBox9";
			this->groupBox9->Size = System::Drawing::Size(250, 92);
			this->groupBox9->TabIndex = 17;
			this->groupBox9->TabStop = false;
			this->groupBox9->Text = L"Nastavení metody růst ze seminka";
			// 
			// label10
			// 
			this->label10->AutoSize = true;
			this->label10->Location = System::Drawing::Point(10, 63);
			this->label10->Name = L"label10";
			this->label10->Size = System::Drawing::Size(73, 13);
			this->label10->TabIndex = 30;
			this->label10->Text = L"Zadej bod do:";
			// 
			// checkBox1
			// 
			this->checkBox1->AutoSize = true;
			this->checkBox1->Location = System::Drawing::Point(92, 63);
			this->checkBox1->Name = L"checkBox1";
			this->checkBox1->Size = System::Drawing::Size(57, 17);
			this->checkBox1->TabIndex = 29;
			this->checkBox1->Text = L"Objekt";
			this->checkBox1->UseVisualStyleBackColor = true;
			this->checkBox1->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox1_CheckedChanged);
			// 
			// numericUpDown8
			// 
			this->numericUpDown8->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->numericUpDown8->Location = System::Drawing::Point(213, 61);
			this->numericUpDown8->Name = L"numericUpDown8";
			this->numericUpDown8->ReadOnly = true;
			this->numericUpDown8->Size = System::Drawing::Size(31, 20);
			this->numericUpDown8->TabIndex = 28;
			// 
			// numericUpDown7
			// 
			this->numericUpDown7->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->numericUpDown7->Location = System::Drawing::Point(213, 35);
			this->numericUpDown7->Name = L"numericUpDown7";
			this->numericUpDown7->ReadOnly = true;
			this->numericUpDown7->Size = System::Drawing::Size(31, 20);
			this->numericUpDown7->TabIndex = 27;
			// 
			// numericUpDown5
			// 
			this->numericUpDown5->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->numericUpDown5->Location = System::Drawing::Point(213, 9);
			this->numericUpDown5->Name = L"numericUpDown5";
			this->numericUpDown5->ReadOnly = true;
			this->numericUpDown5->Size = System::Drawing::Size(31, 20);
			this->numericUpDown5->TabIndex = 26;
			// 
			// label9
			// 
			this->label9->AutoSize = true;
			this->label9->Location = System::Drawing::Point(155, 63);
			this->label9->Name = L"label9";
			this->label9->Size = System::Drawing::Size(52, 13);
			this->label9->TabIndex = 15;
			this->label9->Text = L"3. složka:";
			// 
			// label8
			// 
			this->label8->AutoSize = true;
			this->label8->Location = System::Drawing::Point(155, 37);
			this->label8->Name = L"label8";
			this->label8->Size = System::Drawing::Size(52, 13);
			this->label8->TabIndex = 14;
			this->label8->Text = L"2. složka:";
			// 
			// label7
			// 
			this->label7->AutoSize = true;
			this->label7->Location = System::Drawing::Point(155, 11);
			this->label7->Name = L"label7";
			this->label7->Size = System::Drawing::Size(52, 13);
			this->label7->TabIndex = 12;
			this->label7->Text = L"1. složka:";
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->Location = System::Drawing::Point(10, 20);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(92, 13);
			this->label5->TabIndex = 6;
			this->label5->Text = L"Volba podobnosti:";
			// 
			// button6
			// 
			this->button6->Location = System::Drawing::Point(43, 59);
			this->button6->Name = L"button6";
			this->button6->Size = System::Drawing::Size(100, 23);
			this->button6->TabIndex = 23;
			this->button6->Text = L"Zobraz anaglyf";
			this->button6->UseVisualStyleBackColor = true;
			this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
			// 
			// groupBox12
			// 
			this->groupBox12->Controls->Add(this->label6);
			this->groupBox12->Controls->Add(this->numericUpDown4);
			this->groupBox12->Controls->Add(this->numericUpDown9);
			this->groupBox12->Controls->Add(this->label4);
			this->groupBox12->Controls->Add(this->groupBox1);
			this->groupBox12->Location = System::Drawing::Point(15, 317);
			this->groupBox12->Name = L"groupBox12";
			this->groupBox12->Size = System::Drawing::Size(228, 206);
			this->groupBox12->TabIndex = 25;
			this->groupBox12->TabStop = false;
			this->groupBox12->Text = L"Nastavení metody Kmeans:";
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->Location = System::Drawing::Point(10, 172);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(149, 13);
			this->label6->TabIndex = 15;
			this->label6->Text = L"Velikost průměrovacího okna:";
			// 
			// numericUpDown9
			// 
			this->numericUpDown9->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->numericUpDown9->Location = System::Drawing::Point(165, 170);
			this->numericUpDown9->Name = L"numericUpDown9";
			this->numericUpDown9->ReadOnly = true;
			this->numericUpDown9->Size = System::Drawing::Size(31, 20);
			this->numericUpDown9->TabIndex = 16;
			this->numericUpDown9->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {3, 0, 0, 0});
			// 
			// groupBox7
			// 
			this->groupBox7->Controls->Add(this->numericUpDown6);
			this->groupBox7->Controls->Add(this->label12);
			this->groupBox7->Controls->Add(this->button6);
			this->groupBox7->Location = System::Drawing::Point(509, 317);
			this->groupBox7->Name = L"groupBox7";
			this->groupBox7->Size = System::Drawing::Size(151, 92);
			this->groupBox7->TabIndex = 29;
			this->groupBox7->TabStop = false;
			this->groupBox7->Text = L"Nastavení anaglyfu";
			// 
			// numericUpDown6
			// 
			this->numericUpDown6->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->numericUpDown6->Location = System::Drawing::Point(112, 26);
			this->numericUpDown6->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
			this->numericUpDown6->Name = L"numericUpDown6";
			this->numericUpDown6->ReadOnly = true;
			this->numericUpDown6->Size = System::Drawing::Size(31, 20);
			this->numericUpDown6->TabIndex = 28;
			this->numericUpDown6->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
			// 
			// label12
			// 
			this->label12->AutoSize = true;
			this->label12->Location = System::Drawing::Point(10, 26);
			this->label12->Name = L"label12";
			this->label12->Size = System::Drawing::Size(82, 13);
			this->label12->TabIndex = 6;
			this->label12->Text = L"Volba posunutí:";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(684, 567);
			this->ContextMenuStrip = this->contextMenuStrip1;
			this->Controls->Add(this->richTextBox1);
			this->Controls->Add(this->groupBox7);
			this->Controls->Add(this->groupBox6);
			this->Controls->Add(this->groupBox5);
			this->Controls->Add(this->groupBox4);
			this->Controls->Add(this->groupBox3);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox9);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->groupBox11);
			this->Controls->Add(this->groupBox12);
			this->Name = L"Form1";
			this->Text = L"SegAnag";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown1))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown2))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown3))->EndInit();
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown4))->EndInit();
			this->groupBox2->ResumeLayout(false);
			this->groupBox2->PerformLayout();
			this->groupBox3->ResumeLayout(false);
			this->groupBox4->ResumeLayout(false);
			this->groupBox5->ResumeLayout(false);
			this->groupBox6->ResumeLayout(false);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox3))->EndInit();
			this->contextMenuStrip1->ResumeLayout(false);
			this->groupBox9->ResumeLayout(false);
			this->groupBox9->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown8))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown7))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown5))->EndInit();
			this->groupBox12->ResumeLayout(false);
			this->groupBox12->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown9))->EndInit();
			this->groupBox7->ResumeLayout(false);
			this->groupBox7->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown6))->EndInit();
			this->ResumeLayout(false);

		}
#pragma endregion
	

	
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				 openFileDialog1->Filter = "Picture Files(*.jpg;*.bmp;*.tiff;*.png) |*.jpg;*.bmp;*.tiff;*.png|All files (*.*)|*.*";
				 openFileDialog1->FilterIndex = 1;
				 if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
				 {
					 System::String^ nac_obr = openFileDialog1->FileName;
					 char* ptr = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(nac_obr).ToPointer();
					 vst_obr=cvLoadImage(ptr,CV_LOAD_IMAGE_COLOR);
					 vst_obr1 = cvCreateImage(cvGetSize(vst_obr),vst_obr->depth,vst_obr->nChannels);
					 cvCopyImage(vst_obr,vst_obr1);
					 System::Drawing::Bitmap ^srcBmp = gcnew 
					 System::Drawing::Bitmap(vst_obr->width,vst_obr->height, vst_obr->widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)vst_obr->imageData);
					 pictureBox1->Image = 
					 pictureBox1->Image->FromHbitmap(srcBmp->GetHbitmap());
					 richTextBox1->Text = "Dostupná segmentační metoda kontur.\nPro výběr z dalších segmentačních metod zvol barevné schéma.\nPo zvolení si můžeš prohlédnout histogramy jednotlivých složek.";
				 }
			 }
	private: System::Void pictureBox1_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void openFileDialog1_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) 
		 {			
		 }
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
			 Close();
		 }
private: System::Void konecToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 Close();
		 }
private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 if(!vst_obr)
				 richTextBox1->Text = "Nahrej obrázek!";
			 else
				 {
				 vst_obr_seg = cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,vst_obr->nChannels);
					 switch (comboBox1->SelectedIndex)
					 {
						 case 0:
							 cvCopyImage(vst_obr, vst_obr_seg);
							 break;
						 case 1:
							 cvCvtColor(vst_obr,vst_obr_seg,CV_RGB2HSV);
							 break;
						 case 2:
							 cvCvtColor(vst_obr,vst_obr_seg,CV_RGB2YCrCb);
							 break;
						 case 3:
							 cvCvtColor(vst_obr,vst_obr_seg,CV_RGB2XYZ);
							 break;
						 case 4:
							 cvCvtColor(vst_obr,vst_obr_seg,CV_RGB2Lab);
							 break;
						 case 5:
							 cvCvtColor(vst_obr,vst_obr_seg,CV_RGB2Luv);
							 break;
						 case 6:
							 cvCvtColor(vst_obr,vst_obr_seg,CV_RGB2HLS);
							 break;
					 }
					 
					 System::Drawing::Bitmap ^srcBmp1 = gcnew System::Drawing::Bitmap(vst_obr_seg->width,vst_obr_seg->height, vst_obr_seg->widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)vst_obr_seg->imageData);
					 pictureBox3->Image = pictureBox3->Image->FromHbitmap(srcBmp1->GetHbitmap());
			 }
		 }
private: System::Void czechEnglishToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(czechEnglishToolStripMenuItem->Checked)
			 {
				 button1->Text = "Open";
				 button2->Text = "Show Hist";
				 button3->Text = "Segmentation";
				 button4->Text = "Save";
				 button5->Text = "Quit";
				 button6->Text = "Anaglyph";
				 button7->Text = "Suggestion";
				 nahrátToolStripMenuItem->Text = "Load";
				 konecToolStripMenuItem->Text = "Quit";
				 groupBox1->Text = "weights components of the image";
				 groupBox2->Text = "Output";
				 groupBox3->Text = "Image model";
				 groupBox4->Text = "Segmentation technique";
				 groupBox5->Text = "Input image";
				 groupBox6->Text = "Output image";
				 groupBox7->Text = "Setting anaglyph";
				 groupBox9->Text = "Setting growth of seeds";
				 groupBox11->Text = "Guide";
				 groupBox12->Text = "Setting Kmeans";
				 checkBox2->Text = "Anaglyph";
				 label1->Text = "1.channel:";
				 label2->Text = "2.channel:";
				 label3->Text = "3.channel:";
				 label4->Text = "clusters:";
				 label5->Text = "choice of similarity:";
				 label6->Text = "size averaging window:";
				 label7->Text = "1.channel:";
				 label8->Text = "2.channel:";
				 label9->Text = "3.channel:";
				 label10->Text = "Enter the point:";
				 label12->Text = "Choice of slide:";
				 if(checkBox1->Checked)
				 	checkBox1->Text = "neighbourhood";
				 else
					 checkBox1->Text = "object";
			 }
			 else
			 {
				 button1->Text = "Nahrát";
				 button2->Text = "Histogramy složek";
				 button3->Text = "Segmentovat";
				 button4->Text = "Uložit";
				 button5->Text = "Ukončit";
				 button6->Text = "Zobraz anaglyf";
				 button7->Text = "Doporučení";
				 nahrátToolStripMenuItem->Text = "Nahrát";
				 konecToolStripMenuItem->Text = "Konec";
				 groupBox1->Text = "Váhy jednotlivých složek obrazu";
				 groupBox2->Text = "Výstup";
				 groupBox3->Text = "Barevný model";
				 groupBox4->Text = "Zvolit segmentační metodu";
				 groupBox5->Text = "Vstupní obrázek";
				 groupBox6->Text = "Výstupní obrázek";
				 groupBox7->Text = "Nastavení anaglyfu";
				 groupBox9->Text = "Nastavení metody růstu ze seminka";
				 groupBox11->Text = "Průvodce";
				 groupBox12->Text = "Nastavení metody Kmeans";
				 checkBox2->Text = "Anaglyf";
				 label1->Text = "1.složka:";
				 label2->Text = "2.složka:";
				 label3->Text = "3.složka:";
				 label4->Text = "Počet shluků:";
				 label5->Text = "Volba podobnosti:";
				 label6->Text = "Velikost průměrovacího okna:";
				 label7->Text = "1.složka:";
				 label8->Text = "2.složka:";
				 label9->Text = "3.složka:";
				 label10->Text = "Zadej bod do:";
				 label12->Text = "Volba posunutí:";
				 if(checkBox1->Checked)
				    checkBox1->Text = "Okolí";
				 else
					 checkBox1->Text = "Objekt";
				 
			 }
				 
		}

private: System::Void pictureBox3_Click(System::Object^  sender, System::EventArgs^  e) {
			 
		 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(!vst_obr_seg)
				 richTextBox1->Text = "Zvol barevný model.";
			 else
			 {
					 if(czechEnglishToolStripMenuItem->Checked)
					 {
						 show_histogram("1. channel", vst_obr_seg, "red");
						 show_histogram("2. channel", vst_obr_seg, "green");
						 show_histogram("3. channel", vst_obr_seg, "blue");
						 cvWaitKey();
						 cvDestroyAllWindows();
					 }
					 else
					 {
						 show_histogram("1. složka channel", vst_obr_seg, "red");
						 show_histogram("2. složka", vst_obr_seg, "green");
						 show_histogram("3. složka", vst_obr_seg, "blue");
						 cvWaitKey ();
						 cvDestroyAllWindows();
					 }
			 }
		 }
private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) {
	if(!vst_obr)
		richTextBox1->Text = "Nahrej obrázek!!";
	else
	{
		 IplImage *HSV, *YCrCb, *XYZ, *Lab, *Luv, *HLS;
		IplImage *sl_1,*sl_2,*sl_3;
		sl_1=cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,1);
		sl_2=cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,1);
		sl_3=cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,1);
		HSV=cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,vst_obr->nChannels);
		YCrCb=cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,vst_obr->nChannels);
		XYZ=cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,vst_obr->nChannels);
		Lab=cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,vst_obr->nChannels);
		Luv=cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,vst_obr->nChannels);
		HLS=cvCreateImage(cvSize(vst_obr->width,vst_obr->height),vst_obr->depth,vst_obr->nChannels);
		

		cvSplit(vst_obr,sl_3,sl_2,sl_1,NULL);
		int hod_R=Dop_bar_schem(sl_1);
		int hod_G=Dop_bar_schem(sl_2);
		int hod_B=Dop_bar_schem(sl_3);
		int hod_RGB=hod_R+hod_G+hod_B;

		cvCvtColor(vst_obr, HSV, CV_RGB2HSV);
		cvSplit(HSV,sl_3,sl_2,sl_1,NULL);
		int hod_H=Dop_bar_schem(sl_1);
		int hod_S=Dop_bar_schem(sl_2);
		int hod_V=Dop_bar_schem(sl_3);
		int hod_HSV=hod_H+hod_S+hod_V;

		cvCvtColor(vst_obr, YCrCb, CV_RGB2YCrCb);
		cvSplit(YCrCb,sl_3,sl_2,sl_1,NULL);
		int hod_Y=Dop_bar_schem(sl_1);
		int hod_Cr=Dop_bar_schem(sl_2);
		int hod_Cb=Dop_bar_schem(sl_3);
		int hod_YCrCb=hod_Y+hod_Cr+hod_Cb;
		
		cvCvtColor(vst_obr, XYZ, CV_RGB2XYZ);
		cvSplit(XYZ,sl_3,sl_2,sl_1,NULL);
		int hod_X=Dop_bar_schem(sl_1);
		int hod_Y1=Dop_bar_schem(sl_2);
		int hod_Z=Dop_bar_schem(sl_3);
		int hod_XYZ=hod_X+hod_Y1+hod_Z;

		cvCvtColor(vst_obr, Lab, CV_RGB2Lab);
		cvSplit(Lab,sl_3,sl_2,sl_1,NULL);
		int hod_L=Dop_bar_schem(sl_1);
		int hod_a=Dop_bar_schem(sl_2);
		int hod_b=Dop_bar_schem(sl_3);
		int hod_Lab=hod_L+hod_a+hod_b;

		cvCvtColor(vst_obr, Luv, CV_RGB2Luv);
		cvSplit(Luv,sl_3,sl_2,sl_1,NULL);
		int hod_L1=Dop_bar_schem(sl_1);
		int hod_u=Dop_bar_schem(sl_2);
		int hod_v=Dop_bar_schem(sl_3);
		int hod_Luv=hod_L1+hod_u+hod_v;
		
		cvCvtColor(vst_obr, HLS, CV_RGB2HLS);
		cvSplit(HLS,sl_3,sl_2,sl_1,NULL);
		int hod_H1=Dop_bar_schem(sl_1);
		int hod_L2=Dop_bar_schem(sl_2);
		int hod_S1=Dop_bar_schem(sl_3);
		int hod_HLS=hod_H1+hod_L2+hod_S1;

		if(hod_RGB>=hod_HSV & hod_RGB>=hod_YCrCb & hod_RGB>=hod_XYZ & hod_RGB>=hod_Lab & hod_RGB>=hod_Luv & hod_RGB>=hod_HLS)
			richTextBox1->Text = "Doporučuje se použít schéma RGB.\nProcentuální poměr složek je R="+((hod_R+hod_G+hod_B)/(hod_R))*10+"%, G="+((hod_R+hod_G+hod_B)/(hod_G))*10+"%, B="+((hod_R+hod_G+hod_B)/(hod_B))*10+"%\n";

		if(hod_HSV>=hod_RGB & hod_HSV>=hod_YCrCb & hod_HSV>=hod_XYZ & hod_HSV>=hod_Lab & hod_HSV>=hod_Luv & hod_HSV>=hod_HLS)
			richTextBox1->Text = "Doporučuje se použít schéma HSV.\nProcentuální poměr složek je H="+((hod_H+hod_S+hod_V)/(hod_H))*10+"%, S="+((hod_H+hod_S+hod_V)/(hod_S))*10+"%, V="+((hod_H+hod_S+hod_V)/(hod_V))*10+"%\n";

		if(hod_YCrCb>=hod_RGB & hod_YCrCb>=hod_HSV & hod_YCrCb>=hod_XYZ & hod_YCrCb>=hod_Lab & hod_YCrCb>=hod_Luv & hod_YCrCb>=hod_HLS)
			richTextBox1->Text = "Doporučuje se použít schéma YCrCb.\nProcentuální poměr složek je Y="+((hod_Y+hod_Cb+hod_Cr)/(hod_Y))*10+"%, Cr="+((hod_Y+hod_Cb+hod_Cr)/(hod_Cr))*10+"%, Cb="+((hod_Y+hod_Cb+hod_Cr)/(hod_Cb))*10+"%\n";

		if(hod_XYZ>=hod_RGB & hod_XYZ>=hod_YCrCb & hod_XYZ>=hod_HSV & hod_XYZ>=hod_Lab & hod_XYZ>=hod_Luv & hod_XYZ>=hod_HLS)
			richTextBox1->Text = "Doporučuje se použít schéma XYZ.\nProcentuální poměr složek je X="+((hod_X+hod_Y1+hod_Z)/(hod_X))*10+"%, Y="+((hod_X+hod_Y1+hod_Z)/(hod_Y1))*10+"%, Z="+((hod_X+hod_Y1+hod_Z)/(hod_Z))*10+"%\n";

		if(hod_Lab>=hod_RGB & hod_Lab>=hod_YCrCb & hod_Lab>=hod_XYZ & hod_Lab>=hod_HSV & hod_Lab>=hod_Luv & hod_Lab>=hod_HLS)
			richTextBox1->Text = "Doporučuje se použít schéma Lab.\nProcentuální poměr složek je L="+((hod_L+hod_a+hod_b)/(hod_L))*10+"%, a="+((hod_L+hod_a+hod_b)/(hod_a))*10+"%, b="+((hod_L+hod_a+hod_b)/(hod_b))*10+"%\n";

		if(hod_Luv>=hod_RGB & hod_Luv>=hod_YCrCb & hod_Luv>=hod_XYZ & hod_Luv>=hod_Lab & hod_Luv>=hod_Lab & hod_Luv>=hod_HLS)
			richTextBox1->Text = "Doporučuje se použít schéma Luv.\nProcentuální poměr složek je L="+((hod_L1+hod_u+hod_v)/(hod_L1))*10+"%, u="+((hod_L1+hod_u+hod_v)/(hod_u))*10+"%, v="+((hod_L1+hod_u+hod_v)/(hod_v))*10+"%\n";

		if(hod_HLS>=hod_RGB & hod_HLS>=hod_YCrCb & hod_HLS>=hod_XYZ & hod_HLS>=hod_Lab & hod_HLS>=hod_HSV & hod_HLS>=hod_Luv)
			richTextBox1->Text = "Doporučuje se použít schéma HLS.\nProcentuální poměr složek je H="+((hod_H1+hod_L2+hod_S1)/(hod_H1))*10+"%, L="+((hod_H1+hod_L2+hod_S1)/(hod_L2))*10+"%, S="+((hod_H1+hod_L2+hod_S1)/(hod_S1))*10+"%\n";
		
		cvReleaseImage(&HSV);
		cvReleaseImage(&YCrCb);
		cvReleaseImage(&XYZ);
		cvReleaseImage(&Lab);
		cvReleaseImage(&Luv);
		cvReleaseImage(&HLS);
		cvReleaseImage(&sl_1);
		cvReleaseImage(&sl_2);
		cvReleaseImage(&sl_3);
	}		 
}
private: System::Void nahrátToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 	 openFileDialog1->Filter = "Picture Files(*.jpg;*.bmp;*.tiff;*.png) |*.jpg;*.bmp;*.tiff;*.png|All files (*.*)|*.*";
				 openFileDialog1->FilterIndex = 1;
				 if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
				 {
					 System::String^ nac_obr = openFileDialog1->FileName;
					 char* ptr = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(nac_obr).ToPointer();
					 vst_obr=cvLoadImage(ptr,CV_LOAD_IMAGE_COLOR);
					 vst_obr1 = cvCreateImage(cvGetSize(vst_obr),vst_obr->depth,vst_obr->nChannels);
					 cvCopyImage(vst_obr,vst_obr1);
					 System::Drawing::Bitmap ^srcBmp = gcnew 
					 System::Drawing::Bitmap(vst_obr->width,vst_obr->height, vst_obr->widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)vst_obr->imageData);
					 pictureBox1->Image = 
					 pictureBox1->Image->FromHbitmap(srcBmp->GetHbitmap());
					 richTextBox1->Text = "Dostupná segmentační metoda kontur.\nPro výběr z dalších segmentačních metod zvol barevné schéma.\nPo zvolení si můžeš prohlédnout histogramy jednotlivých složek.";
				 }
		 }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(!vst_obr)
				 richTextBox1->Text = "Nahrej obrázek!";
			else
			 {
				 switch (comboBox2->SelectedIndex)
				 {
					 case 0://kmeans
						 {
							 if(!vst_obr_seg)
								 richTextBox1->Text = "Zvol barevný model";
							 else
							 {
								 IplImage *temp, *pom_kmeans, *mat;
								 int nBins = 8;
								 int sir_okn = (int)numericUpDown9->Value;
								 int nClass = (int)numericUpDown4->Value;
								 int N = sir_okn;
								 int n = (N-1)/2;
								 int r = (vst_obr->height)+2*n;
								 int c = (vst_obr->width)+2*n;
								 int NbParam = nBins * nBins * nBins;
								 int divis = 256/nBins;
								 int obr_slr = (int)numericUpDown1->Value; 
								 int obr_slg = (int)numericUpDown2->Value; 
								 int obr_slb = (int)numericUpDown3->Value;

								
								temp = cvCreateImage( cvSize(vst_obr->width+N-1,vst_obr->height+N-1), IPL_DEPTH_8U, 3 );
								pom_kmeans = cvCreateImage (cvSize(vst_obr->width+N-1,vst_obr->height+N-1), IPL_DEPTH_8U, 1);
								cvZero(temp);
								cvZero(pom_kmeans);
								
								CvPoint offset = cvPoint(n,n);
								cvCopyMakeBorder(vst_obr_seg, temp, offset, IPL_BORDER_CONSTANT , cvScalarAll(0));
									
								mat = cvCreateImage(cvSize( N, N), IPL_DEPTH_8U, 3);

								int e, f, lab, sum_lab = 0;
								for (int x=n+1 ; x<vst_obr->width+n ; x++)
								{
								 for (int y=n+1 ; y<vst_obr->height+n ; y++)
								 {
									 e = 0;
									 for (int k=x-n ; k<x+n ; k++)
									 {
										 f = 0;
										 for (int l=y-n ; l<y+n ; l++)
										 {
											 ((uchar*)(mat->imageData + mat->widthStep*f))[e*3]=((uchar*)(temp->imageData + temp->widthStep*l))[k*3];
											 ((uchar*)(mat->imageData + mat->widthStep*f))[e*3+1]=((uchar*)(temp->imageData + temp->widthStep*l))[k*3+1];
											 ((uchar*)(mat->imageData + mat->widthStep*f))[e*3+2]=((uchar*)(temp->imageData + temp->widthStep*l))[k*3+2];
											 f++;
										 }
										 e++;
									 }

									 sum_lab = 0;
									 for (int i=0 ; i<sir_okn ; i++)
									 {
										 for (int j=0 ; j<sir_okn ; j++)
										 {
											 if(obr_slb==obr_slg & obr_slg==obr_slr & obr_slb==obr_slr)
											 {
												 lab = (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3]));
												 lab = lab + (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3+1]));
												 lab = lab + (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3+2]));
											 }
											 else if(obr_slr>=obr_slg & obr_slr>=obr_slb)
											 {
												 lab = (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3]) / divis)*(obr_slb*10);
												 lab = lab + (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3+1]) /divis)*(obr_slg*10);
												 lab = lab + (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3+2]) /divis)*(obr_slr*10);
											 }
											 else if(obr_slg>=obr_slr & obr_slg>=obr_slb)
											 {
												 lab = (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3]) / divis)*(obr_slb*10);
												 lab = lab + (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3+2]) /divis)*(obr_slr*10);
												 lab = lab + (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3+1]) /divis)*(obr_slg*10);
											 }else if(obr_slb>=obr_slg & obr_slb>=obr_slg)
											 {
												 lab = (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3+1]) / divis)*(obr_slg*10);
												 lab = lab + (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3+2]) /divis)*(obr_slr*10);
												 lab = lab + (int)floor((float)(((uchar*)(mat->imageData + mat->widthStep*j))[i*3]) /divis)*(obr_slb*10);
											 }
											 lab = lab + 1;
											 sum_lab = sum_lab + lab;
										 }
									 }
									 ((uchar*)(pom_kmeans->imageData + pom_kmeans->widthStep*y))[x] = (int)floor((float) (sum_lab/(sir_okn*sir_okn)));
								 }
							 }
								 cvReleaseImage(&mat);
								 cvReleaseImage(&temp);

								int poc_shl = nClass;

								vys_seg = cvCreateImage(cvGetSize(vst_obr), vst_obr->depth, vst_obr->nChannels);
								
								int size = vst_obr->width * vst_obr->height;

								CvMat* bod_kmeans = cvCreateMat(size, 1, CV_32FC(5));
								CvMat* dat_kmeans = cvCreateMat(size, 1, CV_32SC1);
								CvScalar *bar_kmeans = new CvScalar[poc_shl];

								int counter = 0;
								for(int i=0; i < vst_obr->height; i++)
								{
									for(int j=0; j < vst_obr->width; j++)
									{
										byte col_b = ((uchar *)(pom_kmeans->imageData + i*pom_kmeans->widthStep))[j*pom_kmeans->nChannels + 0]; // B
										byte col_g = ((uchar *)(pom_kmeans->imageData + i*pom_kmeans->widthStep))[j*pom_kmeans->nChannels + 1]; // G
										byte col_r = ((uchar *)(pom_kmeans->imageData + i*pom_kmeans->widthStep))[j*pom_kmeans->nChannels + 2]; // R

										Nas_Mat(bod_kmeans,counter,0,0,col_b);   
										Nas_Mat(bod_kmeans,counter,0,1,col_g);   
										Nas_Mat(bod_kmeans,counter,0,2,col_r);
										Nas_Mat(bod_kmeans,counter,0,3,i);   
										Nas_Mat(bod_kmeans,counter,0,4,j);  

										counter++;
									}
								}

								cvKMeans2(bod_kmeans, poc_shl, dat_kmeans, cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0));

								for(int i=0; i < poc_shl; i++)
								{
									bar_kmeans[i].val[0] = 0;
									bar_kmeans[i].val[1] = 0;
									bar_kmeans[i].val[2] = 0;
									bar_kmeans[i].val[3] = 0;
								}

								counter = 0;
								for(int i=0; i < vys_seg->height; i++)
								{
									for(int j=0; j < vys_seg->width; j++)
									{
										int ind_shl = dat_kmeans->data.i[counter];

										int b = ((uchar *)(vst_obr->imageData + i*vst_obr->widthStep))[j*vst_obr->nChannels + 0];   
										int g = ((uchar *)(vst_obr->imageData + i*vst_obr->widthStep))[j*vst_obr->nChannels + 1];   
										int r = ((uchar *)(vst_obr->imageData + i*vst_obr->widthStep))[j*vst_obr->nChannels + 2];   

										bar_kmeans[ind_shl].val[0] += r;
										bar_kmeans[ind_shl].val[1] += g;
										bar_kmeans[ind_shl].val[2] += b;
										bar_kmeans[ind_shl].val[3] += 1;

										counter++;
									}
								}

								for(int i=0; i < poc_shl; i++)
								{
									bar_kmeans[i].val[0] = bar_kmeans[i].val[0] / bar_kmeans[i].val[3];
									bar_kmeans[i].val[1] = bar_kmeans[i].val[1] / bar_kmeans[i].val[3];
									bar_kmeans[i].val[2] = bar_kmeans[i].val[2] / bar_kmeans[i].val[3];
								}

								counter = 0;
								for(int i=0; i < vys_seg->height; i++)
								{
									for(int j=0; j < vys_seg->width; j++)
									{
										int ind_shl = dat_kmeans->data.i[counter];

										uchar r;
										uchar g;
										uchar b;

										if(bar_kmeans[ind_shl].val[0]< 0) r = 0;
										else r = (uchar)bar_kmeans[ind_shl].val[0];

										if(bar_kmeans[ind_shl].val[1] < 0) g = 0;
										else g = (uchar)bar_kmeans[ind_shl].val[1];

										if(bar_kmeans[ind_shl].val[2] < 0) b = 0;
										else b = (uchar)bar_kmeans[ind_shl].val[2];

										((uchar *)(vys_seg->imageData + i*vys_seg->widthStep))[j*vys_seg->nChannels + 0] = b; // B
										((uchar *)(vys_seg->imageData + i*vys_seg->widthStep))[j*vys_seg->nChannels + 1] = g; // G
										((uchar *)(vys_seg->imageData + i*vys_seg->widthStep))[j*vys_seg->nChannels + 2] = r; // R

										counter++;
									}
								}

								cvReleaseMat(&bod_kmeans);
								cvReleaseMat(&dat_kmeans);
								delete bar_kmeans;
							 
							 cvWaitKey();
							 cvReleaseImage(&pom_kmeans);
								
								System::Drawing::Bitmap ^srcBmp1 = gcnew 
								System::Drawing::Bitmap(vys_seg->width,vys_seg->height, vys_seg->widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)vys_seg->imageData);
								pictureBox3->Image = pictureBox3->Image->FromHbitmap(srcBmp1->GetHbitmap());
							 }
							 break;
						 }
					 case 1://seminko
						 {
							 if(!vst_obr_seg)
								 richTextBox1->Text = "Zvol barevný model";
							 else
							 {
								 pom_sem1=cvCloneImage(vst_obr);
								 pom_sem2=cvCloneImage(vst_obr);
								 int mez_r=(int)numericUpDown5->Value;
								 int mez_g=(int)numericUpDown7->Value;
								 int mez_b=(int)numericUpDown8->Value;
								 if(checkBox1->Checked)
									 bod_okoli=0;
								 else
									 bod_okoli=1;
								 mez = cvScalar(mez_b,mez_g,mez_r,0);
								 cvNamedWindow("Vstupní obraz", CV_WINDOW_AUTOSIZE);
								
								 cvSetMouseCallback( "Vstupní obraz", mouseHandler, NULL );

								 cvShowImage("Vstupní obraz", vst_obr);
								 cvWaitKey();
								 cvDestroyAllWindows();
								 System::Drawing::Bitmap ^srcBmp1 = gcnew 
								 System::Drawing::Bitmap(vys_seg->width,vys_seg->height, vys_seg->widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)vys_seg->imageData);
								 pictureBox3->Image = 
								 pictureBox3->Image->FromHbitmap(srcBmp1->GetHbitmap());
								 cvReleaseImage(&pom_sem1);
								 cvReleaseImage(&pom_sem2);
							 }
							 break;
						 }
					 case 2:
						 {
							 storage = cvCreateMemStorage(0);

							 obr_kont = cvCreateImage(cvSize(vst_obr->width,vst_obr->height), IPL_DEPTH_8U, 3);
							 IplImage *cont_img = cvCreateImage(cvSize(vst_obr->width,vst_obr->height), IPL_DEPTH_8U, 3);

							 cvNamedWindow("kont");
							 
							 cvCreateTrackbar("prah", "kont", &_prah, 255, on_trackbar2);
							 cvCreateTrackbar("obsah", "kont", &_min_obsah, 300, on_trackbar3);

							 on_trackbar2(1);
								
							 cvWaitKey(0);
							 cvDestroyAllWindows();
							 CvScalar puv,kont;
							 for(int i=0;i<vst_obr->height;i++)
								 for(int j=0;j<vst_obr->width;j++)
								 {
						 			 puv=cvGet2D(vst_obr,i,j);
						 			 kont=cvGet2D(obr_kont,i,j);
									 if(kont.val[0]!=0 & kont.val[1]!=0 & kont.val[2]!=0)
										 cvSet2D(vys_seg,i,j,puv);
									 else
										 cvSet2D(vys_seg,i,j,cvScalarAll(0));
								 }

							 System::Drawing::Bitmap ^srcBmp1 = gcnew 
							 System::Drawing::Bitmap(vys_seg->width,vys_seg->height, vys_seg->widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)vys_seg->imageData);
							 pictureBox3->Image = 
							 pictureBox3->Image->FromHbitmap(srcBmp1->GetHbitmap());
							 cvReleaseMemStorage( &storage );
  							 cvDestroyAllWindows();
							 }
				 }
			 }

		 }
private: System::Void comboBox2_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 switch (comboBox2->SelectedIndex)
				 {
					 case 0://kmeans
						 {
							 richTextBox1->Text = "Nastavení parametrů segmentace:\nVolíme poměr jednotlivých obrazových složek, můžeme si pomoci volbou tlačítka Doporučit, počet shluků a velikost průměrovacího okna.";
							 break;
						 }
					 case 1://seminko
						 {
							 richTextBox1->Text = "Nastavení parametrů segmentace:\nVolíme meze podobnosti sousedních pixelů od vstupního bodu, který zadáme stiskem myši v samostatném okně. To se objeví po stisku tlačítka Segmentovat. Na výběr máme volit bod  do hledaného objektu nebo jeho okolí, kdy je toto okolí odstraněno. Vstupní body se zadávají levým tlačítkem myši, pravým tlačítkem se vymaže provedená segmentace. Snímek dokončíme stiskem klávesy.";
							 break;
						 }
					 case 2://kontury
						 {
							 richTextBox1->Text = "Nastavení parametrů segmentace se provádí v novém okně, které se objeví po stisku tlačítka Segmentovat. Výsledek se uloží po stisku klávesy.";
							 break;
						 }
				 }
		 }
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void groupBox8_Enter(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void contextMenuStrip1_Opening(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) {
		 }
private: System::Void checkBox1_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
			 if(checkBox1->Checked)
				 if(czechEnglishToolStripMenuItem->Checked)
					checkBox1->Text = "neighbourhood";
				 else
					 checkBox1->Text = "Okolí";
			 else
				 if(czechEnglishToolStripMenuItem->Checked)
					checkBox1->Text = "object";
				 else
					 checkBox1->Text = "Objekt";
		 }
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
			 saveFileDialog1->Filter = "Picture Files(*.jpg;*.bmp;*.tiff;*.png) |*.jpg;*.bmp;*.tiff;*.png|All files (*.*)|*.*";
			 saveFileDialog1->FilterIndex = 1;
			 if(!vst_obr)
				 richTextBox1->Text = "Nahrej obrázek";
			 else if(!vys_seg)
			 {
				 richTextBox1->Text = "Proveď segmentaci, uložit můžeš jenom anaglyf";
				 if(checkBox2->Checked)
				 {
					 if(saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
					 {
						System::String^ uloz_anag = saveFileDialog1->FileName;
						char* ptr = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(uloz_anag).ToPointer();
						cvSaveImage(ptr,anaglyf);
					 }
				 }
			 }
			 else
			 {
				 if(checkBox2->Checked)
				 {
					 if(saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
					 {
						System::String^ uloz_anag = saveFileDialog1->FileName;
						char* ptr = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(uloz_anag).ToPointer();
						cvSaveImage(ptr,anaglyf);
					 }
				 }
				 else
				 {
					 if(saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
					 {
						 System::String^ uloz_obr = saveFileDialog1->FileName;
						 char* ptr = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(uloz_obr).ToPointer();
						 cvSaveImage(ptr,vys_seg);

					 }
				 }
			 }
		 }
private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(!vst_obr)
				 richTextBox1->Text = "Nahrej obrázek.";
			 else
			 {
			 	anaglyf = cvCreateImage(cvSize(vst_obr1->width,vst_obr1->height),vst_obr1->depth,vst_obr1->nChannels);
				IplImage *pom_anag = cvCreateImage(cvSize(vst_obr1->width,vst_obr1->height),vst_obr1->depth,vst_obr1->nChannels);

				//anaglyf
				IplImage *g = cvCreateImage(cvSize(vst_obr1->width,vst_obr1->height),vst_obr1->depth,1);
				IplImage *b = cvCreateImage(cvSize(vst_obr1->width,vst_obr1->height),vst_obr1->depth,1);
				IplImage *r_l = cvCreateImage(cvSize(vst_obr1->width,vst_obr1->height),vst_obr1->depth,1);
				IplImage *r_r = cvCreateImage(cvSize(vst_obr1->width,vst_obr1->height),vst_obr1->depth,1);
				
				int k=(int)numericUpDown6->Value;
					for(int i=0;i<vst_obr1->height;i++)
						for(int j=0;j<vst_obr1->width-k;j++)
						{
							puv=cvGet2D(vst_obr1,i,j);
							cvSet2D(pom_anag,i,j+k,puv);
							if(j<k)
							{
								ozn=cvGet2D(vst_obr1,i,0);
								cvSet2D(pom_anag,i,j,ozn);
							}
						}


					cvSplit(vst_obr1, b, g, r_l, NULL);
					cvSplit(pom_anag, b, g, r_r, NULL);
				  
					cvMerge(b, g, r_l, NULL, anaglyf);

					cvShowImage("anaglyf", anaglyf);
					cvWaitKey();
					cvDestroyAllWindows();
			 }
		 }
};
}

