<< Chapter < Page Chapter >> Page >
This test determines whether a fish is a salmon or a trout based on different color features that are detected using the 2-D DWT

One of the most important features of different fish are the colors of their heads, tails, and bodies. This test breaks downthe different color matricies into blocks of similar colors and uses them to detect what color the different parts of the fish'sbody are.

The first part of the process is to run the 2-D DWT on each of the color matricies. It is run 3 times so that the resulting picture is 1/8 of theresolution of the original matricies, and there are only high values where the color is relatively constant for a largearea. This essentially provides a method for Low-Pass filtering the picture and finding only large blocks of color.

Next, the picture is filtered by dropping any values that are lower than a threshold and setting any values over thatthreshold to 1. This drops all areas in the picture that are not very intense, or where the values are not constant for alarge area. Now, the picture has only ones whereever the large blocks of color are.

The next step is to count all the different blocks of ones, which is done by using the Matlab command, bwlabel . Next, each block is examined one by one to see what size it is, and where in the picture itslocated. From this, it can be determined what color the body, head, and tail of the fish is. If they match the pattern foreither type of fish, then the test classifies it as that type. Because this is the hardest test to satisfy, it is also the mostheavily weighted test in the entire process.

Feature testing image

The features for each of the colors(red, green, then blue) for a sample sockeye salmon picture.

Code for feature detection

% This function takes in a 3D image matrix of three colors, red, green, and blue and uses the % 2-D DWT to low poss filter them and decrease their resolution. It then looks for blocks of% color and outputs a matrix with the size, and location of each of the different features of % each color. These can then be analyzed to see if they show evidence of a specific fish type.function [rfeats,gfeats,bfeats] = featuredet(image)redimage = image(:,:,1); greenimage = image(:,:,2);blueimage = image(:,:,3); rfeats = [0 0 0 0 0 0 0 0]; gfeats = [0 0 0 0 0 0 0 0]; bfeats = [0 0 0 0 0 0 0 0]; % Run the 2-D DWT on the different colors to reduce the resolution of the picture and% effectively low-pass filter the image. dwtr = dwt2(redimage, 'haar');dwtr2 = dwt2(dwtr, 'haar'); dwtr3 = dwt2(dwtr2, 'haar');%dwtr3feat = (dwtr3 > 6) dwtr4 = dwt2(dwtr3, 'haar');%dwtr4feat = (dwtr4 > 13); dwtg = dwt2(greenimage, 'haar');dwtg2 = dwt2(dwtg, 'haar'); dwtg3 = dwt2(dwtg2, 'haar');dwtg4 = dwt2(dwtg3, 'haar'); dwtb = dwt2(blueimage, 'haar');dwtb2 = dwt2(dwtb, 'haar'); dwtb3 = dwt2(dwtb2, 'haar');dwtb4 = dwt2(dwtb3, 'haar'); % Set everything below a threshold to 0 and everything above to 1 and then% number every group of ones in the binary image [redfeatures, numred]= bwlabel(dwtr3>5); [greenfeatures, numgreen]= bwlabel(dwtg3>5); [bluefeatures, numblue]= bwlabel(dwtb3>5); % Cycle through each different feature and find its location and sizefor a = 1:numred rowval = sum(redfeatures==a);colval = sum((redfeatures==a)')'; sizeval = size(redfeatures);j = 1; left = 0;while rowval(j)<1 left = j;j = j+1; endj = 1; right = sizeval(2);while rowval(sizeval(2)-j+1)<1 right = sizeval(2)-j+1;j = j+1; endj = 1; top = 0;while colval(j)<1 top = j;j = j+1; endj = 1; bottom = sizeval(1);while colval(sizeval(1)-j+1)<1 bottom = sizeval(1)-j+1;j = j+1; endsumval = sum(rowval); rfeats(a,:) = [top bottom bottom-top left right right-left (right-left)./(bottom-top) sumval]; endfor b = 1:numgreen rowval = sum(greenfeatures==b);colval = sum((greenfeatures==b)')'; sizeval = size(greenfeatures);j = 1; while rowval(j)<1 left = j;j = j+1; endj = 1; while rowval(sizeval(2)-j+1)<1 right = sizeval(2)-j+1;j = j+1; endj = 1; while colval(j)<1 top = j;j = j+1; endj = 1; while colval(sizeval(1)-j+1)<1 bottom = sizeval(1)-j+1;j = j+1; endsumval = sum(rowval); gfeats(b,:) = [top bottom bottom-top left right right-left (right-left)./(bottom-top) sumval]; endfor c = 1:numblue rowval = sum(bluefeatures==c);colval = sum((bluefeatures==c)')'; sizeval = size(bluefeatures);j = 1; while rowval(j)<1 left = j;j = j+1; endj = 1; while rowval(sizeval(2)-j+1)<1 right = sizeval(2)-j+1;j = j+1; endj = 1; while colval(j)<1 top = j;j = j+1; endj = 1; while colval(sizeval(1)-j+1)<1 bottom = sizeval(1)-j+1;j = j+1; endsumval = sum(rowval); bfeats(c,:) = [top bottom bottom-top left right right-left (right-left)./(bottom-top) sumval]; end

Code for feature analysis

% This function takes a 3D image and runs the feature detector on it, which gives matricies% containing the sizes and shapes of the different features. It then decides what color the % fish's body, head, and tail are, or whether the can't be determined by the features.function [body,head,tail] = featureanalyzer(fishimage);[rfeats,gfeats,bfeats] = featuredet(fishimage);impfeats = [0 0 0; 0 0 0; 0 0 0];% This section takes each feature located by the feature detector and decides if they % are evidence or a body, head, or tail of the fish being that color.for a = 1:size(rfeats,1) % If the feature is extremely long, it is a bodyif and(rfeats(a,6)>30, rfeats(a,8)>30) impfeats(1,1) = 1;end % If the feature is far to the right, it is a headif and(rfeats(a,4)>38, rfeats(a,8)>20) impfeats(1,2) = 1;end % If the features is far to the left, it is a tailif and(rfeats(a,5)<25, rfeats(a,8)>6) impfeats(1,3) = 1;end endfor b = 1:size(gfeats,1) if and(gfeats(b,6)>30, gfeats(b,8)>30)impfeats(2,1) = 1; endif and(gfeats(b,4)>38, gfeats(b,8)>10) impfeats(2,2) = 1;end if and(gfeats(b,5)<25, gfeats(b,8)>6) impfeats(2,3) = 1;end endfor c = 1:size(bfeats,1) if and(bfeats(c,6)>30, bfeats(c,8)>30)impfeats(3,1) = 1; endif and(bfeats(c,4)>38, bfeats(c,8)>10) impfeats(3,2) = 1;end if and(bfeats(c,5)<25, bfeats(c,8)>6) impfeats(3,3) = 1;end end% This section looks at each of the columns of the feature matrix and then % outputs which color pattern they are.if and(impfeats(1,1) == 1, and(impfeats (2,1) == 1, impfeats (3,1) == 1)) body = 'rgb';end if and(impfeats(1,1) == 1, and(impfeats (2,1) == 1, impfeats (3,1) == 0))body = 'rg '; endif and(impfeats(1,1) == 1, and(impfeats (2,1) == 0, impfeats (3,1) == 1)) body = 'rb ';end if and(impfeats(1,1) == 1, and(impfeats (2,1) == 0, impfeats (3,1) == 0))body = 'r '; endif and(impfeats(1,1) == 0, and(impfeats (2,1) == 1, impfeats (3,1) == 1)) body = 'gb ';end if and(impfeats(1,1) == 0, and(impfeats (2,1) == 1, impfeats (3,1) == 0))body = 'g '; endif and(impfeats(1,1) == 0, and(impfeats (2,1) == 0, impfeats (3,1) == 1)) body = 'b ';end if and(impfeats(1,1) == 0, and(impfeats (2,1) == 0, impfeats (3,1) == 0))body = 'cbd'; endif and(impfeats(1,2) == 1, and(impfeats (2,2) == 1, impfeats (3,2) == 1))head = 'rgb'; endif and(impfeats(1,2) == 1, and(impfeats (2,2) == 1, impfeats (3,2) == 0)) head = 'rg ';end if and(impfeats(1,2) == 1, and(impfeats (2,2) == 0, impfeats (3,2) == 1))head = 'rb '; endif and(impfeats(1,2) == 1, and(impfeats (2,2) == 0, impfeats (3,2) == 0)) head = 'r ';end if and(impfeats(1,2) == 0, and(impfeats (2,2) == 1, impfeats (3,2) == 1))head = 'gb '; endif and(impfeats(1,2) == 0, and(impfeats (2,2) == 1, impfeats (3,2) == 0)) head = 'g ';end if and(impfeats(1,2) == 0, and(impfeats (2,2) == 0, impfeats (3,2) == 1))head = 'b '; endif and(impfeats(1,2) == 0, and(impfeats (2,2) == 0, impfeats (3,2) == 0)) head = 'cbd';endif and(impfeats(1,3) == 1, and(impfeats (2,3) == 1, impfeats (3,3) == 1)) tail = 'rgb';end if and(impfeats(1,3) == 1, and(impfeats (2,3) == 1, impfeats (3,3) == 0))tail = 'rg '; endif and(impfeats(1,3) == 1, and(impfeats (2,3) == 0, impfeats (3,3) == 1)) tail = 'rb ';end if and(impfeats(1,3) == 1, and(impfeats (2,3) == 0, impfeats (3,3) == 0))tail = 'r '; endif and(impfeats(1,3) == 0, and(impfeats (2,3) == 1, impfeats (3,3) == 1)) tail = 'gb ';end if and(impfeats(1,3) == 0, and(impfeats (2,3) == 1, impfeats (3,3) == 0))tail = 'g '; endif and(impfeats(1,3) == 0, and(impfeats (2,3) == 0, impfeats (3,3) == 1)) tail = 'b ';end if and(impfeats(1,3) == 0, and(impfeats (2,3) == 0, impfeats (3,3) == 0))tail = 'cbd'; end

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ece 301 projects fall 2003. OpenStax CNX. Jan 22, 2004 Download for free at http://cnx.org/content/col10223/1.5
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ece 301 projects fall 2003' conversation and receive update notifications?

Ask