Professional Documents
Culture Documents
ẢNH
EDGE DETECTION AND
SEGMENTATION
• Ñeå ñôn giaûn vaán ñeà, bieåu ñoà Histogram ñöôïc bieán ñoåi vaø
xem nhö laø moät phaân boá xaùc xuaát:
I = imread('coins.png');
imshow(I)
level = graythresh(I);
BW = im2bw(I,level);
figure, imshow(BW)
I = imread('rice.png');
BW = imbinarize(I,
'adaptive');
figure
imshowpair(I,BW,'mo
ntage')
Các phép tính đạo hàm được thay bằng các tích chập
với các mặt nạ phù hợp
TS NGUYỄN ĐỨC THÀNH 35
TS NGUYỄN ĐỨC THÀNH 36
• Tách cạnh gồm ba giai đoạn: lọc, vi phân và so
ngưỡng
• Vi phân thường dùng lọc trung bình hay lọc
Gauss
Lọc Prewitt tính toán đơn giản hơn lọc Sobel nhưng kết
quả không trơn bằng
• Tìm θ và ρ
• Ảnh xám có thể xem như một bề mặt có chỗ cao chỗ thấp, chỗ
thấp là lưu vực (catchment basin) nơi các con sông chảy
xuống, đường phân thủy phân chia ranh giơi lưu vực, các con
sông phát xuất từ đường phân thủy chảy ra hai bên. Các lưu
vực chính là các vùng ảnh và đường phân thủy là ranh giới các
vùng, để tìm đường phân thủy ta cho nước dâng lên cho đến
khi các hồ giao nhau , đường phân thủy vẽ đường ranh giới
giữa các vùng chạm nhau
• Để biểu thị độ cao các vùng trũng ta dùng biến đổi khoảng
cách, giả sử nền ảnh đen trắng là đen (0) các vùng có gía trị
trắng (1), ta lấy đảo ảnh, sau đó dùng biến đổi khoảng cách,
các pixel giá trị 1 được thay bằng 0.0, các pixel giá trị 0 được
thay bằng khoảng cách đến pixel giá trị 1 gần nhất
TS NGUYỄN ĐỨC THÀNH 93
PHÂN ẢNH DỰA VÀO ĐƯỜNG PHÂN THỦY
(WATERSHED)
gmag =
imgradient(I);
imshow(gmag,[]
)
title('Gradient
Magnitude')
se = strel('disk',20);
Io = imopen(I,se);
imshow(Io)
title('Opening')
Ioc =
imclose(Io,se);
imshow(Ioc)
title('Opening-
Closing')
fgm =
imregionalmax(Iobrc
br);
imshow(fgm)
title('Regional
Maxima of Opening-
Closing by
Reconstruction')
TS NGUYỄN ĐỨC THÀNH 111
To help interpret the result, superimpose the
foreground marker image on the original image
I2 =
labeloverlay(I,fgm);
imshow(I2)
title('Regional
Maxima
Superimposed on
Original Image')
fgm4 =
bwareaopen(fgm3,2
0);
I3 =
labeloverlay(I,fgm4);
imshow(I3)
title('Modified
Regional Maxima
Superimposed on
Original Image') TS NGUYỄN ĐỨC THÀNH 114
Now you need to mark the background. In the cleaned-up image,
Iobrcbr, the dark pixels belong to the background, so you could
start with a thresholding operation.
bw =
imbinarize(Iob
rcbr);
imshow(bw)
title('Threshol
ded Opening-
Closing by
Reconstructio
n')
L=
watershed(gm
ag2);
Lrgb =
label2rgb(L,'jet','w','shuffle
');
imshow(Lrgb)
title('Colored Watershed
Label Matrix')
TS NGUYỄN ĐỨC THÀNH 119
You can use transparency to superimpose this pseudo-color label
matrix on top of the original intensity image.
figure
imshow(I)
hold on
himage =
imshow(Lrgb);
himage.AlphaData =
0.3;
title('Colored Labels
Superimposed
Transparently on
Original Image') TS NGUYỄN ĐỨC THÀNH 120
CONTOUR ĐƯỜNG BAO
• A contour is a list of points that represent, in one way or
another, a curve in an image.
• The function cv::findContours() computes contours from
binary images. It can take images created by cv::Canny(),
which have edge pixels in them, or images created by
functions like cv::threshold() or cv::adaptiveThreshold(), in
which the edges are implicit as boundaries between positive
and negative regions.
Hierarchy is the output that describes the tree structure of the contours. The
output hierarchy will be an array with one entry for each contour in contours.
Each such entry will contain an array of four elements, each indicating the node
to which a particular link from the current node is connected
m00 là diện tích các phần ảnh khác 0, với contour m00 là
chiều dài contour,
m10/m00 và m01/m00 là tọa độ trọng tâm (x,y) của phần
diện tích đường bao
Central moments
• https://drive.google.com/file/d/0B7lDtwez94H
3MWZlMGQwOTUtODk2Ni00NmNmLWI3
NTUtNjA4MTY2NTc5NDk0/view
• https://dev.to/amarlearning/finger-detection-
and-tracking-using-opencv-and-python-586m