mirror of
				https://github.com/qurator-spk/sbb_binarization.git
				synced 2025-10-30 00:54:14 +01:00 
			
		
		
		
	Merge pull request #52 from bertsky/img-allow-alpha
allow alpha channels
This commit is contained in:
		
						commit
						eff7a47852
					
				
					 2 changed files with 6 additions and 0 deletions
				
			
		|  | @ -30,6 +30,10 @@ def cv2pil(img): | ||||||
| 
 | 
 | ||||||
| def pil2cv(img): | def pil2cv(img): | ||||||
|     # from ocrd/workspace.py |     # from ocrd/workspace.py | ||||||
|  |     if img.mode in ('LA', 'RGBA'): | ||||||
|  |         newimg = Image.new(img.mode[:-1], img.size, 'white') | ||||||
|  |         newimg.paste(img, mask=img.getchannel('A')) | ||||||
|  |         img = newimg | ||||||
|     color_conversion = cv2.COLOR_GRAY2BGR if img.mode in ('1', 'L') else  cv2.COLOR_RGB2BGR |     color_conversion = cv2.COLOR_GRAY2BGR if img.mode in ('1', 'L') else  cv2.COLOR_RGB2BGR | ||||||
|     pil_as_np_array = np.array(img).astype('uint8') if img.mode == '1' else np.array(img) |     pil_as_np_array = np.array(img).astype('uint8') if img.mode == '1' else np.array(img) | ||||||
|     return cv2.cvtColor(pil_as_np_array, color_conversion) |     return cv2.cvtColor(pil_as_np_array, color_conversion) | ||||||
|  |  | ||||||
|  | @ -34,6 +34,8 @@ class SbbBinarizer: | ||||||
|         self.start_new_session() |         self.start_new_session() | ||||||
| 
 | 
 | ||||||
|         self.model_files = glob('%s/*.h5' % self.model_dir) |         self.model_files = glob('%s/*.h5' % self.model_dir) | ||||||
|  |         if not self.model_files: | ||||||
|  |             self.model_files = glob('%s/*/' % self.model_dir) | ||||||
|         if not self.model_files: |         if not self.model_files: | ||||||
|             raise ValueError(f"No models found in {self.model_dir}") |             raise ValueError(f"No models found in {self.model_dir}") | ||||||
|          |          | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue