www.pudn.com > source.zip > gui.h


#ifndef GUI_H 
#define GUI_H 
 
#include "gaborutil.h" 
#include  
#ifndef WX_PRECOMP 
    #include  
#endif 
#include  
 
 
/* ImageOperations class: it handles all image operations such as 
 * loading, saving, etc...  
 */ 
class ImageOperations 
{ 
public: 
  ImageOperations(wxWindow *_frame);    // constructor 
  wxImage *LoadBmp(wxString bmp_name);	// loads an image from file		 
  bool SaveBmp(wxString bmp_name, int i);      // saves out_image to a given file 
  bool IsOutput();			// TRUE if  out_image <> NULL 
  void CalculateMeanAndVariance(int region);				//no color layer 
  void CalculateMeanAndVariance2(int region,int region2); //no color layer 
  void SetNoRegions(int n,int m);	      	// sets the number of regions, 
									// allocates/frees memory for 
									// means and variances 
  void SetNoRegions2(int n,int m);	      	// sets the number of regions, 
									// allocates/frees memory for 
									// means and variances 
  int GetNoRegions() { return no_regions; } 
  int GetNoRegions2() { return no_regions2; } 
  void LUV2();							//compute the 3 channels of luv 
  void CreateOutput(int l);	           // creates and draws the output 
  void CreateOutputG(int l);	          
  void CreateOutput(unsigned char *input_pic); 
  void CreateOutput2(unsigned char *input_pic); 
  void CreateOutput3(unsigned char *input_pic); 
  void CreateOutput(wxImage input_pic); 
  void CreateOutputIn(wxImage input_pic); 
  void Gabor();						//compute the texture feature images 
  fftw_real *gray_to_real(gray **img, fftw_real *realim, int num_rows, 
			int num_cols, int real_row_length); 
  gray *dim(gray **in);					//convert an array into wxImage format. 
  gray *dim2(gray **in,int layer); 
  double GetColorMean(int i, int region){return ColorMean[i][region];}; 
  double GetColorVariance(int i, int j, int region){return ColorVariance[i][j][region];}; 
  double GetInvColor(int i, int j, int region){return InvColor[i][j][region];}; 
  double GetDetColor(int region){return DetColor[region];}; 
  double GetTextureMean(int i, int region){return TextureMean[i][region];}; 
  double GetTextureVariance(int i, int j, int region){return TextureVariance[i][j][region];}; 
  double GetInvTexture(int i, int j, int region){return InvTexture[i][j][region];}; 
  double GetDetTexture(int region){return DetTexture[region];}; 
  int get_phase(){return phase;}; 
  void set_phase(int i){phase = i;}; 
  int get_no_g_f(){return no_g_feature;}; 
  void set_no_g_f(int i){no_g_feature = i;}; 
  int get_rows(){return num_rows;}; 
  int get_cols(){return num_cols;}; 
  int get_iter(){return iterations;}; 
  int get_height(){return height;}; 
  int get_width(){return width;}; 
  int get_maxit(){return max_iterations;}; 
  gray get_text(int i, int x, int y){return Texture[i][x][y];} 
  void set_text(int i, int x, int y, gray v){Texture[i][x][y] = v;} 
  double get_global_en(){return global_en;}; 
  int get_num_rad_freq(){return num_rad_freq;}; 
  int get_index(int i){return index[i];}; 
  double get_R(){return R;}; 
  double get_R1(){return R1;}; 
  wxImage *get_tmp_image(){return tmp_image;}; 
  unsigned char **get_GrayImage(){return GrayImage;}; 
 
  void Set_no_color_region(int i){no_color_region = i;}; 
  void Set_no_texture_region(int i){no_texture_region = i;}; 
  void Set_no_combined_region(int i){no_combined_region = i;}; 
  void Set_L_mean(int i){L_mean = i;}; 
  void Set_L_conf(int i){L_conf = i;}; 
  void InitOutImage();			//inicializing before the semgent algorithm 
  void Cout(int i);				//like createOutput 
  void  Metropolis(bool mmd);	//segmentation methods 
  void Gibbs(); 
  void  ICM2(); 
  int max_iterations; 
  int maxpixel_value; 
  wxImage GetOriginal(){return original;}; 
  int Ced_Pix; 
  fftw_real      ***realMatrix; 
private: 
 
  wxWindow *frame;		    // the main window 
  wxImage *in_image, *out_image, *tmp_image, *original;    // input & output images 
  wxImage *out_image2, *out_image3, *out_image4; 
  int p_num_rows, p_num_cols, p_ft_num_cols, row_pad, col_pad; 
  int width, height, num_rows, num_cols;		    // width and height of the image 
  int no_regions; 
  int no_regions2; // number of regions for Gaussian 
  int no_color_region;		//number of classes on the color layer 
  int no_texture_region;	//number of classes on the texture layer 
  int no_combined_region;	//number of classes on the combined layer 
  int L_mean;				//priori knowgeledge for the singelton energies 
  int L_conf; 
   
															// displayed image 
   ///varibles for the gabor filter///////////////////////////////// 
  fftw_complex   *p_ft_image, *filter; 
  rfftwnd_plan    p, pinv; 
  double          U_norm_fact, min, max, scale, alpha, LPsigmafact; 
  double		  alpha_combined; 
  int             i, j, k, l, row, col; 
  int             save_resp,save_freq_resp, select_filters; 
  int             skip_low, num_rad_freq, *Esorted; 
  double 	num_rad_freq_double; 
  double         *U, *SigmaV, *SigmaU, Theta[NUM_ORIENT], Esum; 
  fftw_real      *image, *p_image, *response; 
   
  int             do_stat, save_filter, no_pgm; 
  char            fname[MAXPATHLEN]; 
  gray          **in; 
  double 	satisfy_COD; 
  int 		last_filter; 
  int 		f; 
  int             nogauss_lowpass, nononlin_tanh, save_feature_pgm; 
  ///////gabor///////////////////////////// 
   
  int *index; 
 
  int **in_image_data;		    // Intensity values of the input image  
  unsigned char *LUV_features;	 
  unsigned char **GrayImage; 
  double ***Color;				// the color features 
  gray ***Texture;				// the texture features 
  int no_g_feature; 
 
  double **temp1, **temp2;		//these matrixes for the inverse variance matrix 
  double **temp3, **temp4; 
   
  double ***ColorVariance, ***InvColor, ***InvTexture;  // variances for each region and layer 
  double **ColorMean, *DetColor, *DetTexture; 
  double ***TextureVariance;		    
  double **TextureMean;   
  double ****S, **detS, ****invS, ***m, **K, *log_prior,*log_prior_texture,*log_prior_color; 
  double R, R1,log_numclass_prior,log_numclass_prior_texture,log_numclass_prior_color; 
 
  int phase; 
  //energy functions///////////////////////////////////////////////////////////// 
  double local_color_interclue_energy(int f, int row, int col, gray Class); 
  double get_color_pot_1_order(int f, int row, int col, gray label); 
  double local_color_energy4(int f, int row, int col, gray l); 
  double beta_color, beta_texture; 
  double global_color_energy(); 
  double global_combined_energy(); 
  double local_texture_energy4(int f, int row, int col, gray l); 
  double get_texture_pot_1_order(int f, int row, int col, gray Class); 
  double local_texture_interclue_energy(int f, int row, int col, gray Class); 
  double global_texture_energy(); 
  double local_combined_interclue_energy(int f, int row, int col, gray Class); 
  double local_combined_energy(int f, int row, int col, gray Class); 
 
  int ml(int num_rows, int num_cols, int num_classes, //computes maximumlikelihood 
	gray **label, double T,int layer); 
 
  double *K_color, *K_texture; 
  double *Gamma, *Beta; 
  locale_energy_func *local_energy, *pot_1_order; 
 
  gray **Color_Layer, **Texture_Layer, **X_Layer; // the 3 layers 
 
  double 	T_color_init, T_combine_init, T_texture_init; 
  double 	T_color, T_combine, T_texture; 
  double    criteria; 
 
  int  icm(int num_frames, int num_rows, int num_cols, int num_classes, 
		gray **label, double T,int layer,	 restrict_data *restrict); 
 
   
 
  int estimations; 
  int iterations; 
   
  double result; 
  double global_en; 
 
   
   
 
				   // image based on the current labeling 
}; 
 
 
/* MyScrolledWindow class: the window used for diaplaying images 
 */ 
class MyScrolledWindow: public wxScrolledWindow 
{ 
public: 
  MyScrolledWindow(wxWindow* parent, wxWindowID id = -1,  
		   const wxPoint& pos = wxDefaultPosition,  
		   const wxSize& size = wxDefaultSize,  
		   long style = wxHSCROLL | wxVSCROLL,  
		   const wxString& name = "scrolledWindow"):  
    wxScrolledWindow(parent, id, pos, size, style, name)  
  { bmp = NULL; } 
  void SetBmp(wxImage *_bmp);     // assigns the image to the window. 
 
protected: 
  virtual void OnDraw(wxDC& dc);  // displays the image in the window 
 
private: 
  wxImage *bmp;			  // the image to be displayed 
  int xDst, yDst;		  // the position of the image within 
				  // the window (meaningful only when 
				  // the image is smaller than the window) 
  void OnLeftDown(wxMouseEvent& event);	   // Left button event handler 
  void OnMouseMotion(wxMouseEvent& event); // mouse motion event handler 
 
  wxMemoryDC memDC;		  // memDC storing the image 
  
  DECLARE_EVENT_TABLE() 
}; 
 
 
/* MyFrame class: the main window 
 */ 
class MyFrame: public wxFrame 
{ 
public: 
  MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); 
  ~MyFrame(); 
  /* returns the coordinates of the given training rectangle (or the 
   * current one if region==-1) 
   */ 
  void GetRegion(int &x, int &y, int &w, int &h, int region=-1); 
 
  int Get_numc(){return atoi(numc->GetValue());} 
   
  int GetActRegion() { return act_region;} 
  void SetRegs(int x, int y, int w, int h, int act_region); 
  void SetRegsGabor(); 
  void SetRegs1(int x, int y) {  
    regs[act_region*4] = x;  
    regs[act_region*4+1] = y;  
  } 
  void SetRegs2(int x, int y) {  
    regs[act_region*4+2] = x;  
    regs[act_region*4+3] = y;  
  } 
  MyScrolledWindow *GetInputWindow() { return input_window; } 
  MyScrolledWindow *GetOutputWindow() { return output_window; } 
  MyScrolledWindow *GetOutputWindow2() { return output_window2; } 
  MyScrolledWindow *GetOutputWindow3() { return output_window3; } 
   
  bool IsSelected(int region) { // tells whether the region has been selected  
    return (regs[region*4] || regs[region*4+1] ||  
	    regs[region*4+2] || regs[region*4+3]);  
  }  
  bool AllRegionsSelected() { // tells whether all the regions has been selected 
    for(int i=1; iGetNoRegions(); ++i) 
      if (!IsSelected(i)) return false;  
    return true;  
  } 
  wxTextCtrl *gaussians;            // output textfield for Gaussian parameters 
  void Set_Gabor(int gabor){no_gabor = gabor;} 
   
private: 
  wxChoice *op_choice, *Im_choice, *Gab_choice, *Sel_choice;		// scroll-list of optimization algorithms 
  wxTextCtrl *regions;          // input field for number of classes, 
  wxTextCtrl *regions2;          // input field for number of classes, 
  wxTextCtrl *tbeta, *tt;	// beta, threshold t, 
  wxTextCtrl *numc, *numcm; 
  wxTextCtrl *maxit, *maxpercent, *maxpixel;	   
  wxTextCtrl *tT0, *tc;		// initial temperature T0, scheduler factor c, 
  wxTextCtrl *talpha;		// and MMD's alpha 
  int act_region;   // the current class 
  int *regs;	    // stores the training rectangles for each class. 
  int *texture_index; 
  int arrow_status; 
  int index1, index2,index3; 
  int gaborkesz; 
  int no_gabor; 
  bool ready, pixactive, percentactive; 
  ImageOperations *imageop;  
  MyScrolledWindow *input_window, *output_window, *output_window2, *output_window3;   // input & output 
																					  // images' window 
  wxButton *load_button, *save_button, *Clear_button, *LUV_button, *G_Select_button, 
			*G_Deselect_button, *Gabor_button, 
			*filter_button, *left_button, *right_button, *filtered_button, *g_feature_button, 
			*Same_button,*save_button2,*save_button3,*save_button4; 
  wxButton *select_region_button, *doit_button, *select_region_button_gabor, *TL_button, 
			*CL_button, *XL_button; 
   
   
  /* Event handlers 
   */   
  void OnDoit(wxCommandEvent& event);          // DoIt 
  void OnOpen(wxCommandEvent& event);          // Load 
  void OnSave(wxCommandEvent& event);          // Save   
  void OnSave2(wxCommandEvent& event);         // Save  
  void OnSave3(wxCommandEvent& event);         // Save  
  void OnSave4(wxCommandEvent& event);         // Save  
  void OnG_Deselect(wxCommandEvent& event);	   // remove for manual filter selection 
  void OnSame(wxCommandEvent& event);		   // same button 
  void OnG_Select(wxCommandEvent& event);	   // select for manual filter selection 
  void OnCL(wxCommandEvent& event);			   
  void OnTL(wxCommandEvent& event);			   
  void OnXL(wxCommandEvent& event);			   
  void OnClear(wxCommandEvent& event);			  // reset for texture features 
  void OnLuv(wxCommandEvent& event);			  // Luv computing 
  void OnGabor(wxCommandEvent& event);			  // gabor filter computing 
  void OnMaxPix(wxCommandEvent& event);			  // stop conditions 
  void OnPercent(wxCommandEvent& event);		  // stop conditions 
  void OnFilter(wxCommandEvent& event);			  
  void OnLeft(wxCommandEvent& event);			  
  void OnRight(wxCommandEvent& event);			  
  void OnFiltered(wxCommandEvent& event);		 
  void OnGFeature(wxCommandEvent& event);		 
  void OnPaint(wxPaintEvent& event);	      // paint handler 
  void OnChoice(wxCommandEvent& event);	      // optimization method selection  
  void ImChoice(wxCommandEvent& event);	      // input picture view selection 
  void GabChoice(wxCommandEvent& event);	      // gabor filters 
  void SelChoice(wxCommandEvent& event);	      // displaing af the matrixes 
  void OnRegions(wxCommandEvent& event);       // number of classes 
  void OnRegions2(wxCommandEvent& event);      // number of classes 
  void OnSelectRegion(wxCommandEvent& event);  // select training rectangle 
 
 
   
  DECLARE_EVENT_TABLE() 
}; 
 
/* Program's application class  
 */ 
class MyApp: public wxApp 
{ 
  virtual bool OnInit(); // this is the main entry point 
}; 
 
 
enum { ID_LOAD_BUTTON, ID_SAVE_BUTTON, ID_CLEAR_BUTTON, ID_LUV_BUTTON, ID_GSELECT_BUTTON, ID_GDESELECT_BUTTON, 
		ID_GABOR_BUTTON, ID_FILTER_BUTTON, ID_LEFT_BUTTON, ID_RIGHT_BUTTON, ID_FILTERED_BUTTON, 
		ID_G_FEATURE,ID_CHOICE, ID_REGIONS, ID_SELECTREGION_BUTTON,ID_GAUSSIANS, ID_DOIT_BUTTON, 
		ID_REGIONS2, ID_NUMC, ID_NUMCM, ID_TL, ID_CL, ID_XL, ID_MAXIT, ID_MAXPIXEL, ID_MAXPERCENT, 
		ID_SAME_BUTTON, IM_CHOICE, GAB_CHOICE,  
		ID_SAVE_BUTTON2,ID_SAVE_BUTTON3,ID_SAVE_BUTTON4,SEL_CHOICE}; 
 
 
 
#endif