Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. def AddImages(img1, img2, result_image):
  2. for i in range(0, img1.size):
  3. result_image[i] = img1[i] + img2[i]
  4.  
  5. def GetFilteredValue(kernel, img, x, y):
  6. final_value = -1
  7. for i in range(-1, 2):
  8. for j in range(-1, 2):
  9. #Check if the number is inside the bounderies
  10. if ((x + i >= 0 and x + i <= img.shape[1]) and (y + j >= 0 and y + j <= img.shape[0])):
  11. final_value += img[x + i][y + j] * kernel[i][j]
  12. else:
  13. continue
  14.  
  15. return final_value;
  16.  
  17. def ApplyKernel(kernel, orig_img, result_img):
  18. for i in range(0, img.shape[1]):
  19. for j in range(0, img.shape[0]):
  20. result_img[i][j] = GetFilteredValue(kernel, orig_img, i, j)
  21.  
  22. def NormalizeValue(value, maxim, minim):
  23. return ((value - minim) / (maxim - minim))*255
  24.  
  25. def GetMaxValueFromMatrix(array):
  26. return_value = -1
  27. for i in range(0, array.shape[1]):
  28. for j in range(0, array.shape[0]):
  29. if array[i][j] > return_value:
  30. return_value = array[i][j]
  31.  
  32. def GetMinValueFromMatrix(array):
  33. return_value = 10000
  34. for i in range(0, array.shape[1]):
  35. for j in range(0, array.shape[0]):
  36. if array[i][j] < return_value:
  37. return_value = array[i][j]
  38.  
  39. def NormalizeImage(img):
  40. max_value = GetMaxValueFromMatrix(img)
  41. min_value = GetMinValueFromMatrix(img)
  42.  
  43. for i in range(0, img.shape[1]):
  44. for j in range(0, img.shape[0]):
  45. NormalizeValue(img[i][j], max_value, min_value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement