+Tiếp cận thư viện xử lý image như PIL pillow, opencv, .... 2Mở link sau: https://neptune.ai/blog/pil-image-tutorial-for-machine-learning 3 Thuc hién: o_ Tìm hiểu khai niém Essential PIL
Trang 1Vị INDUSTRIAL a
TRƯỜNG ĐẠI HỌC CÔNG NGHIỆP TP HÒ CHÍ MINH
Khoa: Công Nghệ Thông Tin
<6,
⁄
tê)
N
¬
SS
LAB REPORT
Student’s name : Huynh Vinh Phat
Class > DHCNTTI8A
Subject : Phat trién hệ thông đa phương tiện
Faculty : Công nghệ thông tin
Completed Date: Thi 2, 23/09/2024
Trang 2
NHAN XET CUA GIAO VIÊN HUONG DAN
Diém lab report:
Trang 3LAB 3-1: IMAGE 1)Mục đích yêu cầu:
+Củng cố kiến thức cơ bản về IMAGE, các khái niệm về hệ màu,
độ phân giải,
+Tiếp cận thư viện xử lý image như PIL (pillow), opencv, các
API hỗ trợ,
2)Mở link sau:
https://neptune.ai/blog/pil-image-tutorial-for-machine-learning
3) Thuc hién:
o_ Tìm hiểu khai niém Essential PIL image concepts:
PIL Image
im = Image.open(
1@ im.show()|
Trang 4
o_ Tìm hiểu thuộc tinh BANDS (kénh: channels):
D:\DAPHUONGTIEN\THUCHANH\TUANS\
im = Image.open(
im show()
bands = im.getbands()
size = im.size
APHUONGTTEN\THUCHANH\TUAN5
TẢ
Console 1/A X
arnt Eo) Các kênh màu của ảnh: ('R', 'G' Kích thước của ảnh: (1929, 198)
o_ Tìm hiểu thuộc tính Size:
Trang 5D:\DAPHUONGTIEN\THUCHANH\TUANS\Lab_3.1.py
Created on Mon Sep 23 09:42:33 2924
@author: Huỳnh Vinh Phát
one
#Tìm hiểu khái niệm Es
im show()
print{ "Các kênh màu của ảnh: ",bands]
im size
print( "Kích thước của ảnh: ”,size)
In [9]: runfile( 'D: /DAPHUONGTIEN/THUCHANH/
TUANS/Lab_3.1.py', wdir='D: /DAPHUONGTIEN/
THUCHANH/TUAN5"')
In [19]:
o_ Tìm hiểu chức năng Loading and saving images
n H pe rv
ìm hiểu chức năng Loading and saving images TUANS/Lab_3.1.py’, wdi
save = im.save( 'D: /DAPHUONGTIEN/THUCHANH/DATA/family-guy.jpg') THUCHANH/TUANS ")
In [14]: runfile( 'D:/DAPHUONGTTEN/THUCHANH/ TUAN5/Lab_3.1.py", wdin= 'D:/DAPHUONGTTEN/ THUCHANH/TUAN5 ')
Các kênh màu của ảnh: ('R', 'G', 'B')
Kích thước của ảnh: (1929, 1689) Hình ảnh được lưu: None
Trang 6
o_ Tìm hiểu chức năng Reading from a string:
save = im.s
print( “Hình ảnh được Lưu:
base64
io
open("D: /DAPHUONGTIEN/THUCHANH/DATA/family-guy.jpg","rb") image: image_string = base64.b64encode(image.read())
image = io.BytesI0(base64.b64decode(image_ string) )
Image open( image)
D;\DAPHUONGTIEN\THUCHANH\TUAN5
ĐÓ ni
Usage
lo 4.1.7) eect eek week front of it, either on the Editor
Co
a
om i rad
c kénh mau Kích thước của ảnh Hình ảnh được lưu: None
o_ Tìm hiểu chức năng Convert to JPEG, Create JPEG thumbnails:
Trang 7
APHUONGTIEN\THUCHANH\TUANS\
Lab_3.1py Lab3.1(H).py X
# -*- coding: utf-8
Created on Mon Sep 23 16:47:44 2624
lf no argument is given, the construcior returns an empty
et Taree) tuple If iterable is specified the tuple is initialized from
iterable's items
If the argument is a tuple, the return value is the same
im = Image.open("D: /DAPHUONGTIEN/THUCHANH/DATA/family-guy jpg")
im thumbnai1 (size) Help Variable Explorer Plots
im save( 'D: /DAPHUONGTTEN/THUCHANH/DATA/ƒfamiLy-guy 3pg ' )|
Console 1/A runfi1e( 'D: /DAPHUONGTTEN/TI TUANS/123.py', wdir='D: /DAPHUONGTIEN, THUCHANH/TUANS ")
Tn [42]: runfile( 'D:/DAPHUONGTTEN/THUCHANH/
TUANS/123.py', wdir="D: /DAPHUONGTIEN/
THUCHANH/TUANS ")
'—
a Built-in imnutabie sequence
tmpzlmhyjui.P It no argument is given, the constructor returns an empty
tupte lf #erabie Is specified the tuple Is initialized from Reese ue
lf the argument is a tupie, the return value is the same
cÓ Help Variable Explorer Plots Flles
( *D: /DAPHUONGTTEN
'D: /DAPHUONGT+T
Rotation images, Merging images, Flip images:
> Cropping images:
Trang 8
im = Image.open("D: /DAPHUONGTIEN/THUCHANH/DATA/famiLly-guy.jpg")
box = (100, 150, 300, 300)
cropped_image = im.crop(box)
cropped_image.save( 'D: /DAPHUONGTIEN/THUCHANH/DATA/family-guy.jpg')
cropped_image.show()
.1.py X
FS) tmpmo24seko »
able sequencd
t is given, the
e is specified
b 1t is a tuple, thị
In Mon Lo
AX
file('D:/D) ', wdinz 'DÌ N5")
"107 N5') file('D:/D N5')
100%
Rotation images:
Trang 9D:\DAPHUONGTIEN\THUCHANH\TUANS \test.py
LĐ Lab_3.1.py X Lab3.1(tt).py X 123.pyX testpy
from PIL import Image
im = Image.open(
rotated = im.rotate(
rotated save(
rotated show()
: HU)
@ tmppjed0ych.P Oy = A aan
Built-in immutabie sequence
If no argument is given, the constructor returns an empty
tuple If iterable is specified the tuple is initialized from iterable's iterms
lf the argument is a tuple, the return value is the same object
Help Variable Explorer Plots Files
a Console 1/A X LH
runfi1e( 'D: /DAPHUOI t.py', wdir='F TUANE ') runfile( ‘'D: /DAPHU
„ Wdỉnz
5')
runfi1e( 'D: /DAPHUONGTT
» Wdir='D
5“)
Merging images:
Trang 10
o_ Tìm hiểu chức năng PIL image to numPy Array
o_ Tìm hiểu chức năng Color transformations:
4) Céng cu hé tro: Python programming language
a) Spyder IDE hoac PYTHON commandline
b) Cài đặt các thư viện hỗ trợ:
Câu lệnh cài đặt: pip install <gói cài đặt>
Vd: pip install opencv-python
pip install pillow
pip install matplotlib
ckages :
led numpy-1.24.4 op
(DaPhuongTien2) C:\Users\admin>,
Trang 11
(DaPhuongTien2) C:\Users\admin>pip install pillow
Collecting pillow
Downloading pillow-10.4.0-cp38-cp38-win_amd64.whl.metadata (9.3 kB)
Downloading pillow-10.4.0-cp38-cp38-win_amd64.whl (2.6 MB)
eta 0:00:00 Installing collected packages: pillow
Successfully installed pillow-10.4.0
(DaPhuongTien2) C:\Users\admin>
> Cài đặt thư viện (nếu chưa có): mở CMD trên Windows, gõ pip install simpleaudio, cài xong chạy python -> gỗ lệnh import
simpleaudio as sa kiểm tra lỗi
download/sample-jpg-download/ download file mẫu *.jpgvà lưu trong thư mục
> Mở notepad viết chương trình *.py lưu trong một thư mục{thường
là chung với thư mục của file Wav)
> Chạy thử code: >python baitap1.py
> Lưu các bài tập trong thư mục, nén và nộp (cuối giờ thực hành)