addition to fobel

This commit is contained in:
Debucquoy 2022-11-04 16:50:09 +01:00
parent 0838004590
commit d574695633
No known key found for this signature in database
GPG Key ID: 3B9EEB701C9E2919
3 changed files with 42 additions and 4 deletions

BIN
03nov/final.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 KiB

BIN
03nov/final2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 KiB

View File

@ -1,4 +1,5 @@
from umage import load, save, show_image from umage import load, save, show_image
from math import atan2, cos
def grayscale(img_mat): def grayscale(img_mat):
"""Transform an image into gray """Transform an image into gray
@ -47,6 +48,33 @@ def dans_image(img_mat, row, col):
return True return True
return False return False
def calculate_direction(img1, img2):
"""Calculate the image direction of 2 image that has been trough gx and gy of phobels formula
:img1: x image of fobel
:img2: y image of fobel
:returns: matrix of direction
"""
res = list()
for row in range(len(img1)):
res.append(list())
for col in range(len(img1[row])):
res[row].append(atan2(img2[row][col][0], img1[row][col][0]))
return res
def dir_mat_to_img(mat):
"""take a matrix with direction and transform it in image with direction hue """
res = list()
for row in range(len(mat)):
res.append(list())
for col in range(len(mat[row])):
res[row].append((round(256*cos(mat[row][col])), round(256*cos(mat[row][col] + 120)), round(256*cos(mat[row][col] - 120))))
return res
if __name__ == "__main__": if __name__ == "__main__":
unit = [ unit = [
[0, 1, 0], [0, 1, 0],
@ -64,10 +92,20 @@ if __name__ == "__main__":
[-2, 0, 0], [-2, 0, 0],
[ 0, 1, 0], [ 0, 1, 0],
[ 0, 0, 2]] [ 0, 0, 2]]
phobel1 = [
[ 1, 0, -1],
[ 2, 1, -2],
[ 1, 0, -1]]
phobel2 = [
[ 1, 2, 1],
[ 0, 0, 0],
[ -1, -2, -1]]
img = load('./myimg.jpg') img = load('./myimg.jpg')
new_image = grayscale(img) new_image = grayscale(img)
convolution(new_image, convolution2) convolution(new_image, convolution2)
save(new_image, 'gray') phob1_img = convolution(new_image, phobel1)
save(convolution(new_image, convolution1), 'convo1') phob2_img = convolution(new_image, phobel2)
save(convolution(new_image, convolution2), 'convo2') final = dir_mat_to_img(calculate_direction(phob2_img, phob1_img))
save(convolution(new_image, convolution3), 'convo3') save(final, 'final2')