Я пишу код для LBP и получаю неправильный вывод изображения Мой код:
import numpy as np
import cv2
# Create Padding around original image using function
def Image_Padding(imagepad,padsize):
#(top, bottom), (left, right)
image = np.pad(imagepad,(padsize,padsize),'edge')
return image
# calculating threshold for 8N
def threshold(imgpixel,center):
if imgpixel >= center:
imgpixel = 1
else:
imgpixel = 0
return imgpixel
def LBP_calculation(pad_img,lbp):
for i in range(1, pad_img.shape[0]-1):
for j in range(1, pad_img.shape[1]-1):
# center pixel
centerPixel = pad_img[i, j]
# 8 neighbouring pixel
pixel7 = threshold(pad_img[i - 1, j - 1],centerPixel)
pixel6 = threshold(pad_img[i - 1, j],centerPixel)
pixel5 = threshold(pad_img[i - 1, j + 1],centerPixel)
pixel4 = threshold(pad_img[i, j + 1],centerPixel)
pixel3 = threshold(pad_img[i + 1, j + 1],centerPixel)
pixel2 = threshold(pad_img[i + 1, j],centerPixel)
pixel1 = threshold(pad_img[i + 1, j - 1],centerPixel)
pixel0 = threshold(pad_img[i, j - 1], centerPixel)
# convert binary values to decimal
lbp[i-1, j-1] = pixel7 * 2 ^ 7 + pixel6 * 2 ^ 6 + pixel5 * 2 ^ 5 + pixel4 * 2 ^ 4 + pixel3 * 2 ^ 3 + pixel2 * 2 ^ 2 + pixel1 * 2 + pixel0
return lbp
# Reading image
img = cv2.imread("human.png",0)
rows, cols = np.shape(img)
new_img = np.copy(img)
# Calculating Padding for Image
padding_size =1
padded_img = Image_Padding(new_img,padding_size)
LBP_img = np.zeros((rows, cols))
Final_img = LBP_calculation(padded_img,LBP_img)
cv2.imshow("LBP image",Final_img)
cv2.imwrite("LBP image.jpg",Final_img)
cv2.waitKey(0)
Желаемый результат: желаемый результат
вывод я получаю мой неправильный вывод
Я не знаю, где я ошибаюсь при кодировании