예제 #1
0
def test_lbp_names():
    f = np.random.random(size=(64, 72))
    f *= 255
    f = f.astype(np.uint8)

    for radius, points in [(8, 6), (8, 8), (6, 6), (8, 4), (12, 6)]:
        assert len(lbp(f, radius, points)) == len(lbp_names(radius, points))
예제 #2
0
def test_lbp_names():
    f = np.random.random(size=(64,72))
    f *= 255
    f = f.astype(np.uint8)

    for radius,points in [(8,6),
            (8,8),(6,6),(8,4),(12,6)]:
        assert len(lbp(f, radius, points)) == len(lbp_names(radius, points))
예제 #3
0
 def __init__(self, img):
     self.img = img#threadsHolding(img)
     #self.pixels = pixels  
     print("Extracting LBP...")
     self.lbpR1P8 = normalize(np.float32(lbp(self.img, 1, 8, ignore_zeros=False)))
     self.lbpR2P16 = normalize(np.float32(lbp(self.img, 2, 16, ignore_zeros=False)))
     self.lbpR3P16 = normalize(np.float32(lbp(self.img, 3, 16, ignore_zeros=False)))
     #self.lbpR3P24 = normalize(np.float32(lbp.lbp(self.img, 3, 24, ignore_zeros=False)))
     self.lbpR1P8_R2P16 = np.float32(np.concatenate([self.lbpR1P8, self.lbpR2P16]))
     self.lbpR1P8_R3P16 = np.float32(np.concatenate([self.lbpR1P8, self.lbpR3P16]))
     self.lbpR2P16_R3P16 = np.float32(np.concatenate([self.lbpR2P16, self.lbpR3P16]))
     
     #self.lbpR1P8pic = np.float32(lbp.lbp_transform(self.img, 1, 8, ignore_zeros=False))
     #self.lbpR2P16pic = np.float32(lbp.lbp_transform(self.img, 2, 16, ignore_zeros=False))
     #self.lbpR3P16pic = np.float32(lbp.lbp_transform(self.img, 3, 16, ignore_zeros=False))
     #self.lbpR3P24pic = np.float32(lbp.lbp_transform(self.img, 3, 24, ignore_zeros=False))
     
     '''
예제 #4
0
 def extractionFeatures(self, image_path):
     self.image_path = image_path
     try:
         img = Image.open(self.image_path).convert('RGB').convert('L')
         arrayFeatures = lbp(np.asanyarray(img), self.radius, self.n_points)
         return arrayFeatures
     except Exception as e:
         print(
             '\n################# (LBP) - Error in processing!  #################\n',
             e)
예제 #5
0
def extractImage(image_name):
    img = Image.open(image_name)
    data = numpy.asarray(img)
    x = data.shape[0]
    if len(data.shape) >= 3:
        y = data.shape[1] * data.shape[2]
    else:
        y = data.shape[1]
    data.resize((x, y))
    arr = lbp(data, 1.0, 10)
    return arr
예제 #6
0
 def extractionFeatures(self, image_path):
     self.image_path = image_path
     try:
         img = Image.open(self.image_path)
         imgRGB = img.convert('RGB')
         imgGray = imgRGB.convert('L')
         arrayFeatures = lbp(np.asanyarray(imgGray), self.radius,
                             self.n_points)
         return arrayFeatures
     except Exception as e:
         print(
             '\n################# (LBP) - Error Reading Image!  #################\n',
             e)
예제 #7
0
    def __init__(self, img):
        self.img = img  #threadsHolding(img)
        #self.pixels = pixels
        print("Extracting LBP...")
        self.lbpR1P8 = normalize(
            np.float32(lbp(self.img, 1, 8, ignore_zeros=False)))
        self.lbpR2P16 = normalize(
            np.float32(lbp(self.img, 2, 16, ignore_zeros=False)))
        self.lbpR3P16 = normalize(
            np.float32(lbp(self.img, 3, 16, ignore_zeros=False)))
        #self.lbpR3P24 = normalize(np.float32(lbp.lbp(self.img, 3, 24, ignore_zeros=False)))
        self.lbpR1P8_R2P16 = np.float32(
            np.concatenate([self.lbpR1P8, self.lbpR2P16]))
        self.lbpR1P8_R3P16 = np.float32(
            np.concatenate([self.lbpR1P8, self.lbpR3P16]))
        self.lbpR2P16_R3P16 = np.float32(
            np.concatenate([self.lbpR2P16, self.lbpR3P16]))

        #self.lbpR1P8pic = np.float32(lbp.lbp_transform(self.img, 1, 8, ignore_zeros=False))
        #self.lbpR2P16pic = np.float32(lbp.lbp_transform(self.img, 2, 16, ignore_zeros=False))
        #self.lbpR3P16pic = np.float32(lbp.lbp_transform(self.img, 3, 16, ignore_zeros=False))
        #self.lbpR3P24pic = np.float32(lbp.lbp_transform(self.img, 3, 24, ignore_zeros=False))
        '''
예제 #8
0
    def calculate(self, resource):
        #initalizing
        except_image_only(resource)

        image_uri = resource.image
        #image_uri = BQServer().prepare_url(image_uri, remap='gray')
        im = image2numpy(image_uri, remap='gray')
        im = np.uint8(im)

        #calculating descriptor
        radius = 5
        points = 5
        descriptor = lbp(im, radius, points)

        #initalizing rows for the table
        return descriptor
예제 #9
0
def compute_lbp(fname):
    '''
    Compute features for an image
    ------------------------------
    Parameters
    ----------
    fname : str
        filepath for image to process
    Returns
    -------
    ndarray
        linear binary patterns
    '''
    imc = mh.imread(fname)
    im = mh.colors.rgb2grey(imc)
    return lbp(im, radius=8, points=6)
예제 #10
0
def get_LBP(image, points, radius, method="default"):
    """
	Function to get Local Binary Pattern of an image based on given parameters
	:param image: OpenCV array_like of uint8
	:param points: int
		Number of circularly symmetric neighbour set points (quantization of the angular space).
	:param radius: float
		Radius of circle (spatial resolution of the operator).
	:param method: {‘default’, ‘ror’, ‘uniform’, ‘var’}
		Method to determine the pattern.
			‘default’: original local binary pattern which is gray scale but not rotation invariant.
			‘ror’: extension of default implementation which is gray scale and rotation invariant.
			‘uniform’: improved rotation invariance with uniform patterns and
				finer quantization of the angular space which is gray scale and rotation invariant.
			‘var’: rotation invariant variance measures of the contrast of local image texture
				which is rotation but not gray scale invariant.
	:return: LBP image array_like

	Example: get_LBP(image, radius=8, points=6)
	"""
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    return mfeats.lbp(image, points, radius, method)
예제 #11
0
def compute_lbp(fname):
    from mahotas.features import lbp
    imc = mh.imread(fname)
    im = mh.colors.rgb2grey(imc)
    return lbp(im, radius=8, points=6)
예제 #12
0
def local_binary_pattern_features(image):
    features = lbp(image, 3, 6)

    return features
예제 #13
0
def test_shape():
    A = np.arange(32 * 32).reshape((32, 32))
    B = np.arange(64 * 64).reshape((64, 64))
    features0 = lbp(A, 3, 12)
    features1 = lbp(B, 3, 12)
    assert features0.shape == features1.shape
예제 #14
0
def test_histogram_large():
    A = np.arange(32*32).reshape((32,32))
    for r in (2,3,4,5):
        assert lbp(A,r,12).sum() == A.size
예제 #15
0
 def run(self, img):
     from mahotas.features import lbp
     coeff = lbp(img, self._r, self._n)
     return coeff
예제 #16
0
def test_nonzero():
    A = np.arange(32 * 32).reshape((32, 32))
    features = lbp(A, 3, 12)
    features_ignore_zeros = lbp(A * (A > 256), 3, 12, ignore_zeros=True)
    assert features.sum() > 0
    assert not np.all(features == features_ignore_zeros)
예제 #17
0
def texture_features(texture):
    '''
    features = texture_features(texture)
    '''
    return features.lbp(texture, 8, 6, ignore_zeros=True)
예제 #18
0
    i_j_ux_uy4 = i_j_ux_uy4.ravel()

    feats[0] = np.dot(i_j2, pravel)
    feats[1] = np.dot(i_j_ux_uy3, pravel)
    feats[2] = np.dot(i_j_ux_uy4, pravel)
    rfeatures.append(feats)

# TODO: check again values (high enough to put me in doubt about it)
# TODO: how to check it?

# I already had done the for loop above, without vectorization,
# and the results were all the same but with a differences in the order of e-14.

rfeatures = np.array(rfeatures)
rfeatures_mean = rfeatures.mean(axis=0)

feats_glcm_6.append(rfeatures_mean[0])  # inertia
feats_glcm_6.append(rfeatures_mean[1])  # cluster shade
feats_glcm_6.append(rfeatures_mean[2])  # cluster prominence

# TODO: LBP feature

# Não entendi porque points é flexível
#   Consquência da fórmula.
# Não entendi porque lbp_hist é 36
#   É porque há apenas 36 diferentes códigos de 8 bits que sejam invariantes à rotação.
# O paper usa 64 atributos, logo essa reprodução já não vai ser exata.
lbp_hist = features.lbp(actual_patch, 1, 8)

# TODO: OC-LBP feature
예제 #19
0
def test_shape():
    A = np.arange(32*32).reshape((32,32))
    B = np.arange(64*64).reshape((64,64))
    features0 = lbp(A, 3, 12)
    features1 = lbp(B, 3, 12)
    assert features0.shape == features1.shape
예제 #20
0
def test_positives():
    np.random.seed(23)
    f = np.random.random_sample((256,256))
    lbps = lbp(f, 4, 8)
    assert len(np.where(lbps == 0)[0]) < 2
    assert lbps.sum() == f.size
예제 #21
0
def compute_lbp(fname):
    from mahotas.features import lbp
    imc = mh.imread(fname)
    im = mh.colors.rgb2grey(imc)
    return lbp(im, radius=8, points=6)
예제 #22
0
def lbp(patch):
    lbp_hist = features.lbp(patch, 1, 8)
    return lbp_hist
예제 #23
0
def test_histogram_large():
    A = np.arange(32 * 32).reshape((32, 32))
    for r in (2, 3, 4, 5):
        assert lbp(A, r, 12).sum() == A.size
예제 #24
0
def test_positives():
    np.random.seed(23)
    f = np.random.random_sample((256, 256))
    lbps = lbp(f, 4, 8)
    assert len(np.where(lbps == 0)[0]) < 2
    assert lbps.sum() == f.size
예제 #25
0
def test_nonzero():
    A = np.arange(32*32).reshape((32,32))
    features = lbp(A, 3, 12)
    features_ignore_zeros = lbp(A * (A> 256), 3, 12, ignore_zeros=True)
    assert features.sum() > 0
    assert not np.all(features == features_ignore_zeros)