3

I have a image which I have binarized and the problem is I want to remove the white spots in that image which are not connected in a loop i.e. small white dots. The reason is I want to take a measurement of that section like shown here.

I have tried some OpenCV morphology functions like erode, open, close but the results are not what I require. I have also tried using canny edge but some diagonal lines which I want for some processing are also gone. here is the result of both thresh(left) and canny(right)

I have read that pruning is a process in which we remove pixels which are not connected but I don't know how it works? Is there a function in Opencv for that?

th3 = cv2.adaptiveThreshold(gray_img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) th3=~th3 th3 = cv2.dilate(th3, cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))) th3 = cv2.erode(th3, cv2.getStructuringElement(cv2.MORPH_RECT,(5,5))) edged = cv2.Canny(gray_img,lower,upper) 

1 Answer 1

2

This answer explains how to measure the diameter of the drill bit:

The first step is to read the image as 2 channel (grayscale) and find the edges using a Canny filter:

img = cv2.imread('/home/stephen/Desktop/drill.jpg',0) canny = cv2.Canny(img, 100, 100) 

canny

The edges of the drill using np.argmax():

diameters = [] # Iterate through each column in the image for row in range(img.shape[1]-1): img_row = img[:, row:row+1] start = np.argmax(img_row) end = np.argmax(np.flip(img_row)) diameters.append(end+start) a = row, 0 b = row, start c = row, img.shape[1] d = row, img.shape[0] - end cv2.line(img, a, b, 123, 1) cv2.line(img, c, d, 123, 1) 

outline

The diameter of the drill in each column is plotted here:

diameters

All of this assumes that you have an aligned image. I used this code to align the image.

Sign up to request clarification or add additional context in comments.

3 Comments

That could help me for extracting some features from thread part but I couldn't understand the graph. What is x-axis and what is y-axis, what are the peaks and valleys. If you are kind enough to explain that, and can I find some thread features of drill bit with this algorithm. Consider me a noob
Please review my edits. I superimposed the drill bit in the graph image.
Sir I am not able to align my image like yours could you please tell me the steps you used in that code link?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.