Tải bản đầy đủ (.pdf) (26 trang)

đề thi và đáp án xử lý ảnh trong công nghiệp

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.5 MB, 26 trang )

TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT
THÀNH PHỐ HỒ CHÍ MINH
KHOA CƠ KHÍ CHẾ TẠO MÁY
BỘ MƠN CƠ ĐIỆN TỬ

ĐÁP ÁN CUỐI KỲ HK I NĂM HỌC 2018-2019
Môn: XỬ LÝ ẢNH CƠNG NGHIỆP
Mã mơn học: IIPR422529
-------------------------------

-------------------------

Câu 1: (3đ)
Xây dựng và cài đặt thuật toán cân bằng histogram tự động. (2đ)
Tại sao cân bằng histogram lại làm cho ảnh đẹp hơn? (1đ)
Đáp án:
Mục đích của cân bằng histogram là làm cho histogram đồng đều. Khi đó ta làm tăng được độ
tương phản của ảnh.
Cân bằng histogram được cho bằng phương trình:
r

s=T(r)=(L-1)  p r ( w)dw
0

với pr(w) : Xác suất xảy ra mức xám w
Trong xác suất, tích phân của hàm mật độ là hàm phân phối. Cơng thức trên có w là biến liên tục,
ta khơng thể lập trình nó. Ta phải dùng công thức rời rạc:
k

sk=T(rk)=(L-1)  p r (r j )
j 0



với k= 0,1,2,…,L-1
void HistogramEqualization(Mat imgin, Mat imgout)
{
int M = imgin.size().height;
int N = imgin.size().width;
int x, y;
int r, h[L];
for (r=0; rh[r] = 0;
for (x=0; xfor (y=0; yr = imgin.at<uchar>(x,y);
h[r]++;
}
double p[L];
for (r=0; rp[r] = (double)h[r]/(M*N);
double s[L];
int j, k;
for (k=0; ks[k] = 0;
for (j=0; j<=k; j++)
s[k] += p[j];

Số hiệu: BM1/QT-PĐBCL-RĐTV

Trang 1/5



s[k] *= L-1;
}
for (x=0; xfor (y=0; yr = imgin.at<uchar>(x,y);
imgout.at<uchar>(x,y) = (uchar)s[r];
}
return;
}

Câu 2: (4đ)
Xây dựng và cài đặt thuật toán loại bỏ các hạt gạo nhỏ hơn 90% hạt gạo lớn nhất, tức là
trong ảnh chỉ còn lại những hạt gạo lớn.

Đáp án:
void RemoveSmallRice(Mat imgin, Mat imgout)
{
// B1
Mat w1 = getStructuringElement(MORPH_ELLIPSE, Size(81, 81));
morphologyEx(imgin, imgout, MORPH_TOPHAT, w1);
// B2
threshold(imgout, imgout, 50, 255, THRESH_BINARY | THRESH_OTSU);
medianBlur(imgout, imgout, 3);
// B3
int M = imgout.size().height;
int N = imgout.size().width;
int x, y, dem = 0;
int r;
int color = 150;
for (x = 0; x < M; x++)

for (y = 0; y < N; y++)
{
r = imgout.at<uchar>(x, y);
if (r == L - 1)
{
floodFill(imgout, Point(y, x), CV_RGB(color, color, color));
dem++;
color++;
}
}

Số hiệu: BM1/QT-PĐBCL-RĐTV

Trang 2/5


// B4
int a[L];
for (r = 0; r < L; r++)
a[r] = 0;
for (x = 0; x < M; x++)
for (y = 0; y < N; y++)
{
r = imgout.at<uchar>(x, y);
if (r > 0)
a[r]++;
}
int max = 0;
for (r=0; rif (a[r] > max)

max = a[r];
max = (int)(max*0.9);
// B5
for (r = 0; rif (a[r] < max)
a[r] = 0;
dem = 0;
for (r = 0; r < L; r++)
if (a[r] > 0)
dem++;
for (x = 0; x < M; x++)
for (y = 0; y < N; y++)
{
r = imgout.at<uchar>(x, y);
if (a[r] == 0)
imgout.at<uchar>(x, y) = 0;
else
imgout.at<uchar>(x, y) = L - 1;
}
char s[5];
sprintf(s, "%d", dem);
putText(imgout, s, Point(0, 30), CV_FONT_HERSHEY_SIMPLEX, 0.8, CV_RGB(255, 255,
255));
return;
}

Câu 3: (1.5đ)
Given the deep learning convolutional neural networks shown in the following figure:

Số hiệu: BM1/QT-PĐBCL-RĐTV


Trang 3/5


a. Determine the number of parameters of filters (do not include the bias node) in the
convolutional layers. (0.75 points)
b. Determine the number of weights of the fully connected layer. (0.75 points)
Answer:
a.
Convolution 1: 5x5x32 = 800
Convolution 2: 5x5x32x64 = 51.200
Sum: 800 + 51.200 = 52.000 parameters
b.
7x7x64 = 3.132
3.132x1024 = 3.211.264
1.024x10 = 10.240
Sum: 3.211.264 + 10.240 = 3.221.504 weights
Câu 4: (1.5đ)
Given the input image and the filter shown in the following figure:

Số hiệu: BM1/QT-PĐBCL-RĐTV

Trang 4/5


a. Determine the size of the output image if zero-padding is 0 and stride is 2. (0.5
points)
b. Compute the output image as the convolution of the input image and the filter. (1.0
points)
Answer:

a. Wout = (W-F+2P)/S + 1 = (7-3+2*0)/2 + 1 = 3, therefore the size of output image
is 3x3
b.
108 126 144
288 306 324
468 486 504
-----------------------HẾT------------------Ngày 14 tháng 1 năm 2019
Giáo viên
Trần Tiến Đức

Số hiệu: BM1/QT-PĐBCL-RĐTV

Trang 5/5


RU'CSNG DAI HOC SU' PHAM KY THUAT
THANH PHO HO CHI MINH
KHOA CO KHI CHE TAO MAY
BO MON C O DIENTtT

DAP AN CUOI KY HK I NAM HOC 2019-2020
Mon: Xff LY ANH CONG NGHlEP
MS mon hoc: IIPR422529
Be so: 01 Be thi co 02 trang
Ng^ythi: 16/12/2019
Thai gian: 75 phut.
Buoc phep su dung tai lieu giay

Cau 1: (2d)
Xay dung va cai dat thuat toan lam tang do net cua anh bang mat na Laplace. (1.5d)

Tai sao mat na Laplace lai lam tang do net cua anh? (0.5d)
Dap an:
void Sharpen2(Mat imgin, Mat imgout)
{
Mat temp = Mat(imgin.size(),CV_32FCl);
Mat w = (Mat_<float>(3,3) « 1,1,1,1,-8,1,1,1,1);
filter2D(imgin,temp,CV_32FC 1,w);
int M - imgin.size().height;
int N = imgin.size().width;
int x, y;
float r;
for (x=0; xfor (y=0; yr = imgin.at<uchar>(x,y) - temp.at<float>(x,y);
if (r < 0)
r = 0;
if (r > L-l)
r = L-l;
imgout.at<uchar>(x,y) = (uchar)r;
}
return;

Cau 2: (3d)
Xay dung va cai dat thuat toan loai bo cac hat gao nho hon 90% hat gao lan nhat, tuc la
trong anh chi con lai nhirng hat gao lan.

Trang 1/5


Dap an:

void RemoveSmallRice(Mat imgin, Mat imgout)

{

// B1
Mat wl = getStructuringElement(MORPH_ELLIPSE, Size(81, 81));
morphologyEx(imgin, imgout, MORPH_TOPHAT, w l);
// B2
threshold(imgout, imgout, 50, 255, THRESH_BINARY | THRESH_OTSU);
medianBlur(imgout, imgout, 3);
// B3
int M = imgout.size().height;
int N = imgout.sizeQ. width;
int x, y, dem = 0;
int r;
int color = 150;
for (x = 0; x < M; x++)
for (y = 0; y < N; y++)

{
r = imgout.at<uchar>(x, y);
if (r == L - 1)

{

i/

floodFill(imgout, Point(y, x), CV_RGB(color, color, color));
dem-H-;
color++;


}

// B4
int a[L];
for (r = 0; r < L; r++)
a[r] = 0;
for (x = 0; x < M; x++)
for (y = 0 ;y < N ;y -H -)

{
r = imgout.at<uchar>(x, y);
if (r > 0)
a[r]++;

}
int max = 0;
for (r=0; rif (a[r] > max)
max = afr];
max = (int)(max*0.9);

// B5
for (r = 0; rif (a[r] < max)
a[r] = 0;
dem = 0;
for (r = 0; r < L; r++)

Trang 2/5



if (a[r] > 0)
dem++;
for (x = 0; x < M; x++)
for (y = 0; y < N; y++)

{
r = imgout.at<uchar>(x, y);
if (a[r] = 0)
imgout.at<uchar>(x, y) = 0;
else
imgout.at<uchar>(x, y) = L - 1;

}
char s[5];
sprintf(s, "%d", dem);
putText(imgout, s, Point(0, 30), CV_FONT HERSHEY SIMPLEX, 0.8, CV RGB(255, 255,
255));
return;

Cau 3: (3d)

Ta dinh nghTa mang na-ron chap dung de nhan dang 10 chu so viet tay co kfch thuoc 28x28
nhtr sau:
def build(input_shape, classes):
model = Sequential()
# CONV => RELU =» POOL
model.add(Conv2D(20, kerne l_size=5, padding=”same",
input_shape=input_shape))

model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
# CONV => RELU => POOL
model.add(Conv2D(50, kernel_size=5, padding="same"))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size:=(2, 2), strides=(2, 2)))
# Flatten => RELU layers
model. add(Flatten())
model.add(Dense(500))
model.add(Activation("relu"))
# a softmax classifier
model.add(Dense(classes))
model.add(Activation("softmax"))
a. Hay ve so do khoi cua mang nof-ron chap tren.
b. Cho biet so luong tham so cua cac bo loc trong cac lop chap (co tmh nut bias).
c. Cho biet so luong trong so cua lap ket noi day du (co tinh nut bias)
Dap an:

Trang 3/5


activation_l (Activation)

(None, 20, 28, 28)

0

uax_pooling2d_l (MaxPooling2 (None, 20, 14, 14)

0


conv2d_2 (Conv2D)

(None, 50, 14, 14)

25050

activation_2 (Activation)

(None, 50, 14, 14)

0

nax_pooling2d_2 (MaxPooling2 (None, 50, 7, 7)

0

flatten_l (Flatten)

(None, 2450)

0

dense_l (Dense)

(None, 500)

1225500

activation_3 (Activation)


(None, 500)

0

dense_2 (Dense)

(None, 10)

activation_4 (Activation)

(None, 10)

Total params: 1,256,080
Cau 4: (2d)
Given the input image and the filter shown in the following figure:

4
7
3
3
1

2
5
8
4
5
5


3
6
9
9
8
7

0
4
5
2
9
4

1
9
0
6
7
6

5
3
1
5
9
0

2


1

-2

0

0

-1

1

0

1

Trang 4/5


a. Determine the size of the output image if zero-padding is 0 and stride is 1. (0.5
points)
b. Compute the output image as the convolution of the input image and the filter. (1.5
points)
Dap an:
a. Wout =
is 4x4
b.
8
4
6

-8

(W-F+2P)/S + 1 = (6-3+2*0)/l + 1 = 4 , therefore the size of output image

16
9
27
13

4
13
32
14

-6
17
21
-5

------------------------ HET-------------------Ghi chu: Can bo coi thi khong giai thick de thi.

Ngay 23 thang 12 nam 2019
Thong qua bQ mon
(ky va ghi ro ho ten)

GV lam dap an
(ky va ghi ro ho ten)

T


I

Trang 5/5

/
O


T R U IN G DAI HOC SU' PHAM KY THUAT
th Anh ph6 ho chi' minh

KHOA CO KHI CHE TAO MAY
BO MON CO DIEN TU”

BE THI CUOI KY HK I NAM HOC 2019-2020
Mon: XU LY ANH CONG NGHIfiP
Ma mon hoc: IIPR422529
Be so: 01 Be thi co 02 trang
Ngaythi: 16/12/2019
Thai gian: 75 phut.
Buoc phep sir dung tai lieu giay

Cau 1: (2d)
Xay dung va cai dat thuat toan lam tang do net cua anh bang mat na Laplace. (2d)
Tai sao mat na Laplace lai lam tang do net cua anh? (0.5d)
Cau 2: (3d)
Xay dung va cai dat thuat toan loai bo cac hat gao nho hon 90% hat gao Ion nhdt, tire la
trong anh chi con lai tihung hat gao ldn.

Can 3: (3d)

Ta dinli nghia mang no-ron chap dung de nhan dang 10 chu so viet tay co kich thuoc 28x28
nhu sau:
def build(input_shape, classes):
model = Sequential)
# corn => RELU => POOL
model.add(Conv2D(20, kernel_size=5, padding="same",
input_shape=input_shape))
model. add(Activation("relu"))
model.add(M’axPooling2D(pool _size~-(2, 2), strides=(2, 2)))
# CONV => RELU => POOL
model.add(Conv2D(50, kernel_sizer-5, padding="same"))
model.add( Act ivati on (" re 1u"))
model.add(MaxPooling2D(pool__size~(2, 2), strides= (2. 2)))
H Flatten => R£LU layers
,in od e 1.a d d (F1a tten ())
model.add(Den.se( 5Of)))
mode! add(Aoiivation(v'reIn"))
A a soltmax classifier
model ,add( Dense(classes))
model. add(Activation("softmax'’))
S3 hicu- B M 1/QT- PDBCL-RDTV

Tranu 1/2


%

a. Hay ve so' do khoi cua mang no-ron chap tren.
b. Cho bi€t s6 lugng tham so cua cac bo loc trong cac lap chap (co tinh nut bias).
c. Cho biet so lugng trong so cua lop ket noi day du (co tinh nut bias)

Cau 4: (26)
Given the input' image and the filter shown in the following figure:
1

2

3

0

1

5

4

5

6

4

9

3

7

8


9

5

0

1

3

4

9

2

6

5

3

5

8

9

7


9

1

5

7

4

6

0

2

1

-2

0

0

-1

1

0


1

a. Determine the size of the output image if zero-padding is 0 and stride is 1. (0.5
points)
b. Compute the output image as the convolution of the input image and the filter. (1.5
points)
------------------------ HET-------------------Ghi chu: Can bo coi thi khong giai thick de thi.

Oman dau ra cua hoc phan (ve kien thuc)
fG 2.11: Nam duac cac phuang phap xic ly anh co ban
[G 2.2]: Tim duac phwongphap giai quyet mot so bai loan

Noi dong idem fra
Cau 1,3, 4
Cau 2

x u ly anh bang each ket hop mot hoac nhieu phuang phap
[G 3]: Hieu duoc cac thudl ngu tieng Anh co ban dung trong
xu ly anh

Cau 4

Ngay 8 thang 12 nam 2019
T hong qua bo mon

(ky va ghi ro ho ten)

C-

So hieu: BM1/QT-PBBCL-RBTV


Qui-cna
7

Trang 2/2















×