<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="Module.2003-12-16.0517">
  <name>Length/Width Ratio Test for Fish Classification</name>
  <metadata>
  <md:version>**new**</md:version>
  <md:created>2003/12/16 20:05:17.274 US/Central</md:created>
  <md:revised>2003/12/17 11:38:20.135 US/Central</md:revised>
  <md:authorlist>
    <md:author id="kclarks">
      <md:firstname>Kyle</md:firstname>
      
      <md:surname>Clarkson</md:surname>
      <md:email>kclarks@rice.edu</md:email>
    </md:author>
    <md:author id="jjsedano">
      <md:firstname>Jason</md:firstname>
      
      <md:surname>Sedano</md:surname>
      <md:email>jjsedano@rice.edu</md:email>
    </md:author>
    <md:author id="ianclark">
      <md:firstname>Ian</md:firstname>
      
      <md:surname>Clark</md:surname>
      <md:email>ianclark@rice.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="kclarks">
      <md:firstname>Kyle</md:firstname>
      
      <md:surname>Clarkson</md:surname>
      <md:email>kclarks@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="mhusband">
      <md:firstname>Mark</md:firstname>
      <md:othername>S.</md:othername>
      <md:surname>Husband</md:surname>
      <md:email>mhusband@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="richb">
      <md:firstname>Richard</md:firstname>
      <md:othername>G.</md:othername>
      <md:surname>Baraniuk</md:surname>
      <md:email>richb@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="jjsedano">
      <md:firstname>Jason</md:firstname>
      
      <md:surname>Sedano</md:surname>
      <md:email>jjsedano@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="ianclark">
      <md:firstname>Ian</md:firstname>
      
      <md:surname>Clark</md:surname>
      <md:email>ianclark@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  

  <md:abstract>This test determines whether a fish is a salmon or a trout, or neither based on the length and width of the fish</md:abstract>
</metadata>

  <content>
    <para id="para1">
      One simple way to tell different fish apart is due to their
      ratio of length to width.  For every species of fish, that ratio
      is essentially the same.  On reason salmon are unique in that
      regard is because during spawning season, they grow wider and
      thus their length to width ratio becomes much smaller
      (approximately 2:1 or 3:1).  Other fish, such as steelhead
      trout, which maintain a much more sleek, approximately 3:1 to
      4:1 length to width ratio even during spawning season.
    </para>
    
    <para id="para2">
      This test is done using primarily the Canny Edge Detection
      method which is performed by Matlab using the command <code type="inline">edge</code>.  It takes the image of the fish and
      finds an outline of it.
    </para>
<figure id="pic1">
<name>Canny edge detection Image</name>
<media type="image/jpg" src="cannytest.jpg"/>
<caption>The Fish image after the canny edge detection is run on it.</caption>
</figure>
    <section id="canny">
      <name>Canny Edge Detection</name>
      <para id="CannyEdgeDetection">
	Image edges contain strong contrasts in intensity.  The Canny Edge
	Detector tries to find only true edges by only selecting
	localized edge points and only responding once to a single real
	edge.  The Canny method also filters noise with a convolution
	mask built through Canny's algorithm.  The edge detector then
	uses the gradient of the image and summing along the x direction
	and y direction to obtain the edge value.  Direction of the edge
	is easily determined by looking at each directions value and
	seeing which one is larger.  However, it is important to test for
	errors when one direction is zero, so Canny looks at the angle
	between the x-direction and y-direction.  Canny also uses
	suppression to connect values along the direction of the edge.
      </para>
      <note type="See Also">
	<link src="http://www.pages.drexel.edu/~weg22/can_tut.html">Canny
	  Method Edge Detection</link>
      </note>
    </section>
    <para id="para3">
      After the edge detection has been run, the image is binary and
      all the edges are represented by ones.  The rows and columns are
      then each summed up.  The algorithm then starts at each edge of
      the image and moves toward the center until it finds a row with
      a significant amount of values in it.  This signals the edge of
      the fish closest to that side.  Then, through simple
      calculations, the length, width, and ration can be calculated.
    </para>

    <example id="codeex">
      <name>Code for Length/Width Test</name>
      <code type="block">% This function uses canny edge detection to try to find an outline of the 
% fish in the grayscale image and then it calculates the length to width 
% ratio of the fish.
function [length,width,lwratio] = fishedge(image)

imagegray = rgb2gray(image);
imageedge = edge(imagegray,'canny');

l4rowedge = sum(imageedge);
l4coledge = sum(imageedge')';
l4size = size(imageedge);

j = 1;
% Find the top edge of the fish
while l4coledge(j)&lt; 4
    top = j;
    j = j+1;
end
j = 1;
% Find the bottom edge of the fish
while l4coledge(l4size(1)-j+1)&lt; 4
    bottom = l4size(1)-j+1;
    j = j+1;
end   

width = bottom - top; 

j = 1;
% Find the left edge of the fish
while l4rowedge(j)&lt; 4
    left = j;
    j = j+1;
end
j = 1;
% Find the right edge of the fish
while l4rowedge(l4size(2)-j+1)%lt; 4 
    right = l4size(2)-j+1;
    j = j+1;
end   

length = right - left;

lwratio = length./width;
      </code>
    </example>

  </content> 

</document>
