Extracting features from grain images, of different aspect ratio

Viewed 73

Context:

  1. This image is taken from far away : Eg1
  2. This image is taken from closer : Eg2
  3. This image is taken from really close : Eg3

This is mainly because of the Threshold I have set, if A < 300 or A > 1800: continue

def Cluster(I):
    I_detected = np.copy(I)
    contours, _ = cv2.findContours(I_detected, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

    num = 0
    grain_coord = []
    area = []
    perimeter = []
    for c in contours:        
        A = cv2.contourArea(c)
        if A < 300 or A > 1800: 
            continue
        print(num, A)
        num += 1

        minAreaRect = cv2.minAreaRect(c)
        rectCnt = np.int64(cv2.boxPoints(minAreaRect))
        cv2.drawContours(I_detected, [rectCnt], 0, (0,0,0), 2)
        P = cv2.arcLength(c, closed=True)

        grain_coord.append(rectCnt)
        area.append(A)
        perimeter.append(P)

    return I_detected, num, np.array(grain_coord), area, perimeter

This Threshold is important as if I set the threshold to vary a lot then it will pick up the other grains too but then the features that I am trying to extract from the grains will also vary quite a bit. Like follows :

  1. Eg2.1
  2. Eg3.1

These are the same images but with Threshold set to : if A < 300 or A > 3500: continue

And the results/features are as follows:

Issue:

Focus on the first 4 columns of each result.

Result1 & Result2 have deviation mainly in area and perimeter whereas the height and width dont differ much.

Result3 is completly different and has drastic differences in all 4 parameters.

Question:

Is there a way in which I dont have to worry about the distance from where the image is taken and still get minimum variation in the extracted features?

I am just looking for a way to resolve this or to get some alternate methods of approaching this.

0 Answers
Related