First lest setup the environment for OSX
In [1]:
import os, sys
from os.path import expanduser
os.path
home = expanduser("~")
sys.path.append('/usr/local/Cellar/opencv/3.3.1_1/lib/python3.6/site-packages/')
sys.path.append(home + '/.pyenv/versions/OPENCV/lib/python3.6/site-packages/')
import cv2
cv2.__version__
! pip install numpy > tmp.log
! pip install matplotlib >> tmp.log
%matplotlib inline
For now we just selected 4 images from the video
In [2]:
import cv2
import matplotlib.pyplot as plt
img1 = cv2.imread('secchi/secchi1.png')
img2 = cv2.imread('secchi/secchi2.png')
img3 = cv2.imread('secchi/secchi3.png')
img4 = cv2.imread('secchi/secchi4.png')
In [3]:
figures = []
fig = plt.figure(figsize=(18, 16))
for i in range(1,13):
figures.append(fig.add_subplot(4,3,i))
count = 0
for img in [img1,img2,img3,img4]:
figures[count].imshow(img)
color = ('b','g','r')
for i,col in enumerate(color):
histr = cv2.calcHist([img],[i],None,[256],[0,256])
figures[count+1].plot(histr,color = col)
figures[count+2].hist(img.ravel(),256,[0,256])
count += 3
print("Legend")
print("First column = image of Secchi disk")
print("Second column = histogram of colors in image")
print("Third column = histogram of all values")
plt.show()
Rotation of the image for an angle of t
In [5]:
def threshold(img):
ret,thresh = cv2.threshold(img,150,255,cv2.THRESH_BINARY)
plt.subplot(1,2,1), plt.imshow(img, cmap='gray')
plt.subplot(1,2,2), plt.imshow(thresh, cmap='gray')
In [6]:
threshold(img1)
In [7]:
threshold(img2)
In [8]:
threshold(img3)
In [9]:
threshold(img4)
In [10]:
def find_edge(img):
edges = cv2.Canny(img,50,200)
plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.subplot(122),plt.imshow(edges,cmap = 'gray')
In [11]:
find_edge(img1)
In [12]:
find_edge(img2)
In [13]:
find_edge(img3)
In [14]:
find_edge(img4)
In [19]:
th = cv2.adaptiveThreshold(img1, 255, cv2.THRESH_BINARY,150,5)
plt.subplot(121),plt.imshow(img1,cmap = 'gray')
plt.subplot(122),plt.imshow(th,cmap = 'gray')
In [87]:
bw1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
plt.imshow(bw1, cmap='gray')
Out[87]: