Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def AddImages(img1, img2, result_image):
- for i in range(0, img1.size):
- result_image[i] = img1[i] + img2[i]
- def GetFilteredValue(kernel, img, x, y):
- final_value = -1
- for i in range(-1, 2):
- for j in range(-1, 2):
- #Check if the number is inside the bounderies
- if ((x + i >= 0 and x + i <= img.shape[1]) and (y + j >= 0 and y + j <= img.shape[0])):
- final_value += img[x + i][y + j] * kernel[i][j]
- else:
- continue
- return final_value;
- def ApplyKernel(kernel, orig_img, result_img):
- for i in range(0, img.shape[1]):
- for j in range(0, img.shape[0]):
- result_img[i][j] = GetFilteredValue(kernel, orig_img, i, j)
- def NormalizeValue(value, maxim, minim):
- return ((value - minim) / (maxim - minim))*255
- def GetMaxValueFromMatrix(array):
- return_value = -1
- for i in range(0, array.shape[1]):
- for j in range(0, array.shape[0]):
- if array[i][j] > return_value:
- return_value = array[i][j]
- def GetMinValueFromMatrix(array):
- return_value = 10000
- for i in range(0, array.shape[1]):
- for j in range(0, array.shape[0]):
- if array[i][j] < return_value:
- return_value = array[i][j]
- def NormalizeImage(img):
- max_value = GetMaxValueFromMatrix(img)
- min_value = GetMinValueFromMatrix(img)
- for i in range(0, img.shape[1]):
- for j in range(0, img.shape[0]):
- NormalizeValue(img[i][j], max_value, min_value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement