1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
   | class MainFrame(Tk.Frame):
	""" Affiche paramètres """
	def __init__(self, boss=None):
		Tk.Frame.__init__(self) 
		self.text=Tk.StringVar()
		self.previous_choice=-1
		self.frame = Tk.Frame(self)
 
		self.buttons = [ Tk.Button(self, text="Mean-Shift filtering parmeters", command = lambda x = None: self.change_frame(0)),
					Tk.Button(self, text="Correction light parameters", command = lambda x = None: self.change_frame(1)),
					Tk.Button(self, text="Method search markers", command = lambda x = None: self.change_frame(2)),
					Tk.Button(self, text="Method fitting ellipse", command = lambda x = None: self.change_frame(3)) ]
		self.pack_buttons()
 
		# Mode d'allocation des classes
		self.alloc_subclasse = {0 : ParamMeanShift,
								1 : ParamLight,
								2 : ParamMarker,
								3 : ParamFit}
		# Allocation des sous classes
		self.subclasses = [ ParamMeanShift(self.frame, self.buttons[0]), ParamLight(self.frame, self.buttons[1]), ParamMarker(self.frame, self.buttons[2]), ParamFit(self.frame, self.buttons[3]) ]
		Tk.Button(self, text="Run All", command = self.runall).pack(side = Tk.BOTTOM)
 
	def pack_buttons(self):
		self.buttons[0].pack(fill=Tk.X)
		self.buttons[1].pack(fill=Tk.X)
		self.buttons[2].pack(fill=Tk.X)
		self.buttons[3].pack(fill=Tk.X)
 
	def change_frame(self, frame_choice):
		""" Destruction du frame de la sous class courante et initialisation de la nouvelle sousclasse """
		self.subclasses[self.previous_choice].destroy()
		self.buttons[ self.previous_choice ]["background"] = "white"
		self.pack_buttons()
		self.buttons[frame_choice]["background"]="green"
		self.subclasses[frame_choice]=self.alloc_subclasse[frame_choice](self.frame, self.buttons[frame_choice])
		self.subclasses[frame_choice].pack()	
		self.previous_choice = frame_choice		
 
	def runall(self):
		global path	, current_image
		print("Running Mean-Shift Filtering...")
		if path==None:
			app.open()
		self.img=ChargeImage(path)
		self.img_filtree=FiltrageMeanShift(self.img, sp, sr, PyrScale)	
		current_image= self.img_filtree
		self.show_curr_img()
 
		print("Running RGB->GL, Egalize Histogramme, Correction Light...")
		current_image=Correction_light( current_image, correction_light, 0)
		self.show_curr_img()		
 
		print("Running Watershed...")
		if method_search_marker=="2":
			self.contour=Detection_contour(current_image)
			self.markers= SearchMarker(self.contour, MS_Param.img_filtree, method_search_marker)
		elif method_search_marker=="4":
			self.markers= Segmentation(current_image)
		else:
			self.markers= SearchMarker(current_image, self.img_filtree, method_search_marker)
		current_image=self.markers
		self.show_curr_img()
		print("Nombre de particules:"+repr(np.max(np.unique(self.markers))))
 
		print("Searching fitting ellipses....")
		try:
			self.b=findEllipse(current_image, method_fit_ellispe, 1)
		except ValueError:
			print ValueError			
 
	def show_curr_img(self):
		global current_image
		pil_image = None
		# Conversion de numpy.ndarray OU cv.iplimage vers PIL.Image (ImageTk.Image)
		if type(current_image) == cv.iplimage:
			if current_image.nChannels == 3:
				pil_image = ImageTk.Image.fromstring(
						'RGB', 
						cv.GetSize(current_image), 
						current_image.tostring(), 
						'raw', 
						'BGR', 
						current_image.width*3, 
						0)	
			elif current_image.nChannels==1:
				pil_image = ImageTk.Image.fromstring(
						'L', 
						cv.GetSize(current_image), 
						current_image.tostring())
			else:
				print("Error: Format non compatible nchannels!=1 ou 3")
		elif type(current_image) == np.ndarray:
			if len(np.shape(current_image)) == 3 or len(np.shape(current_image)) == 2:
				if current_image.dtype == np.uint32:
					im8bit = np.zeros(np.shape(current_image), dtype = np.int8)
					im8bit += np.floor(current_image*255/(np.max(current_image)-np.min(current_image)))
					pil_image = ImageTk.Image.fromarray(im8bit)
				else:
					pil_image = ImageTk.Image.fromarray(current_image)
			else:
				print("Error: Format non compatible nchannels!=1 ou 3")
		else:
			print("type d'image gérée")
		tk_image = ImageTk.PhotoImage(pil_image)
		try:
			self.frame.destroy()
			self.frame = Tk.Frame(self)
			self.frame.pack()
			panel1 = Tk.Label(self.frame, image=tk_image)
			panel1.pack(side=Tk.LEFT, fill=Tk.BOTH, expand='yes')
			panel1.image = tk_image
		except ValueError:
			print(ValueError)
			pass |