Phát hiện lổ hổng trên tường

How to detect small holes in the wall
Phát hiện lổ hổng trên tường

The Mathematica Stack Exchange is really a gold mine for image processing learners like us. A few days ago there was someone posted a question about how to detect small holes in walls. I first thought it was a very difficult problem, but it turns out the solution in Mathematica consists only a few lines of code. And I’m really amazed with the brilliance of the Mathematica fellows there.

Trang Mathematica Stack Exchange thật sự là mỏ vàng để học xử lý ảnh. Ít ngày trước có người gửi câu hỏi “làm sao để phát hiện lổ nứt trên tường”. Đầu tiên tôi nghĩ đó là vấn đề rất khó, nhưng sau khi xem giải pháp ở Mathematica chỉ có vài dòng code. Tôi đã thực sự kinh ngạc với các nghiên cứu sinh Mathematica.

Take a look at the image below. There is a little damage on the wall that needs to be located.
Nhìn xem ảnh bên dưới, có vài hư hỏng trên tường cần được xác định.

wall_damage
Figure 1. Image of a wall with small damage. Ảnh bức tường có hư hỏng nhỏ

wall_damage_org_1

wall_damage_org_2

wall_damage_org_3

wall_damage_org_4

For more samples, see the original images from MSE: image1, image2, image3,image4. I will be using those images for testing my code below.
Để có nhiều mẫu hơn thì xem các ảnh trên. Tôi sẽ dùng các ảnh này để thử code

A simple and short Mathematica code is given to solve this problem:
Code ở Mathematica đơn giản và ngắn:

Basically the code threshold the images, perform distance transform and find the peaks, then enlarge the contours with dilation. All of the required algorithm is available in OpenCV so I tried to port the code to Python.

Căn bản là code này phân ngưỡng ảnh, thực hiện phép DistanceTransform và tìm đỉnh, rồi mở rộng biên với phép giãn nở. Tất cả thuật toán cần dùng OpenCV đều có nên tôi đã thử chuyển qua Python.

The result is pretty amazing as shown below.
Kết quả đẹp 1 cách đáng kinh ngạc.

wall_detected_hole

Figure 2. The result of the program. Kết quả của chương trình

Nguồn http://opencv-code.com/tutorials/how-to-detect-small-holes-in-the-wall/

Leave a Reply