Exemplo n.º 1
0
import matplotlib.pyplot as plt

from pyxvis.processing.segmentation import seg_bimodal
from pyxvis.features.extraction import extract_features
from pyxvis.io.plots import plot_ellipses_image

img = plt.imread('../images/N0006_0003b.png')  # input image with a fruit
R, _, = seg_bimodal(img)  # segmentation
fxell = extract_features('ellipse', bw=R)  # extraction of elliptical features
print('Elliptical Features:')  # show results
print(fxell)  # print elliptical features
plot_ellipses_image(img, fxell)  # draw ellipse onto image
Exemplo n.º 2
0
import matplotlib.pyplot as plt
from skimage.measure import label
from pyxvis.features.extraction import extract_features

fig    = plt.figure()
ax     = fig.add_subplot(111)
img    = plt.imread('../images/N0001_0004b.png')
implot = plt.imshow(img,cmap='gray')    
R      = img>0.27     # segmentation
L      = label(R)     # labeling
n      = np.max(L)    # number of segmented regions
t      = 0
T      = np.zeros((n,6))
for i in range(n):
    R = (L == i)*1    # binary image of object i
    f = extract_features('basicgeo',bw=R)
    area = f[4]
    # recognition of fruits according to the size
    if area>14000 and area<21000:
        # extract int features only in the segmented region
        h      = extract_features('basicint',img=img,bw=R)
        T[t,:] = h
        t = t+1
        ax.text(f[1]-20, f[0]+10, str(t), fontsize=12,color='Red')
plt.show()
F = T[0:t,:]
print('Basic Int-Features:')
print(F)
np.save('IntFeatures.npy',F) # save features

Exemplo n.º 3
0
fig = plt.figure()
ax = fig.add_subplot(111)
img = plt.imread('../images/N0001_0004b.png')
img[100:399, 750:849] = 0.5
img[500:699, 850:916] = 0.75
img[20:119, 100:399] = 0.6
img[90:156, 1000:1199] = 0.75
implot = plt.imshow(img, cmap='gray')
R = img > 0.27  # segmentation
L = label(R)  # labeling
n = np.max(L)  # number of segmented objects
t = 0
T = np.zeros((n, 7))
for i in range(n):
    R = (L == i) * 1  # binary image of object i
    fx = ['basicgeo', 'hugeo']
    f = extract_features(fx, bw=R)  # feature extraction
    area = f[4]
    # recognition of fruits according to the size
    if area > 10000 and area < 31000:
        h = f[18:]  # hu moments
        T[t, :] = h
        t = t + 1
        x = round(1000 * h[0])  # first hu moment
        ax.text(f[1] - 20, f[0] + 10, str(int(x)), fontsize=12, color='Red')
plt.show()
F = T[0:t, :]
print('Hu Features:')
print(F)
np.save('HuFeatures.npy', F)  # save features
Exemplo n.º 4
0
from pyxvis.processing.images import gradlog
from skimage.measure import label
from pyxvis.features.extraction import extract_features

img = plt.imread('../images/small_wheel.png')  # input image with a defect
(N, M) = img.shape
e = gradlog(img, 1.25, 4 / 250)
L = label(~e)  # labeling of objects
n = np.max(L)  # number of detected objects

K1 = np.zeros((N, M), dtype=bool)
K2 = np.zeros((N, M), dtype=bool)
# Analysis of each segmented object
for i in range(n):
    R = (L == i)  # binary image of object i
    f = extract_features('basicgeo',
                         bw=R * 1)  # feature extraction for object i
    area = f[4]
    # recognition of potential defects according to the size
    if area > 20 and area < 40:
        K1 = np.bitwise_or(K1, R)
        i0 = int(round(f[0]))
        j0 = int(round(f[1]))
        h = int(round(f[2] / 2))
        w = int(round(f[3] / 2))
        i1 = max(i0 - h, 0)
        j1 = max(j0 - w, 0)
        i2 = min(i0 + h, N - 1)
        j2 = min(j0 + w, M - 1)
        I = img[i1:i2, j1:j2]
        bw = R[i1:i2, j1:j2]
        x = extract_features('contrast', img=I, bw=bw)
Exemplo n.º 5
0
fig = plt.figure()
ax = fig.add_subplot(111)
img = plt.imread('../images/N0001_0004b.png')
implot = plt.imshow(img, cmap='gray')

# Segmentation
R = img > 0.27  # thresholding of light objects
L = label(R)  # labeling of objects
n = np.max(L)  # number of detected objects
T = np.zeros((n, 18))  # features of each object will stored in a row

# Analysis of each segmented object
t = 0  # count of recognized fruits
for i in range(n):
    R = (L == i) * 1  # binary image of object i
    f = extract_features('basicgeo', bw=R)  # feature extraction for object i
    area = f[4]
    # recognition of fruits according to the size
    if area > 14000 and area < 21000:
        T[t, :] = f  # storing the features of the fruit t
        t = t + 1
        # labeling each recognized fruit in the plot
        ax.text(f[1] - 20, f[0] + 10, str(t), fontsize=12, color='Red')

# Display and save results
plt.show()
F = T[0:t, :]
print('Basic Geo-Features:')
print(F)
np.save('GeoFeatures.npy', F)  # save features
Exemplo n.º 6
0
from skimage.measure import label

img = plt.imread('../images/small_wheel.png')  # input image with a defect
(N, M) = img.shape
e = gradlog(img, 1.25, 4 / 250)
L = label(~e)  # labeling of objects
n = np.max(L)  # number of detected objects

K1 = np.zeros((N, M), dtype=bool)
K2 = np.zeros((N, M), dtype=bool)

# Analysis of each segmented object
for i in range(n):
    R = L == i  # binary image of object i
    f = extract_features('basicgeo',
                         bw=R * 1)  # feature extraction for object i
    area = f[4]

    # recognition of potential defects according to the size
    if area > 10 and area < 40:
        K1 = np.bitwise_or(K1, R)
        i0 = int(round(f[0]))
        j0 = int(round(f[1]))
        h = int(round(f[2] / 2))
        w = int(round(f[3] / 2))
        i1 = max(i0 - h, 0)
        j1 = max(j0 - w, 0)
        i2 = min(i0 + h, N - 1)
        j2 = min(j0 + w, M - 1)
        I = img[i1:i2, j1:j2]
        x = extract_features('clp', img=I)