Upload 4 files
Browse filesUpdated Some Mini Project. Continue....
- ProJect 01 .ipynb +0 -0
- Project 02 .ipynb +0 -0
- Project 03.ipynb +0 -0
- imgtools.py +36 -0
ProJect 01 .ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Project 02 .ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Project 03.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
imgtools.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from IPython.display import display
|
| 4 |
+
|
| 5 |
+
def load_image(image_path):
|
| 6 |
+
"""
|
| 7 |
+
Đọc ảnh từ đường dẫn cho trước và trả về đối tượng ảnh
|
| 8 |
+
Arguments: image_path
|
| 9 |
+
Returns: đối tượng hình ảnh
|
| 10 |
+
"""
|
| 11 |
+
try:
|
| 12 |
+
image02 = Image.open(image_path)
|
| 13 |
+
return image02
|
| 14 |
+
except Exception as e:
|
| 15 |
+
print('Lỗi khi đọc hình ảnh từ:', image_path, e)
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
def is_image_file(image_path):
|
| 19 |
+
"""
|
| 20 |
+
return: True - nếu là hình ảnh
|
| 21 |
+
False - nếu không phải
|
| 22 |
+
"""
|
| 23 |
+
extensions = ('.png', '.jpeg', '.jpg', '.gif', '.bmp')
|
| 24 |
+
return image_path.lower().endswith(extensions)
|
| 25 |
+
|
| 26 |
+
def get_image_list(folder_path):
|
| 27 |
+
image_list = []
|
| 28 |
+
if os.path.exists(folder_path) and os.path.isdir(folder_path):
|
| 29 |
+
filenames = os.listdir(folder_path)
|
| 30 |
+
for filename in filenames:
|
| 31 |
+
file_path = os.path.join(folder_path, filename)
|
| 32 |
+
if os.path.isfile(file_path) and is_image_file(file_path):
|
| 33 |
+
img = load_image(file_path)
|
| 34 |
+
if img is not None:
|
| 35 |
+
image_list.append(img)
|
| 36 |
+
return image_list
|