www.pudn.com > source.zip > MyFrame.cpp


#include "gui.h" 
/********************************************************************* 
/* Functions of MyFrame class 
/********************************************************************/ 
void MyFrame::OnPaint(wxPaintEvent& event) 
{ 
  wxPaintDC pDC(this); 
  wxString str; 
  str.Printf("input picture"); 
  pDC.DrawText(str, 75, 5);   
  str.Printf("Color layer"); 
  pDC.DrawText(str, 290, 5);   
  str.Printf("Combined layer"); 
  pDC.DrawText(str, 495, 5);   
  str.Printf("Texture layer"); 
  pDC.DrawText(str, 710, 5);   
  str.Printf("view :"); 
  pDC.DrawText(str, 15,265);   
  str.Printf("Number of color classes:"); 
  pDC.DrawText(str, 15, 385);   
  str.Printf("Number of texture classes:"); 
  pDC.DrawText(str, 15, 415);   
  str.Printf("max iterations = "); 
  pDC.DrawText(str, 15, 445); 
  str.Printf("min chaged pixels / percent = "); 
  pDC.DrawText(str, 15, 475); 
  str.Printf("combined classes / variance:"); 
  pDC.DrawText(str, 15, 505); 
  str.Printf("method ="); 
  pDC.DrawText(str, 15, 535); 
 
 /* if(imageop->get_phase() == 1){ 
	str.Printf("Computing LUV features"); 
	pDC.DrawText(str, 605, 480);   
  } 
  if(imageop->get_phase() == 2){ 
	str.Printf("Computing gabor features"); 
	pDC.DrawText(str, 605, 480);   
  }*/ 
 // str.Printf("global energy = "); 
 // pDC.DrawText(str, 445, 265); 
 // pDC.DrawText(wxString() << imageop->get_global_en(), 600, 265); 
  str.Printf("iterations = "); 
  pDC.DrawText(str, 445, 285); 
  pDC.DrawText(wxString() << imageop->get_iter(), 600, 285);   
  str.Printf("changed pixels = "); 
  pDC.DrawText(str, 445, 305); 
  pDC.DrawText(wxString() << imageop->Ced_Pix, 600, 305); 
  //*gaussians << imageop->get_global_en(); 
 
  event.Skip();	 
} 
 
 
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) 
  : wxFrame((wxFrame *)NULL, -1, title, pos, size) 
{ 
  imageop = new ImageOperations(this); 
  input_window = new MyScrolledWindow(this, -1, wxPoint(15,25),  
				      wxSize(200,200), wxHSCROLL | wxVSCROLL); 
  output_window = new MyScrolledWindow(this, -1, wxPoint(445,25),  
				       wxSize(200,200), wxHSCROLL | wxVSCROLL); 
  output_window2 = new MyScrolledWindow(this, -1, wxPoint(230,25),  
				       wxSize(200,200), wxHSCROLL | wxVSCROLL); 
  output_window3 = new MyScrolledWindow(this, -1, wxPoint(660,25),  
				       wxSize(200,200), wxHSCROLL | wxVSCROLL); 
  doit_button = new wxButton(this, ID_DOIT_BUTTON, "Do it >>",  
			     wxPoint(15,565)); 
  doit_button->Disable(); 
  load_button = new wxButton(this, ID_LOAD_BUTTON, "Open", wxPoint(15,235)); 
  save_button = new wxButton(this, ID_SAVE_BUTTON, "Save", wxPoint(100,235)); 
  save_button2 = new wxButton(this, ID_SAVE_BUTTON2, "Save", wxPoint(230,235)); 
  save_button3 = new wxButton(this, ID_SAVE_BUTTON3, "Save", wxPoint(445,235)); 
  save_button4 = new wxButton(this, ID_SAVE_BUTTON4, "Save", wxPoint(660,235)); 
  Same_button = new wxButton(this, ID_SAME_BUTTON, "Same", wxPoint(275,415)); 
  Same_button->Disable(); 
  Clear_button = new wxButton(this, ID_CLEAR_BUTTON, "Clear gabor filters", wxPoint(65,295)); 
  Clear_button->Disable(); 
  G_Select_button = new wxButton(this, ID_GSELECT_BUTTON, "Selcet", wxPoint(15,355)); 
  G_Select_button->Disable(); 
  G_Deselect_button = new wxButton(this, ID_GDESELECT_BUTTON, "Remove", wxPoint(100,355)); 
  G_Deselect_button->Disable(); 
  save_button->Disable(); 
  save_button2->Disable(); 
  save_button3->Disable(); 
  save_button4->Disable(); 
   
  select_region_button = new wxButton(this, ID_SELECTREGION_BUTTON,  
				      "Select classes", wxPoint(275,385)); 
  select_region_button->Disable(); 
  wxString choices[3] = {"Metropolis", "Gibbs sampler", "MMD"}; 
  op_choice = new wxChoice(this, ID_CHOICE, wxPoint(100,535), wxDefaultSize,  
			   3, choices); 
  op_choice->SetStringSelection("Metropolis"); 
 
  wxString ImChoices[4] = {"Original", "L", "U", "Gabaor feature xxxx"}; 
  Im_choice = new wxChoice(this, IM_CHOICE, wxPoint(65,265), wxDefaultSize,  
			   4, ImChoices); 
  Im_choice->SetStringSelection("Original"); 
  Im_choice->Disable(); 
 
  wxString GabChoices[2] = {"Gabor feature 0","Gabaor feature xxxx"}; 
  Gab_choice = new wxChoice(this, GAB_CHOICE, wxPoint(15,325), wxDefaultSize,  
			   8, GabChoices); 
  Gab_choice->SetStringSelection("Gabor feature 0"); 
  Gab_choice->Disable(); 
 
  wxString SelChoices[1] = {"Color selection 1"}; 
  Sel_choice = new wxChoice(this, SEL_CHOICE, wxPoint(445,380), wxDefaultSize,  
			   10, SelChoices); 
  Sel_choice->SetStringSelection("Color selection 1"); 
  Sel_choice->Disable(); 
 
  regions = new wxTextCtrl(this, ID_REGIONS, "", wxPoint(230,385),  
			   wxSize(27,20),  
			   wxTE_PROCESS_ENTER|wxTE_RIGHT,  
			   *(new wxTextValidator(wxFILTER_NUMERIC))); 
  regions->SetMaxLength(3); 
  regions->Disable(); 
 
  regions2 = new wxTextCtrl(this, ID_REGIONS2, "", wxPoint(230,415),  
			   wxSize(27,20),  
			   wxTE_PROCESS_ENTER|wxTE_RIGHT,  
			   *(new wxTextValidator(wxFILTER_NUMERIC))); 
  regions2->SetMaxLength(3); 
  regions2->Disable(); 
 
  gaussians = new wxTextCtrl(this, ID_GAUSSIANS, "", wxPoint(445,410),  
			     wxSize(420,220),  
			     wxTE_MULTILINE|wxTE_DONTWRAP|wxTE_READONLY, 
			     wxDefaultValidator); 
  gaussians->SetValue(""); 
 
  numc = new wxTextCtrl(this, ID_NUMC, "", wxPoint(230,505),  
			 wxSize(20,20),  
			 wxTE_PROCESS_ENTER|wxTE_RIGHT,  
			 *(new wxTextValidator(wxFILTER_NUMERIC))); 
  numc->SetMaxLength(2);  
  numc->Disable(); 
  //*numc << 5; 
 
  numcm = new wxTextCtrl(this, ID_NUMC, "", wxPoint(275,505),  
			 wxSize(20,20),  
			 wxTE_PROCESS_ENTER|wxTE_RIGHT,  
			 *(new wxTextValidator(wxFILTER_NUMERIC))); 
  numcm->SetMaxLength(2);   
  numcm->Disable(); 
  //*numcm << 1; 
 
  maxit = new wxTextCtrl(this, ID_MAXIT, "", wxPoint(230,445),  
			 wxSize(40,20),  
			 wxTE_PROCESS_ENTER|wxTE_RIGHT,  
			 *(new wxTextValidator(wxFILTER_NUMERIC))); 
  maxit->SetMaxLength(4);  
  maxit->Enable(); 
   
   
  maxpixel = new wxTextCtrl(this, ID_MAXPIXEL, "", wxPoint(230,475),  
			 wxSize(40,20),  
			 wxTE_PROCESS_ENTER|wxTE_RIGHT,  
			 *(new wxTextValidator(wxFILTER_NUMERIC))); 
  maxpixel->SetMaxLength(5);  
  maxpixel->Enable(); 
   
 
  maxpercent = new wxTextCtrl(this, ID_MAXPERCENT, "", wxPoint(275,475),  
			 wxSize(40,20),  
			 wxTE_PROCESS_ENTER|wxTE_RIGHT,  
			 *(new wxTextValidator(wxFILTER_NUMERIC))); 
  maxpercent->SetMaxLength(6);  
  maxpercent->Enable(); 
   
 
 
  regs = NULL; 
  gaborkesz = 0;   
  act_region = -1; 
  ready = false; 
  pixactive = false; 
  percentactive = false; 
  *maxit << 200; 
  *maxpixel << 25; 
} 
 
 
MyFrame::~MyFrame() 
{ 
  delete imageop; 
} 
 
 
void MyFrame::OnOpen(wxCommandEvent& event) 
{ 
  wxString image_name; 
  wxFileDialog* fdialog = new wxFileDialog(this, "Open file", "", "",  
					   "BMP files (*.bmp)|*.bmp",  
					   wxOPEN|wxCHANGE_DIR); 
	 
  if (fdialog->ShowModal() == wxID_OK) 
    { 
      image_name = fdialog->GetPath(); 
      wxImage *bmp; 
      if (bmp = imageop->LoadBmp(image_name)) // image succesfully load 
	{ 
	  input_window->SetScrollbars(10,10,(bmp->GetWidth())/10, 
				      (bmp->GetHeight())/10); 
	  input_window->SetBmp(bmp); 
	  imageop->CreateOutputIn(bmp); 
	  output_window->SetBmp(NULL); 
	  output_window2->SetBmp(NULL); 
	  output_window3->SetBmp(NULL); 
	  output_window->SetScrollbars(10,10,0,0); 
	  output_window2->SetScrollbars(10,10,0,0); 
	  output_window3->SetScrollbars(10,10,0,0); 
	  input_window->Refresh(); 
	  output_window->Refresh();	 
	  output_window2->Refresh();	 
	  output_window3->Refresh();	 
	  save_button->Enable(); 
 
 
	  regions->Disable(); 
	  regions2->Disable(); 
 
 
	  doit_button->Disable(); 
	  numc->Disable(); 
	  numcm->Disable(); 
	  imageop->LUV2(); 
	  gaborkesz = 0; 
 
	   
		imageop->Gabor();	 
		gaborkesz = 1; 
		regions->Enable(); 
        regions2->Enable();	   
		select_region_button->SetLabel("Select classes"); 
									  
		if (regs != NULL)  
	    { 
	      delete [] regs;  // remove all rectangle selections 
	      regs = NULL; 
	      act_region = -1; 
	      imageop->SetNoRegions(-1,-1); 
	    } 
		Im_choice->Clear(); 
		//} 
		wxString txt; 
		Im_choice->Append("Original"); 
		Im_choice->Append("L"); 
		Im_choice->Append("U"); 
		Im_choice->Append("V"); 
		for(int i = 4; i<4+imageop->get_no_g_f(); i++ ){ 
			txt = ""; 
			txt << "Gabor feature " << i-4; 
			Im_choice->Append(txt);			 
		} 
		Im_choice->SetSelection(0); 
    Im_choice->Enable(); 
	Clear_button->Enable(); 
	save_button2->Disable(); 
	save_button3->Disable(); 
	save_button4->Disable(); 
	Sel_choice->Disable(); 
	Gab_choice->Disable(); 
	gaussians->Clear(); 
	regions->Clear(); 
	regions2->Clear(); 
	ready = true; 
	   
	   
	  Refresh(); 
	} 
    } 
} 
void MyFrame::OnGFeature(wxCommandEvent& event) 
{ 
	char  image_name[MAXPATHLEN]; 
	arrow_status = 3; 
	index3 = 0; 
	wxImage *bmp;	 
	 
	sprintf(image_name, "%s.%u.%u.gabor.feature.bmp\0", ".\\tmp\\Kimenet", imageop->get_index(0),imageop->get_index(1));			 
	if (bmp = imageop->LoadBmp(image_name)) // image succesfully load 
		 
	imageop->CreateOutput(bmp); 
	left_button->Enable(); 
	right_button->Enable();	 
 
} 
 
void MyFrame::OnFilter(wxCommandEvent& event) 
{ 
	char  image_name[MAXPATHLEN]; 
	arrow_status = 1; 
	index1 = 0; 
	index2 = 0; 
	wxImage *bmp; 
	sprintf(image_name, "gabor.%uX%u.%u.%u.bmp\0", imageop->get_cols(), imageop->get_rows(), index1, index2); 
	if (bmp = imageop->LoadBmp(image_name)) // image succesfully load 
		 
	imageop->CreateOutput(bmp); 
	left_button->Enable(); 
	right_button->Enable();	 
} 
 
void MyFrame::OnFiltered(wxCommandEvent& event) 
{ 
	char  image_name[MAXPATHLEN]; 
	arrow_status = 2; 
	index1 = 0; 
	index2 = 0; 
	wxImage *bmp; 
	sprintf(image_name, "%s.%u.%u.gabor.bmp\0", ".\\tmp\\Kimenet", index1, index2);	 
	if (bmp = imageop->LoadBmp(image_name)) // image succesfully load 
		 
	imageop->CreateOutput(bmp); 
	left_button->Enable(); 
	right_button->Enable();	 
	 
} 
 
 
 
void MyFrame::OnRight(wxCommandEvent& event) 
{ 
	char  image_name[MAXPATHLEN]; 
	wxImage *bmp; 
	index3++; 
	index2++; 
	if(index2 > 3){ 
		index2 = 0; 
		index1++;			 
		if(index1 > imageop->get_num_rad_freq()-1){ index1 = 0;} 
	}	 
 
	if(arrow_status == 1){				 
		sprintf(image_name, "gabor.%uX%u.%u.%u.bmp\0", imageop->get_cols(), imageop->get_rows(), index1, index2); 
		bmp = imageop->LoadBmp(image_name); // image succesfully load		 
	} 
	if(arrow_status == 2){ 
		sprintf(image_name, "%s.%u.%u.gabor.bmp\0", ".\\tmp\\Kimenet", index1, index2);	 
		bmp = imageop->LoadBmp(image_name); // image succesfully load 
	} 
	if(arrow_status == 3){ 
		if(imageop->get_index(2*index3)>=0){ 
			sprintf(image_name, "%s.%u.%u.gabor.feature.bmp\0", ".\\tmp\\Kimenet",  
					imageop->get_index(2*index3),imageop->get_index(2*index3+1)); 
			bmp = imageop->LoadBmp(image_name); // image succesfully load 
		}else{ 
			index3=0; 
			sprintf(image_name, "%s.%u.%u.gabor.feature.bmp\0", ".\\tmp\\Kimenet",  
					imageop->get_index(2*index3),imageop->get_index(2*index3+1)); 
			bmp = imageop->LoadBmp(image_name); // image succesfully load 
		} 
	} 
	imageop->CreateOutput(bmp); 
	 
} 
 
void MyFrame::OnLeft(wxCommandEvent& event) 
{ 
	char  image_name[MAXPATHLEN]; 
	wxImage *bmp; 
	index3--; 
	index2--; 
	if(index2 < 0){ 
		index2 = 3; 
		index1--;			 
		if(index1 < 0){ index1 = imageop->get_num_rad_freq()-1;} 
	} 
 
	if(arrow_status == 1){				 
		sprintf(image_name, "gabor.%uX%u.%u.%u.bmp\0", imageop->get_cols(), imageop->get_rows(), index1, index2); 
		bmp = imageop->LoadBmp(image_name); // image succesfully load		 
	} 
	if(arrow_status == 2){ 
		sprintf(image_name, "%s.%u.%u.gabor.bmp\0", ".\\tmp\\Kimenet", index1, index2);	 
		bmp = imageop->LoadBmp(image_name); // image succesfully load 
	} 
	if(arrow_status == 3){ 
		if(index3 >= 0){ 
			sprintf(image_name, "%s.%u.%u.gabor.feature.bmp\0", ".\\tmp\\Kimenet",  
					imageop->get_index(2*index3),imageop->get_index(2*index3+1)); 
			bmp = imageop->LoadBmp(image_name); // image succesfully load 
		}else{ 
			index3=0; 
			while(imageop->get_index(2*index3) >= 0){index3++;} 
			index3--; 
			sprintf(image_name, "%s.%u.%u.gabor.feature.bmp\0", ".\\tmp\\Kimenet",  
					imageop->get_index(2*index3),imageop->get_index(2*index3+1)); 
			bmp = imageop->LoadBmp(image_name); // image succesfully load 
		} 
	} 
	imageop->CreateOutput(bmp); 
} 
 
void MyFrame::OnClear(wxCommandEvent& event) 
{ 
	Gab_choice->Clear(); 
		//} 
	wxString txt;	 
	for(int i = 0; iAppend(txt);			 
	} 
	Gab_choice->SetSelection(0); 
    Gab_choice->Enable(); 
	Im_choice->Clear(); 
	Im_choice->Append("Original"); 
	Im_choice->Append("L"); 
	Im_choice->Append("U"); 
	Im_choice->Append("V"); 
	Im_choice->SetSelection(0); 
	G_Select_button->Enable(); 
	texture_index = new int[no_gabor]; 
	for(i =0; i< no_gabor; i++){ 
		texture_index[i] = 0; 
	} 
	imageop->set_no_g_f(0); 
	select_region_button->Disable(); 
	regions->Clear(); 
	regions2->Clear(); 
 
} 
void MyFrame::OnG_Select(wxCommandEvent& event) 
{ 
	gray **TempTexture;	 
	int index = Gab_choice->GetSelection(); //ahonnan 
	int index2;								//ahova 
	int k = 0; 
	while(texture_index[k] == 1) k++; 
	index2 = k; 
 
	TempTexture = new gray*[imageop->get_width()]; 
	for (int j = 0; j < imageop->get_width(); ++j){ 
		TempTexture[j] = new gray[imageop->get_height()]; 
	} 
 
	texture_index[index2] = 1; 
	for (int i=0; iget_height(); ++i){ 
		for (int j=0; jget_width(); ++j){ 
			TempTexture[j][i] = imageop->get_text(index,j,i); 
			imageop->set_text(index,j,i,imageop->get_text(index2,j,i)); 
			imageop->set_text(index2,j,i,TempTexture[j][i]); 
		} 
	} 
	 
	Gab_choice->Clear(); 
	wxString txt; 
	k = 0; 
	while(texture_index[k] == 1){		 
		txt = ""; 
		txt << "(*)Gabor feature " << k; 
		Gab_choice->Append(txt); 
		k++; 
	} 
	for(i = k; iAppend(txt); 
	}	 
	Im_choice->Clear(); 
	Im_choice->Append("Original"); 
	Im_choice->Append("L"); 
	Im_choice->Append("U"); 
	Im_choice->Append("V"); 
	k = 0; 
	while(texture_index[k] == 1){		 
		txt = ""; 
		txt << "Gabor feature " << k; 
		Im_choice->Append(txt);			 
		k++; 
	} 
	imageop->set_no_g_f(imageop->get_no_g_f()+1); 
 
	Gab_choice->SetSelection(0); 
	Im_choice->SetSelection(0); 
	imageop->CreateOutputG(0); 
	if(texture_index[0] == 1){ 
		G_Select_button->Disable(); 
		G_Deselect_button->Enable(); 
	}else{ 
		G_Select_button->Enable(); 
		G_Deselect_button->Disable(); 
	} 
 
	 
	for (j = 0; j < imageop->get_width(); ++j){ 
		delete TempTexture[j]; 
	} 
	delete TempTexture; 
	regions->Clear(); 
	regions2->Clear(); 
	select_region_button->Disable(); 
	doit_button->Disable(); 
 
} 
 
void MyFrame::OnG_Deselect(wxCommandEvent& event) 
{ 
	gray **TempTexture;	 
	int index = Gab_choice->GetSelection();  
	int index2;								 
	int k = no_gabor-1; 
	while(texture_index[k] == 0) k--; 
	index2 = k; 
 
	TempTexture = new gray*[imageop->get_width()]; 
	for (int j = 0; j < imageop->get_width(); ++j){ 
		TempTexture[j] = new gray[imageop->get_height()]; 
	} 
 
	texture_index[index2] = 0; 
	for (int i=0; iget_height(); ++i){ 
		for (int j=0; jget_width(); ++j){ 
			TempTexture[j][i] = imageop->get_text(index,j,i); 
			imageop->set_text(index,j,i,imageop->get_text(index2,j,i)); 
			imageop->set_text(index2,j,i,TempTexture[j][i]); 
		} 
	} 
 
	Gab_choice->Clear(); 
	wxString txt; 
	k = 0; 
	while(texture_index[k] == 1){		 
		txt = ""; 
		txt << "(*)Gabor feature " << k; 
		Gab_choice->Append(txt); 
		k++; 
	} 
	for(i = k; iAppend(txt); 
	}	 
	Im_choice->Clear(); 
	Im_choice->Append("Original"); 
	Im_choice->Append("L"); 
	Im_choice->Append("U"); 
	Im_choice->Append("V"); 
	k = 0; 
	while(texture_index[k] == 1){		 
		txt = ""; 
		txt << "Gabor feature " << k; 
		Im_choice->Append(txt);			 
		k++; 
	} 
	imageop->set_no_g_f(imageop->get_no_g_f()-1); 
 
	Gab_choice->SetSelection(0); 
	Im_choice->SetSelection(0); 
	imageop->CreateOutputG(0); 
	 
	if(texture_index[0] == 1){ 
		G_Select_button->Disable(); 
		G_Deselect_button->Enable(); 
	}else{ 
		G_Select_button->Enable(); 
		G_Deselect_button->Disable(); 
	} 
 
	 
	for (j = 0; j < imageop->get_width(); ++j){ 
		delete TempTexture[j]; 
	} 
	delete TempTexture; 
	regions->Clear(); 
	regions2->Clear(); 
	select_region_button->Disable(); 
	doit_button->Disable(); 
 
	 
} 
 
void MyFrame::OnCL(wxCommandEvent& event) 
{ 
	imageop->Cout(0); 
} 
void MyFrame::OnTL(wxCommandEvent& event) 
{ 
	imageop->Cout(1); 
} 
void MyFrame::OnXL(wxCommandEvent& event) 
{ 
	imageop->Cout(2); 
} 
void MyFrame::OnSame(wxCommandEvent& event) 
{	 
	SetRegsGabor(); 
	Sel_choice->Enable(); 
	wxString txt = "";	 
	Sel_choice->Clear(); 
	int no_regions = (atoi(regions->GetValue())+atoi(regions2->GetValue())); 
	for(int i=0; i < no_regions; i++){ 
		txt = ""; 
		if(i >= atoi(regions->GetValue())){ 
			txt << "Gabor selection " << i+1-atoi(regions->GetValue()); 
			Sel_choice->Append(txt);	 
		}else{ 
			txt << "Color selection " << i+1; 
			Sel_choice->Append(txt); 
		}		 
		Sel_choice->SetSelection(no_regions-1); 
	} 
} 
 
void MyFrame::OnLuv(wxCommandEvent& event) 
{	 
	imageop->set_phase(1); 
	Update(); 
	Refresh(); 
	imageop->LUV2(); 
	imageop->CreateOutput(imageop->dim(imageop->get_GrayImage())); 
//	L_button->Enable(); 
//	U_button->Enable(); 
//	V_button->Enable();	 
//	Gabor_button->Enable(); 
	save_button->Enable();	 
	imageop->set_phase(0); 
	Update(); 
	Refresh(); 
} 
void MyFrame::OnGabor(wxCommandEvent& event) 
{ 
	if(!gaborkesz){		 
		imageop->Gabor();	 
//		filter_button->Enable(); 
//		filtered_button->Enable(); 
//		g_feature_button->Enable(); 
		//imageop->CreateOutput(imageop->get_tmp_image()); 
		gaborkesz = 1; 
		regions->Enable(); 
        regions2->Enable();	   
		select_region_button->SetLabel("Select classes");  // reset button 
									 // label 
		if (regs != NULL)  
	    { 
	      delete [] regs;  // remove all rectangle selections 
	      regs = NULL; 
	      act_region = -1; 
	      imageop->SetNoRegions(-1,-1); 
	    } 
	} 
	imageop->CreateOutput(imageop->get_tmp_image());	 
	   
	 
} 
 
void MyFrame::OnSave(wxCommandEvent& event) 
{ 
	  wxString image_name; 
      wxFileDialog* fdialog = new wxFileDialog(this, "Save file as", "", "",  
					       "BMP files (*.bmp)|*.bmp",  
					       wxSAVE | wxCHANGE_DIR |  
					       wxOVERWRITE_PROMPT); 
 
      if (fdialog->ShowModal() == wxID_OK) 
	{ 
	  image_name = fdialog->GetPath(); 
	  if (!imageop->SaveBmp(image_name,0)) // saving failed 
	    wxMessageBox("Can't save image!", "ERROR"); 
	} 
} 
 
void MyFrame::OnSelectRegion(wxCommandEvent& event) 
{ 
	  boolean GActive = false; 
	  boolean CActive = false; 
	  static int no_regions=0; 
	  static int no_regions2=0; 
  if (select_region_button->GetLabel() == "Select classes") 
    { 
      act_region = 0; 
      no_regions = (atoi(regions->GetValue())+atoi(regions2->GetValue())); 
	   
      imageop->SetNoRegions(atoi(regions->GetValue()),no_regions); 
	  imageop->SetNoRegions2(atoi(regions2->GetValue()),no_regions); 
	  imageop->Set_no_color_region(atoi(regions->GetValue())); 
	  imageop->Set_no_texture_region(atoi(regions2->GetValue())); 
 
      regs = new int[no_regions*4];                   // aloccate memory 
      for (int i=0; iSetLabel(act_region == no_regions-2?  
	//			     "Finish":"Next class");  // change label 
	  select_region_button->SetLabel("Next class");  // change label 
    } 
  else	// select next training rectangle 
    { 
      if (IsSelected(act_region) && (act_region < atoi(regions->GetValue()))){  
	 
		  imageop->CalculateMeanAndVariance(act_region); 
		  CActive = true; 
	 
	  } 
	  if((act_region+1 >= atoi(regions->GetValue()))&& 
		 (atoi(regions->GetValue()) == atoi(regions2->GetValue()))) Same_button->Enable(); 
 
	  if ((IsSelected(act_region)) && (act_region >= atoi(regions->GetValue()))&& 
		  (act_region < imageop->GetNoRegions())){  
		  imageop->CalculateMeanAndVariance2(act_region,atoi(regions->GetValue()));	 
		  GActive = true; 
	  } 
      if (++act_region >= imageop->GetNoRegions())   // no more regions 
		act_region = -1;                             // no act_region 
      if (AllRegionsSelected()) {                     
			doit_button->Enable();            // Enable DoIt button 
			select_region_button->Disable();  // Disable "Next class" button 
			numc->Enable(); 
			numcm->Enable(); 
			numc ->SetValue(regions2->GetValue()); 
			numcm ->SetValue("1"); 
      }       
    } 
	Sel_choice->Enable(); 
	wxString txt = ""; 
	if(GActive){ 
		if(act_region != -1){ 
			txt << "Gabor selection " << act_region-atoi(regions->GetValue()); 
			Sel_choice->Append(txt); 
		}else{ 
			txt << "Gabor selection " << no_regions-atoi(regions->GetValue()); 
			Sel_choice->Append(txt); 
		} 
	}else if(CActive){ 
		txt << "Color selection " << act_region; 
		Sel_choice->Append(txt); 
	} 
	if(act_region != -1)Sel_choice->SetSelection(act_region-1); 
	else Sel_choice->SetStringSelection(txt); 
  input_window->Refresh(); 
} 
 
 
void MyFrame::OnRegions(wxCommandEvent& event) 
{ 
	Sel_choice->Clear(); 
  select_region_button->SetLabel("Select classes"); // reset button label 
  { 
    delete [] regs;	// remove all rectangle selections 
    regs = NULL; 
    act_region = -1; 
    imageop->SetNoRegions(-1,-1); 
	gaussians->Clear(); 
 
  } 
  doit_button->Disable(); 
  Same_button->Disable(); 
  wxString str = regions->GetValue(); 
  wxString str2 = regions2->GetValue();// get entered value 
  // TODO: check wheter the value is a positive integer! 
  if ((str.Length() != 0) && (str2.Length() != 0) 
	  && imageop->get_no_g_f() > 0 && atoi(regions->GetValue()) >= 2 
	  && atoi(regions2->GetValue()) >= 2) select_region_button->Enable(); 
  else select_region_button->Disable(); 
 
} 
 
void MyFrame::OnRegions2(wxCommandEvent& event) 
{ 
  select_region_button->SetLabel("Select classes"); // reset button label 
  { 
    delete [] regs;	// remove all rectangle selections 
    regs = NULL; 
    act_region = -1; 
    imageop->SetNoRegions(-1,-1); 
	gaussians->Clear(); 
 
  } 
  doit_button->Disable(); 
  Same_button->Disable(); 
  wxString str = regions->GetValue(); 
  wxString str2 = regions2->GetValue();// get entered value 
  // TODO: check wheter the value is a positive integer! 
  if ((str.Length() != 0) && (str2.Length() != 0) 
	  && imageop->get_no_g_f() > 0 && atoi(regions2->GetValue()) >= 2 
	  && atoi(regions->GetValue()) >= 2) select_region_button->Enable(); 
  else select_region_button->Disable(); 
 
} 
 
void MyFrame::SetRegs(int x, int y, int w, int h, int act_region) 
{ 
	regs[act_region] = x; 
	regs[act_region+1] = y; 
	regs[act_region+2] = w; 
	regs[act_region+3] = h; 
} 
 
void MyFrame::SetRegsGabor() 
{ 
	int no_regions; 
	no_regions = (atoi(regions->GetValue())+atoi(regions2->GetValue())); 
	for(int i = 0; i < no_regions/2; ++i){ 
		regs[(no_regions/2)*4+i*4] = regs[i*4]; 
		regs[(no_regions/2)*4+i*4+1] = regs[i*4+1]; 
		regs[(no_regions/2)*4+i*4+2] = regs[i*4+2];  
		regs[(no_regions/2)*4+i*4+3] = regs[i*4+3];  
		imageop->CalculateMeanAndVariance2((no_regions/2)+i,atoi(regions->GetValue()));	 
	} 
	act_region = -1;                             // no act_region 
    doit_button->Enable();            // Enable DoIt button 
	select_region_button->Disable();  // Disable "Next class" button 
	numc->Enable(); 
	numcm->Enable(); 
	numc ->SetValue(regions2->GetValue()); 
	numcm ->SetValue("1"); 
	Same_button->Disable(); 
} 
 
void MyFrame::GetRegion(int &x, int &y, int &w, int &h, int region) 
{ 
  x = y = w = h = 0; 
  if (region == -1) // -1 ==> return current rectangle 
    region = act_region;	 
  if (region != -1) // otherwise compute coordinates 
    { 
      int x1 = regs[region*4]; 
      int y1 = regs[region*4+1]; 
      int x2 = regs[region*4+2]; 
      int y2 = regs[region*4+3]; 
      x = x1Set_L_mean(atoi(numcm->GetValue())); 
	imageop->Set_L_conf(atoi(numc->GetValue())); 
	imageop->max_iterations = atoi(maxit->GetValue()); 
	imageop->maxpixel_value = atoi(maxpixel->GetValue()); 
 
	if (op_choice->GetStringSelection() == "Metropolis") 
    { 
      imageop->Metropolis(false); 
    } 
	else if (op_choice->GetStringSelection() == "MMD") 
    { 
      imageop->Metropolis(true); 
    } 
	else if (op_choice->GetStringSelection() == "ICM") 
    { 
      imageop->ICM2(); 
    } 
	else if (op_choice->GetStringSelection() == "Gibbs sampler") 
    { 
      imageop->Gibbs(); 
    } 
	save_button2->Enable(); 
	save_button3->Enable(); 
	save_button4->Enable(); 
 
} 
 
void MyFrame::OnChoice(wxCommandEvent& event) 
{ 
} 
 
void MyFrame::GabChoice(wxCommandEvent& event) 
{ 
	  int index = Gab_choice->GetSelection(); 
	  if(texture_index[index] == 1){ 
		G_Select_button->Disable(); 
		G_Deselect_button->Enable(); 
	  }else{ 
		G_Select_button->Enable(); 
		G_Deselect_button->Disable(); 
	  } 
	  imageop->CreateOutputG(index); 
} 
 
void MyFrame::SelChoice(wxCommandEvent& event) 
{ 
	int no_regions = (atoi(regions->GetValue())+atoi(regions2->GetValue())); 
	wxString txt = ""; 
	txt << "Color selection " << Sel_choice->GetSelection()+1; 
 
	if (Sel_choice->GetStringSelection() == txt){ 
	  gaussians->Clear(); 
	  txt = ""; 
	  txt << "Color Selection no" << Sel_choice->GetSelection()+1 << "\n"; 
	  txt << "Component\tMean\t\tVariance\n"; 
	  gaussians->AppendText(txt); 
	  txt = ""; 
      txt << "L" << "\t\t" << imageop->GetColorMean(0,Sel_choice->GetSelection()) << "\t\t" 
		  << imageop->GetColorVariance(0,0,Sel_choice->GetSelection()) << "\n"; 
	  gaussians->AppendText(txt); 
	  txt = ""; 
	  txt << "U" << "\t\t" << imageop->GetColorMean(1,Sel_choice->GetSelection()) << "\t\t"  
		  << imageop->GetColorVariance(1,1,Sel_choice->GetSelection()) << "\n"; 
	  gaussians->AppendText(txt); 
	  txt = ""; 
	  txt << "V" << "\t\t" << imageop->GetColorMean(2,Sel_choice->GetSelection()) << "\t\t"  
		  << imageop->GetColorVariance(2,2,Sel_choice->GetSelection()) << "\n"; 
	  gaussians->AppendText(txt); 
	  gaussians->AppendText("Variance matrix : \n"); 
	  txt = ""; 
	  for(int i=0;i < 3;i++){ 
		for(int j=0;j < 3;j++){ 
			txt << imageop->GetColorVariance(i,j,Sel_choice->GetSelection()) << "\t";			     
		} 
		txt << "\n"; 
	  }	   
	  gaussians->AppendText(txt); 
	  gaussians->AppendText("Inverz variance matrix : \n"); 
	  txt = ""; 
	  for(i=0;i < 3;i++){ 
		for(int j=0;j < 3;j++){ 
			txt << imageop->GetInvColor(i,j,Sel_choice->GetSelection()) << "\t";			     
		} 
		txt << "\n"; 
	  } 
	  gaussians->AppendText(txt); 
	  txt = "Determinant : "; 
	  txt << imageop->GetDetColor(Sel_choice->GetSelection()); 
	  gaussians->AppendText(txt); 
 
 
	} 
	txt = ""; 
	txt << "Gabor selection " << Sel_choice->GetSelection()-atoi(regions->GetValue())+1; 
	//gaussians->AppendText(txt); 
	if (Sel_choice->GetStringSelection() == txt){ 
	  int region = Sel_choice->GetSelection()-atoi(regions->GetValue()); 
	  gaussians->Clear(); 
	  txt = ""; 
	  txt << "Gabor Selection no" << Sel_choice->GetSelection()-atoi(regions->GetValue())+1 << "\n"; 
	  txt << "Component\tMean\t\tVariance\n"; 
	  gaussians->AppendText(txt); 
	  for(int i=0;i < imageop->get_no_g_f() ;i++){		   
		txt = ""; 
		txt << "Gabor "<< i << "\t\t" << imageop->GetTextureMean(i,region) << "\t\t" 
		    << imageop->GetTextureVariance(i,i,region) << "\n"; 
		gaussians->AppendText(txt);					 
	  }	 
	  txt = ""; 
	  gaussians->AppendText("Variance matrix : \n"); 
	  for( i=0;i < imageop->get_no_g_f();i++){	 
		  for(int j=0;j < imageop->get_no_g_f();j++){	 
			  txt << imageop->GetTextureVariance(i,j,region) << "\t";			     
		  } 
		  txt << "\n"; 
	  } 
	  gaussians->AppendText(txt); 
	  txt=""; 
	  gaussians->AppendText("Inverz variance matrix : \n"); 
	  for( i=0;i < imageop->get_no_g_f();i++){	 
		  for(int j=0;j < imageop->get_no_g_f();j++){	 
			  txt << imageop->GetInvTexture(i,j,region) << "\t";			     
		  } 
		  txt << "\n"; 
	  }	   
	  gaussians->AppendText(txt); 
	  txt = "Determinant : "; 
	  txt << imageop->GetDetTexture(region); 
	  gaussians->AppendText(txt); 
	} 
} 
 
void MyFrame::ImChoice(wxCommandEvent& event) 
{ 
	if (Im_choice->GetStringSelection() == "L") 
    { 
      imageop->CreateOutput(0); 
    } 
	if (Im_choice->GetStringSelection() == "U") 
    { 
      imageop->CreateOutput(1); 
    } 
	if (Im_choice->GetStringSelection() == "V") 
    { 
      imageop->CreateOutput(2); 
    } 
	if (Im_choice->GetStringSelection() == "Original"){ 
		imageop->CreateOutputIn(imageop->GetOriginal()); 
	} 
	if (Im_choice->GetSelection() > 3) 
    { 
	  int index = Im_choice->GetSelection()-4; 
	  imageop->CreateOutputG(index); 
 
    } 
	 
} 
 
void MyFrame::OnMaxPix(wxCommandEvent& event) 
{ 
	pixactive = true; 
	if((ready)&&(!percentactive)) 
	{ 
	wxString txt; 
	int full; 
	int pix = atoi(maxpixel->GetValue()); 
	full = imageop->get_height()*imageop->get_width()*3; 
		maxpercent->SetValue(""); 
		*maxpercent << (double)pix/(double)full*100;	 
	} 
	pixactive = false; 
	 
} 
 
void MyFrame::OnPercent(wxCommandEvent& event) 
{	 
	percentactive = true; 
	if((ready)&&(!pixactive)) 
	{ 
	wxString txt; 
	int full; 
	double percent = atof(maxpercent->GetValue()); 
	full = imageop->get_height()*imageop->get_width()*3; 
		maxpixel->SetValue(""); 
		*maxpixel << (int)(full * percent/100); 
	} 
	percentactive = false; 
	 
} 
 
void MyFrame::OnSave2(wxCommandEvent& event) 
{	 
    
	  wxString image_name; 
      wxFileDialog* fdialog = new wxFileDialog(this, "Save file as", "", "",  
					       "BMP files (*.bmp)|*.bmp",  
					       wxSAVE | wxCHANGE_DIR |  
					       wxOVERWRITE_PROMPT); 
 
    if (fdialog->ShowModal() == wxID_OK) 
	{ 
	  image_name = fdialog->GetPath(); 
	  if (!imageop->SaveBmp(image_name,2)) // saving failed 
	  wxMessageBox("Can't save image!", "ERROR"); 
	} 
 
     
} 
void MyFrame::OnSave3(wxCommandEvent& event) 
{ 
	wxString image_name; 
      wxFileDialog* fdialog = new wxFileDialog(this, "Save file as", "", "",  
					       "BMP files (*.bmp)|*.bmp",  
					       wxSAVE | wxCHANGE_DIR |  
					       wxOVERWRITE_PROMPT); 
 
    if (fdialog->ShowModal() == wxID_OK) 
	{ 
	  image_name = fdialog->GetPath(); 
	  if (!imageop->SaveBmp(image_name,1)) // saving failed 
	  wxMessageBox("Can't save image!", "ERROR"); 
	}  
} 
void MyFrame::OnSave4(wxCommandEvent& event) 
{ 
	wxString image_name; 
      wxFileDialog* fdialog = new wxFileDialog(this, "Save file as", "", "",  
					       "BMP files (*.bmp)|*.bmp",  
					       wxSAVE | wxCHANGE_DIR |  
					       wxOVERWRITE_PROMPT); 
 
    if (fdialog->ShowModal() == wxID_OK) 
	{ 
	  image_name = fdialog->GetPath(); 
	  if (!imageop->SaveBmp(image_name,3)) // saving failed 
	  wxMessageBox("Can't save image!", "ERROR"); 
	}  
}