In [1]:
import pandas as pd
from PIL import Image
import matplotlib.pyplot as plt
from skimage import measure
%matplotlib inline
import os
import numpy as np # linear algebra

In [2]:
###function outlines fish. 
###i should be the address of the image 
###show is a boolean value indicating whether or not you want the plot printed
###sens is the sensitivity
def fishskin(i, show, sens):
    img =
    img_gray = img.convert('L')
    contours = measure.find_contours(img_gray, sens)
    contours_long = list()
    for x in range (0, len(contours)):
        if len(contours[x]) > 99:
    if show:
        fig, ax = plt.subplots()
        ax.imshow(img, interpolation='nearest',

        for n, contour in enumerate(contours_long):
            ax.plot(contour[:, 1], contour[:, 0], linewidth=1)

In [3]:
test_cons = fishskin('../data/raw/train/ALB/test.jpg', True, 100)

In [4]:
test_cons2 = fishskin('../data/raw/train/ALB/test.jpg', True, 80)

In [5]:
albs = os.listdir('../data/raw/train/ALB/')
bets = os.listdir('../data/raw/train/BET/')
dols = os.listdir('../data/raw/train/DOL/')
lags = os.listdir('../data/raw/train/LAG/')
nofs = os.listdir('../data/raw/train/NoF/')
oths = os.listdir('../data/raw/train/OTHER/')
shas = os.listdir('../data/raw/train/SHARK/')
yfts = os.listdir('../data/raw/train/YFT/')

In [6]:
for i in albs[0:5]:
    fishskin(('../data/raw/train/ALB/'+i),True, 100)