You are on page 1of 110

Image Processing

Robotic & Vision Lab RoVis


Counting Coins

• Counting coins is difficult because they touch each


other!
• Solution: Binarization and Erosion separates them!

Robotic & Vision Lab RoVis


19-Sep-19
Structuring Element (Kernel)
• Structuring Elements can have varying sizes
• Usually, element values are 0,1 and none(!)
• Structural Elements have an origin
• For thinning, other values are possible
• Empty spots in the Structuring Elements are don’t
care’s!
Box

Disc

19-Sep-19 Examples of stucturing elements


3

Robotic & Vision Lab RoVis


Erosion

Erosion is used for shrinking of element A by using


element B
With A and B as sets in Z 2 , the erosion of A by B, denoted A B,
defined
A B   z | ( B) Z  A
The set of all points z such that B, translated by z , is contained by A.

A B   z | ( B) Z  Ac  

Consider each foreground pixel in the input image


If the structuring element fits in, write a “1” at the origin of the
structuring element!

Robotic & Vision Lab RoVis


9/19/2019 4
Robotic & Vision Lab RoVis
Erosion

Robotic & Vision Lab RoVis


Example for Erosion

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0

Robotic & Vision Lab RoVis


19-Sep-19 7
Example for Erosion

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0

Robotic & Vision Lab RoVis


19-Sep-19 8
Example for Erosion

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0

Robotic & Vision Lab RoVis


19-Sep-19 9
Example for Erosion

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0

Robotic & Vision Lab RoVis


19-Sep-19 10
Example for Erosion

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0 1

Robotic & Vision Lab RoVis


19-Sep-19 11
Example for Erosion

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0 1 0

Robotic & Vision Lab RoVis


19-Sep-19 12
Example for Erosion

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0 1 0 0

Robotic & Vision Lab RoVis


19-Sep-19 13
Example for Erosion

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 0 0 0 0 1 0 0 0

Robotic & Vision Lab RoVis


19-Sep-19 14
Robotic & Vision Lab RoVis
Exercise
• Erode

Robotic & Vision Lab RoVis


9/19/2019 16
Example access matrix
for (int y = 0; y < output.rows; y++)
{
for (int x = 0; x < output.cols; x++)
{
Mat ROI = Mat output(Rect(Point(x, y), Size(3, 3))); //tao window
for (int i = 0; i < ROI.rows; i++)
{
for (int j = 0; j < ROI.cols; j++)
{
kiểm tra: ROI.at<uchar>(i, j)
}
}
}
}

Robotic & Vision Lab RoVis


Remember from previous Lecture:
GRAY LEVEL THRESHOLDING

Objects

Set threshold
here
9/19/2019 Introduction to Machine Vision
BINARY IMAGE
Problem here

How do we fill “missing pixels”?


9/19/2019 Introduction to Machine Vision
Dilation
• Dilation is used for expanding an element A by using structuring
element B
• Dilation of A by B and is defined by the following equation:

• This equation is based 0n obtaining the reflection 0f B


about its origin and shifting this reflection by z.
• The dilation of A by B is the set of all displacements z,
such that and A overlap by at least one element. Based
On this interpretation the equation of (9.2-1) can be
rewritten as:

Consider each pixel in the input image


If the structuring element touches the foreground image, write a “1” at the
origin of the structuring element!

Robotic & Vision Lab RoVis


void cv::erode (cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
cv::InputArray element, // Structuring, a cv::Mat()
cv::Point anchor = cv::Point(-1,-1), // Location of anchor point
int iterations = 1, // Number of times to apply
int borderType = cv::BORDER_CONSTANT // Border extrapolation
const cv::Scalar& borderValue = cv::morphologyDefaultBorderValue()
);

Hàm getStructuringElement():
cv::getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1));
Với:
 shape: Là hình dạng của phần tử cấu trúc. Ví dụ: MORPH_RECT. Bạn có thể tham
khảo các loại hình dạng của phần tử cấu trúc trong cv::MorphShapes.
 ksize: Là kích thước của ma tận phần tử cấu trúc.
 anchor: Là điểm neo của phần tử cấu trúc. Giá trị mặc định là (-1, -1).

Robotic & Vision Lab RoVis


Robotic & Vision Lab RoVis
Example for Dilation

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1

Robotic & Vision Lab RoVis


19-Sep-19 23
Example for Dilation

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0

Robotic & Vision Lab RoVis


19-Sep-19 24
Example for Dilation

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1

Robotic & Vision Lab RoVis


19-Sep-19 25
Example for Dilation

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1

Robotic & Vision Lab RoVis


19-Sep-19 26
Example for Dilation

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1 1

Robotic & Vision Lab RoVis


19-Sep-19 27
Example for Dilation

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1 1 1

Robotic & Vision Lab RoVis


19-Sep-19 28
Example for Dilation

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1 1 1 1

Robotic & Vision Lab RoVis


19-Sep-19 29
Example for Dilation

Input image 1 0 0 0 1 1 1 0 1 1

Structuring Element 1 1 1

Output Image 1 0 1 1 1 1 1 1

Robotic & Vision Lab RoVis


19-Sep-19 30
Robotic & Vision Lab RoVis
Dilation

Robotic & Vision Lab RoVis


Dilation : Bridging gaps

33
Robotic & Vision Lab RoVis
Exercise

Robotic & Vision Lab RoVis


9/19/2019 34
Mat image, dst;
image = imread("demcoin2.jpg",1);
// Create a structuring element
int erosion_size = 6;
Mat element = getStructuringElement(cv::MORPH_ERODE,
cv::Size(2 * erosion_size + 1, 2 * erosion_size + 1),
cv::Point(erosion_size, erosion_size));
// Apply erosion or dilation on the image
erode(image, dst, element);
namedWindow("Display window", CV_WINDOW_AUTOSIZE);
imshow("Display window", image);
namedWindow("Result window", CV_WINDOW_AUTOSIZE);
imshow("Result window", dst);
waitKey(0);
return 0;

Robotic & Vision Lab RoVis


Useful

• erosion
• removal of structures of certain shape and size, given by
SE
• Dilation
• filling of holes of certain shape and size, given by SE

36
Robotic & Vision Lab RoVis
Exercise

• A) erode by hand
• B) erode by programing do not use erode function
• C) using erode function to compare
• D) dilate by hand
• E) dilate by programing do not use dilate function
• F) using dilate function to compare

Robotic & Vision Lab RoVis


Opening

Erosion followed by dilation, denoted ∘

A  B  ( A  B )  B
• First – erode A by B, and then dilate the result by B
First – erode A by B, and then dilate the result by B
• eliminates protrusions
• breaks necks
• smoothes contour
In other words, opening is the unification of all B objects
Entirely Contained in A

38
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Opening

• Structuring element: 3x3 square

Robotic & Vision Lab RoVis


19-Sep-19 41
Opening Example

• Opening with a 11 pixel diameter disc

Robotic & Vision Lab RoVis


19-Sep-19 42
Opening Example

• 3x9 and 9x3 Structuring Element

3*9

9*3

Robotic & Vision Lab RoVis


19-Sep-19 43
Opening on Gray Value Images

• 5x5 square structuring element

Robotic & Vision Lab RoVis


19-Sep-19 44
Use Opening for Separating Blobs

• Use large structuring element that fits into the big


blobs
• Structuring Element: 11 pixel disc

Robotic & Vision Lab RoVis


19-Sep-19 45
Exercise opening

Robotic & Vision Lab RoVis


Closing

dilation followed by erosion, denoted •

A  B  ( A  B)  B
First – dilate A by B, and then erode the result by B
• smooth contour
• fuse narrow breaks and long thin gulfs
• eliminate small holes
• fill gaps in the contour
In other words, closing is the group of points, which the
intersection of object B around them with object A – is not
empty
47
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Closing

• Structuring element: 3x3 square

Robotic & Vision Lab RoVis


19-Sep-19 50
Closing Example

• Closing operation with a 22 pixel disc


• Closes small holes in the foreground

Robotic & Vision Lab RoVis


19-Sep-19 51
Closing Example 1

1. Threshold
2. Closing with disc of size 20

19-Sep-19
Thresholded closed
52
Robotic & Vision Lab RoVis
A) open by hand
B) open by programing do not use morphologyex function
C) using morphologyex function to compare
D) close by hand
E) close by programing do not use morphologyex function
F) using close function to compare

Robotic & Vision Lab RoVis


Using opening to remove the line

Robotic & Vision Lab RoVis


Closing Gray Value Images

• 5x5 square structuring element

Robotic & Vision Lab RoVis


19-Sep-19 55
Hàm cv::morphologyEx().
cv::morphologyEx( InputArray src, OutputArray dst, int op, InputArray kernel, Point anchor = Point(-1,-1
), int iterations = 1, int borderType = BORDER_CONSTANT, const Scalar& borderValue = morphologyDe
faultBorderValue());
Với
 src: Là ảnh ban đầu:
 dst: Là ảnh sau khi xử lý hình thái học.
 op: Là loại hình thái học, ví dụ: MORPH_ERODE. Bạn có thể tham khảo các loại phép toán hình thái
học trong cv::MorphTypes.
 kernel: Là phần tử cấu trúc. Bạn hoàn toàn có thể khởi tạo và sử dụng bằng cách sử dụng hàm getStruc
turingElement().
 anchor: Là điểm neo của phần tử cấu trúc kernel. Giá trị mặc định là (-1, -1).
 iterations: Số lần lặp đi lặp lại các phép toán hình thái học lên ảnh. Ví dụ: Bạn càng để phép toán giãn
nở ảnh (Dialation) thì ảnh càng giãn nở nhiều.
 borderType: BORDER_CONSTANT
 borderValue: Là giới hạn biên của những điểm ảnh (Pixel) nằm ngoài kích thước của ảnh trong quá t
rình tính toán.

Robotic & Vision Lab RoVis


Ví dụ 4.13: Sử dụng opencv để thực hiện các phép toán tử sau:

Opening Closing Tophat Gradient

Blackhat
Robotic & Vision Lab RoVis
createTrackbar("Operator:\n 0: Opening - 1: Closing \n 2: Gradient - 3: Top Hat \n 4: Black Hat",
window_name, &morph_operator, max_operator, Morphology_Operations);
/// Create Trackbar to select kernel type
createTrackbar("Element:\n 0: Rect - 1: Cross - 2: Ellipse", window_name, &morph_elem, max_elem,
Morphology_Operations);
/// Create Trackbar to choose kernel size
createTrackbar("Kernel size:\n 2n +1", window_name, &morph_size, max_kernel_size,
Morphology_Operations);
/// Default start
Morphology_Operations(0, 0);
waitKey(0);
return 0;
}
/**
* @function Morphology_Operations
*/
void Morphology_Operations(int, void*)
{
// Since MORPH_X : 2,3,4,5 and 6
int operation = morph_operator + 2;

Mat element = getStructuringElement(morph_elem, Size(2 * morph_size + 1, 2 * morph_size +


1), Point(morph_size, morph_size));
/// Apply the specified morphology operation
morphologyEx(src, dst, operation, element);
imshow(window_name, dst);
}
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Useful: open & close

60
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Some Basic Morphological Algorithms (1)

• Boundary Extraction
The boundary of a set A, can be obtained by first eroding A
by B and then performing the set difference between A and
its erosion.

 ( A)  A   A  B 

Robotic & Vision Lab RoVis


9/19/2019 62
Example 1

Robotic & Vision Lab RoVis


9/19/2019 63
Boubdary extracion

Robotic & Vision Lab RoVis


Example 2

Robotic & Vision Lab RoVis


9/19/2019 65
int erosion_size = 1;
Mat element = getStructuringElement(cv::MORPH_ERODE,
cv::Size(2 * erosion_size + 1, 2 * erosion_size + 1),
cv::Point(erosion_size, erosion_size));
// Apply erosion or dilation on the image
erode(image, dst, element);
cv::subtract(image, dst, dst);

Robotic & Vision Lab RoVis


Some Basic Morphological Algorithms (2)

• Hole Filling
A hole may be defined as a background region surrounded
by a connected border of foreground pixels.

Let A denote a set whose elements are 8-connected


boundaries, each boundary enclosing a background region
(i.e., a hole). Given a point in each hole, the objective is to
fill all the holes with 1s.

Robotic & Vision Lab RoVis


9/19/2019 67
Some Basic Morphological Algorithms (2)

• Hole Filling
1. Forming an array X0 of 0s (the same size as the array
containing A), except the locations in X0 corresponding to
the given point in each hole, which we set to 1.

c
2. Xk = (Xk-1 + B) A k=1,2,3,…

Stop the iteration if Xk = Xk-1

Robotic & Vision Lab RoVis


9/19/2019 68
Example

Robotic & Vision Lab RoVis


9/19/2019 69
Hold filling

Robotic & Vision Lab RoVis


9/19/2019 70
Robotic & Vision Lab RoVis
9/19/2019 71
Ví dụ 4.21: Tô đầy vùng các ký tự có lỗ trống

cv::Mat mask;
image_thresh.copyTo(mask);
for (int i = 0; i < mask.cols; i++) {
if (mask.at<char>(0, i) == 0) {
cv::floodFill(mask, cv::Point(i, 0), 255, 0, 10, 10);
}
if (mask.at<char>(mask.rows - 1, i) == 0) {
cv::floodFill(mask, cv::Point(i, mask.rows - 1), 255, 0, 10, 10);
}
}
for (int i = 0; i < mask.rows; i++) {
if (mask.at<char>(i, 0) == 0) {
cv::floodFill(mask, cv::Point(0, i), 255, 0, 10, 10);
}
if (mask.at<char>(i, mask.cols - 1) == 0) {
cv::floodFill(mask, cv::Point(mask.cols - 1, i), 255, 0, 10, 10);
}
}

Robotic & Vision Lab RoVis


HIT and MISS

Robotic & Vision Lab RoVis


9/19/2019 73
Hit-and-miss Transform

• Used to look for particular patterns of foreground


and background pixels
• Very simple object recognition
• All other morphological operations can be derived
from it!!
• Input:
• Binary Image
• Structuring Element, containing 0s and 1s!!

Robotic & Vision Lab RoVis


74
Robotic & Vision Lab RoVis
Hit-and-miss Transform
• Example for a Hit-and-miss Structuring Element
• Contains 0s, 1s and don’t care’s.
• Usually a “1” at the origin!

Robotic & Vision Lab RoVis


19-Sep-19 76
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
The Hit-or-Miss
Transformation

if B denotes the set composed of


D and its background,the match
(or set of matches) of B in A,
denoted A  B,
A * B   A  D    Ac  W  D  

B   B1 , B2 
B1 : object
B2 : background
A  B   A  B1   ( Ac  B2 )

Robotic & Vision Lab RoVis


9/19/2019 79
The Hit-or-Miss Transformation

Robotic & Vision Lab RoVis


Exercise hit and fit
in this case, we are looking for a pattern in which the central pixel belongs to the background
while the north, south, east, and west pixels belong to the foreground. The rest of pixels in the
neighbourhood can be of any kind, we don't care about them. Now, let's apply this kernel to an
input image:

Robotic & Vision Lab RoVis


Hàm cv::morphologyEx().
cv::morphologyEx( InputArray src, OutputArray dst, int op, InputArray kernel, Point anchor = Point(-1,-1
), int iterations = 1, int borderType = BORDER_CONSTANT, const Scalar& borderValue = morphologyDe
faultBorderValue());
Với
 src: Là ảnh ban đầu:
 dst: Là ảnh sau khi xử lý hình thái học.
 op: Là loại hình thái học, ví dụ: MORPH_ERODE. Bạn có thể tham khảo các loại phép toán hình thái
học trong cv::MorphTypes.
 kernel: Là phần tử cấu trúc. Bạn hoàn toàn có thể khởi tạo và sử dụng bằng cách sử dụng hàm getStruc
turingElement().
 anchor: Là điểm neo của phần tử cấu trúc kernel. Giá trị mặc định là (-1, -1).
 iterations: Số lần lặp đi lặp lại các phép toán hình thái học lên ảnh. Ví dụ: Bạn càng để phép toán giãn
nở ảnh (Dialation) thì ảnh càng giãn nở nhiều.
 borderType: BORDER_CONSTANT
 borderValue: Là giới hạn biên của những điểm ảnh (Pixel) nằm ngoài kích thước của ảnh trong quá t
rình tính toán.

Robotic & Vision Lab RoVis


#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
int main(){
Mat input_image = (Mat_<uchar>(8, 8) <<
0, 0, 0, 0, 0, 0, 0, 0,
0, 255, 255, 255, 0, 0, 0, 255,
0, 255, 255, 255, 0, 0, 0, 0,
0, 255, 255, 255, 0, 255, 0, 0,
0, 0, 255, 0, 0, 0, 0, 0,
0, 0, 255, 0, 0, 255, 255, 0,
0, 255, 0, 255, 0, 0, 255, 0,
0, 255, 255, 255, 0, 0, 0, 0);
Mat kernel = (Mat_<int>(3, 3) <<
0, 1, 0,
1, -1, 1,
0, 1, 0);
Mat output_image;
morphologyEx(input_image, output_image, MORPH_HITMISS, kernel);
const int rate = 50;
kernel = (kernel + 1) * 127;
kernel.convertTo(kernel, CV_8U);
resize(kernel, kernel, Size(), rate, rate, INTER_NEAREST);
imshow("kernel", kernel);
moveWindow("kernel", 0, 0);
resize(input_image, input_image, Size(), rate, rate, INTER_NEAREST);
imshow("Original", input_image);
moveWindow("Original", 0, 200);
resize(output_image, output_image, Size(), rate, rate, INTER_NEAREST);
imshow("Hit or Miss", output_image);
moveWindow("Hit or Miss", 500, 200);
waitKey(0);

Robotic & Vision Lab RoVis


return 0;
}
Kernel and output result for Kernel and output result for finding left
finding top-right corners end points

Robotic & Vision Lab RoVis


Robotic & Vision Lab RoVis
Basic
THINNING
Robotic & Vision Lab RoVis
9/19/2019 86
Thinning

1. Used to remove selected foreground pixels from


binary images

2. After edge detection, lines are often thicker than


one pixel.

3. Thinning can be used to thin those line to one


pixel width.

Robotic & Vision Lab RoVis


19-Sep-19 87
Definition of Thinning

• Let B be a kernel and A be an image

with 0-1=0!!
• If foreground and background fit the structuring
element exactly, then the pixel at the origin of the
SE is set to 0

• Note that the value of the SE at the origin is 1 or


don’t care!
Robotic & Vision Lab RoVis
19-Sep-19 88
Some Basic Morphological Algorithms (5)

• A more useful expression for thinning A symmetrically is


based on a sequence of structuring elements:

  
B  B1
, B 2
, B 3
,..., B n

where B i is a rotated version of B i -1

The thinning of A by a sequence of structuring element {B}


A  {B}  ((...(( A  B1 )  B 2 )...)  B n )

Robotic & Vision Lab RoVis


9/19/2019 89
Robotic & Vision Lab RoVis
9/19/2019 90
Ví dụ 4.18: Sử dụng kernel sau để làm mỏng hình

Kernel:

Robotic & Vision Lab RoVis


// seRight90
Mat seRight90 = getStructuringElement(MORPH_RECT, Size(3, 3));
data = { { { 0, 1, 0 },{ 1, 1, 0 },{ 0, 0, 0 } } };
seRight90 = Mat(3, 3, CV_8UC1, &data);
cout << "seRight90 = " << endl << " " << seRight90 << endl << endl;

Mat dum1 = dst_bin.clone();


morphologyEx(dst_bin, dum1, MORPH_HITMISS, seLeft0);
Mat dum3;
morphologyEx(dum1, dum3, MORPH_HITMISS, seRight0);
Mat dum5;
morphologyEx(dum3, dum5, MORPH_HITMISS, seLeft90);
Mat dum7;
morphologyEx(dum5, dum7, MORPH_HITMISS, seRight90);

cv::imshow("ketqua", dum7 * 255);


cout << endl;
cv::waitKey();
return 0;

Robotic & Vision Lab RoVis


Basic
THICKENING

Robotic & Vision Lab RoVis


9/19/2019 93
49/19/2019

Some Basic Morphological Algorithms (6)

• Thickening:

The thickening is defined by the expression


A B  A   A* B

The thickening of A by a sequence of structuring element {B}


A {B}  ((...(( A B1 ) B 2 )...) Bn )

In practice, the usual procedure is to thin the background of the set


and then complement the result.

Robotic & Vision Lab RoVis


59/19/2019

Some Basic Morphological Algorithms (6)

Robotic & Vision Lab RoVis


Example Thinning

We use two Hit-and-


miss Transforms

Robotic & Vision Lab RoVis


19-Sep-19 96
Skeleton
K
Gọi: S ( A)   S k ( A)
k 0

K  max{k | A  kB  };
Với
Sk ( A)  ( A  kB)  ( A  kB) B

Với B là kernel hay structure elements


( A kB )  ((..(( A B ) B ) ...) B)

Robotic & Vision Lab RoVis


Skeleton Finding via Distance Transform

• Distance transform: find the distance from


the nearest boundary for each point
- initialization
x0 (m, n)  x(m, n)
- iteration
xk (m, n)  xo (m, n)  min{xk 1 (i, j ) : d (m, n; i, j )  1}

Robotic & Vision Lab RoVis


98
Robotic & Vision Lab RoVis
Euclide Distance

Robotic & Vision Lab RoVis


Robotic & Vision Lab RoVis
Skeleton Finding via Distance Transform

• Skeleton is the set of points whose distance


from the nearest boundary is locally maximum

{(m, n) : xk (m, n)  xk (i, j ), d (m, n; i, j )  1}

Robotic & Vision Lab RoVis


102
Numerical Example

11111 11111 11111 1 1


11111 12221 12221 2 2
11111 12221 12321 3
11111 12221 12221 2 2
11111 11111 11111 1 1
x0(m,n) x1(m,n) x3(m,n) local skeleton
maximum

Robotic & Vision Lab RoVis


103
Image Example

original skeleton

MATLAB code: y=bwmorph(x,’skel’,inf);

Robotic & Vision Lab RoVis


104
Image Example (Con’t)

Binary fingerprint image Skeleton image

Robotic & Vision Lab RoVis


105
Thickening

• Used to grow selected regions of foreground pixels


• E.g. applications like approximation of convex hull

Robotic & Vision Lab RoVis


19-Sep-19 106
Definition Thickening

• Let B be a kernel and A be an image

with 1+1=1
• If foreground and background match exactly the SE,
then set the pixel at its origin to 1!
• Note that the value of the SE at the origin is 0 or
don’t care!

Robotic & Vision Lab RoVis


19-Sep-19 107
Example Thickening

Robotic & Vision Lab RoVis


19-Sep-19 108
Ví dụ 4.20: làm dày hình sau sử dụng các kernel

Kernel:

Hình 4.44 Hình và Kernel cho ví dụ 4.20

Robotic & Vision Lab RoVis


for (int iii = 0; iii < 10; iii++)
{
filter2D(dst_bin, dum, dst_bin.depth(), seLeft0);
filter2D(dum, dum, dst_bin.depth(), seRight0);
filter2D(dum, dum, dst_bin.depth(), seLeft90);
filter2D(dum, dum, dst_bin.depth(), seRight90);
filter2D(dum, dum, dst_bin.depth(), seLeft180);
filter2D(dum, dum, dst_bin.depth(), seRight180);
filter2D(dum, dum, dst_bin.depth(), seLeft270);
filter2D(dum, dum, dst_bin.depth(), seRight270);
cv::bitwise_and(dum, dum, dum);
}

Robotic & Vision Lab RoVis

You might also like