python 3 Circular - LBP (원형 국부 이치 화 알고리즘) 의 실현 및 대량 처리
                                            
 3968 단어  python3
                    
import numpy as np
import cv2
from matplotlib import pyplot as plt
import math
#     
def bilinear_interpolation(x, y, img):
    x1, y1 = int(r), int(c)
    x2, y2 = math.ceil(r), math.ceil(c)
    r1 = (x2 - x) / (x2 - x1) * get_pixel_else_0(img, x1, y1) + (x - x1) / (x2 - x1) * get_pixel_else_0(img, x2, y1)
    r2 = (x2 - x) / (x2 - x1) * get_pixel_else_0(img, x1, y2) + (x - x1) / (x2 - x1) * get_pixel_else_0(img, x2, y2)
    return (y2 - y) / (y2 - y1) * r1 + (y - y1) / (y2 - y1) * r2    
#    
def thresholded(center, pixels):
    out = []
    for a in pixels:
        if a >= center:
            out.append(1)
        else:
            out.append(0)
    return out
#    
def get_pixel_else_0(l, idx, idy):
    if idx < int(len(l)) - 1 and idy < len(l[0]):
        return l[idx,idy]
    else:
        return 0
#    
img = cv2.imread('C:/Users/qgl/Desktop/articles/test1.jpg', 0)
transformed_img = cv2.imread('C:/Users/qgl/Desktop/articles/test1.jpg', 0)
#    P   R
P = 8 # number of pixels
R = 1 # radius 
for x in range(0, len(img)):
    for y in range(0, len(img[0])):
        center        = img[x,y]
        pixels = []
        for point in range(0, P):
            r = x + R * math.cos(2 * math.pi * point / P)
            c = y - R * math.sin(2 * math.pi * point / P)
            if r < 0 or c < 0:
                pixels.append(0)
                continue            
            if int(r) == r:
                if int(c) != c:
                    c1 = int(c)
                    c2 = math.ceil(c)
                    w1 = (c2 - c) / (c2 - c1)
                    w2 = (c - c1) / (c2 - c1)
                                    
                    pixels.append(int((w1 * get_pixel_else_0(img, int(r), int(c)) + \
                                   w2 * get_pixel_else_0(img, int(r), math.ceil(c))) / (w1 + w2)))
                else:
                    pixels.append(get_pixel_else_0(img, int(r), int(c)))
            elif int(c) == c:
                r1 = int(r)
                r2 = math.ceil(r)
                w1 = (r2 - r) / (r2 - r1)
                w2 = (r - r1) / (r2 - r1)                
                pixels.append((w1 * get_pixel_else_0(img, int(r), int(c)) + \
                               w2 * get_pixel_else_0(img, math.ceil(r), int(c))) / (w1 + w2))
            else:
                pixels.append(bilinear_interpolation(r, c, img))
                
        values = thresholded(center, pixels)
        res = 0
        for a in range(0, len(values)):
            res += values[a] * (2 ** a)
        transformed_img.itemset((x,y), res)
         
print (x)
cv2.imshow('image', img)
cv2.imshow('thresholded image', transformed_img)
cv2.imwrite('C:...'+'/'+'1.jpg',transformed_img)
return transformed_img
다시 def 순환 함 수 를 정의 하고 대상 경로 의 모든 그림 을 처리 합 니 다:
def tran(src,drc,P,R):
    list = os.listdir(src)#          
    sum = 0
    for i in list:
        try:
            img = cv2.imread(src+'/'+i,0)# list          
            transformed_img = cv2.imread(src+'/'+i,0)# list          
            cv2.imshow('img',img)#    
            transformed_img = LBP(img,P,R,transformed_img)#       LBP()  ,  LBP      
            cv2.imwrite(drc+'/'+i,transformed_img)#                  
            
            
            
            sum = int(sum)+1
            print(i+'is finished, number is'+str(sum))
        except:
            print('error in'+i)
데이터 세트 를 처리 하면 후속 적 인 분류 작업 을 할 수 있다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Jupyter 공식 DockerHub에 대한 메모에 기재되어 있다. base-notebook minimal-notebook scipy-notebook tensorflow-notebook datascience-notebook pyspark-notebook all-s...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.