Secchi Disk

Overview

More information about Secchi DIsk can be found at:

Figure: Different kinds of Secchi disks. A marine style on the left and the freshwater version on the right [wikipedia]

Setup for OSX

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

Step 1: Record the video

Record the video on the robot

Step 2: Analyse the images from the Video

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()


Legend
First column = image of Secchi disk
Second column = histogram of colors in image
Third column = histogram of all values

Rotation of the image for an angle of t

Image Thresholding


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)


Edge Detection

Edge detection using Canny edge detection algorithm


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)


Adaptive Threshold


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')


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-a479d598eea8> in <module>()
----> 1 th = cv2.adaptiveThreshold(img1, 255, cv2.THRESH_BINARY,150,5)
      2 plt.subplot(121),plt.imshow(img1,cmap = 'gray')
      3 plt.subplot(122),plt.imshow(th,cmap = 'gray')

TypeError: Required argument 'C' (pos 6) not found

Black and white


In [87]:
bw1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
plt.imshow(bw1, cmap='gray')


Out[87]:
<matplotlib.image.AxesImage at 0x11b331198>