Advertisement
Guest User

spectrum

a guest
Apr 22nd, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import matplotlib.image as mpimg
  3. from PIL import Image
  4. import cv2
  5. import numpy as np
  6.  
  7. points = []
  8.  
  9. def onMouse(event, x, y, flags,param):
  10.     if event == cv2.EVENT_LBUTTONDBLCLK:
  11.         print(x, y)
  12.         points.append((x, y))
  13.         if len(points) == 1:
  14.             print("click on the red border")
  15.  
  16.  
  17. print("enter picture's name")
  18. while True:
  19.     try:
  20.         fname = input()
  21.         img = cv2.imread(fname, 1)
  22.         img = cv2.resize(img, (0,0), fx=0.5, fy=0.5)
  23.  
  24.         arr = img
  25.         break
  26.     except Exception:
  27.         print("couldn't find image")
  28.  
  29. print("click on the violet border")
  30. cv2.namedWindow('image')
  31. cv2.setMouseCallback('image', onMouse)
  32.  
  33. while len(points) < 2:
  34.     cv2.imshow('image',img)
  35.     k = cv2.waitKey(20) & 0xFF
  36.     if k == 27:
  37.         break
  38.  
  39.  
  40.  
  41. print(arr.shape)
  42. line = []
  43.  
  44. print(points)
  45. for i in range(points[0][1], points[1][1]):
  46.     pixel = arr[i][points[0][0]]
  47.     #print(pixel)
  48.     now = 0
  49.     for j in pixel:
  50.         now += j
  51.      
  52.     line.append(now)
  53. line = line[::-1]
  54. plot = plt.plot(line)
  55. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement