Appendix A: MATLAB Code
Matlab code for;
•
Pre-processing
•
Colour histogram equalisation
•
Printing measurement and sexing information to
file
•
Measurement and sexing
preprocess.m
function preprocess(i)
%PREPROCESS Performs preprocessing on images required for % honours thesis
% It no longer sharpens the identified images and then % if i = 1 simply applies a
% colhisteq to the images, renames the files and saves % them as
% 'previousFileName'CHE.jpg. If i = -1 it edge detects % with a sobel edge
% detector, then colhisteq the images and saves them to % a new filename of
% 'previousFileName'EDCHE.jpg
% Author: Mark Knights August 2007
% Set up some basic variables
index = 1; edged = 0; reComp = 0;
toSharpen = [14 45 50 62 76 94 96 99 116 132 134 135 136 137 138 139 144 146 147 148 152 155 156 160 165 170 172 176 179 180 192 203 204 205 217 221 236 240 242 245 247 276 296 300 303 307 310 322 323 333 345 348 354 366 395 -1];
EXT = '.jpg'; ColHist = 'CHE'; edg = 'ED';
hSobel = fspecial('sobel');
vSobel = [1 0 -1; 2 0 -2; 1 0 -1]; sharp = [1 1 1 ; 1 -4 1; 1 1 1];
for count = 1: 1 : 416 % Read in file
numStr = int2str(count);
filename = strcat(numStr, EXT); f = imread(filename);
% Change to type 'double' and get rgb components identified
f = im2double(f);
fr = f(:,:,1); fg = f(:,:,2); fb = f(:,:,3);
% Sharpen if image is identified as needing sharpening
if count == toSharpen(index)
fr = fr - imfilter(fr, sharp, 'replicate'); fg = fg - imfilter(fg, sharp, 'replicate'); fb = fb - imfilter(fb, sharp, 'replicate'); index = index + 1;
Appendix A
end
% Edge detect if -1 entered in as i
if i == -1
frh = fr - imfilter(fr, hSobel, 'replicate'); frv = fr - imfilter(fr, vSobel, 'replicate'); fr = imadd(frv, frh);
fgh = fg - imfilter(fg, hSobel, 'replicate'); fgv = fg - imfilter(fg, vSobel, 'replicate'); fg = imadd(fgh, fgv);
fbh = fb - imfilter(fb, hSobel, 'replicate'); fbv = fb - imfilter(fb, vSobel, 'replicate'); fb = imadd(fbh, fbv);
reComp = 1; edged = 1; end
% If image has been sharpened or edge detected recompute the image
if reComp == 1
f = cat(3, fr, fg, fb); reComp = 0;
end
f = im2uint8(f);
% Perform ColHistEq on image
f = colhisteq(f);
% Rename the file to reflect the pre-processing done
if edged == 1
addon = strcat(edg, ColHist);
filename = strcat(numStr, addon, EXT); imwrite(f, filename, 'quality', 100); edged = 0;
else
filename = strcat(numStr, ColHist, EXT); imwrite(f, filename, 'quality', 100); end
count
colhisteq.m
function f = colhisteq(i)
%COLHISTEQ Performs an equalisation of light intensity in %image i
% F = COLHISTEQ(I) is created to fill a need in % equalisation
% techniques %
% As doing a histogram equalisation on each component % of an RGB image
% provides erroneous results this function takes image % i and transfers it
% to an HSI style image, then equalises the I portion % of the HSI, puts it
% back together and returns it as an RGB image.
% Author Mark Knights August 2007
% Transfer to HSI
f1 = rgb2hsi(i);
% Separate components
f1h = f1(:,:,1); f1s = f1(:,:,2); f1i = f1(:,:,3);
% Equalise Intensity
f1he = histeq(f1i, 256);
f1st = imadjust(f1s, [0.05 0.95], [0 1]);
% imshow(f1h); title('hue'); figure, imshow(f1st); title('saturation'); figure, imshow(f1he); title('he intensity');
% Concatenate new Intensity into HSI image
f1 = cat(3, f1h, f1s, f1he);
% Change back to rgb image
Appendix A
lobsterTest.m
function status = lobsterTest()
%LOBSTERTEST runs a script to read in dat files and %output lengths and sex
%
% This file is a specific creation simply for the % honours thesis of Mark
% Knights. A more general file reading script needs % development for a
% final system development
% Author Mark Knights September 2007
% Set up the variable for filenames
files = {'1che.dat' '2che.dat' '3che.dat' '4che.dat' '5che.dat' ...
'6che.dat' '7che.dat' '8che.dat' '9che.dat' '10che.dat' ...
'12che.dat' '13che.dat' '14che.dat' '15che.dat' '16che.dat' ...
'17che.dat' '18che.dat' '19che.dat' '20che.dat' '21che.dat' ...
'22che.dat' '23che.dat' '24che.dat' '25che.dat' '28che.dat' ...
'29che.dat' '30che.dat' '31che.dat' '32che.dat' '33che.dat' ...
'34che.dat' '35che.dat' '36che.dat' '38che.dat' '39che.dat' ...
'40che.dat' '41che.dat' '42che.dat' '43che.dat' '44che.dat' ...
'45che.dat' '46che.dat' '47che.dat' '48che.dat' '49che.dat' ...
'50che.dat' '51che.dat' '52che.dat' '53che.dat' '54che.dat' ...
'55che.dat' '56che.dat' '57che.dat' '58che.dat' '59che.dat' ...
'60che.dat' '61che.dat' '62che.dat' '63che.dat' '64che.dat' ...
'65che.dat' '66che.dat' '67che.dat' '68che.dat' '69che.dat' ...
'70che.dat' '71che.dat' '73che.dat' '74che.dat' '75che.dat' ...
'76che.dat' '77che.dat' '78che.dat' '79che.dat'
'81che.dat' ...
'82che.dat' '83che.dat' '85che.dat' '86che.dat' '87che.dat' ...
'88che.dat' '89che.dat' '90che.dat' '91che.dat' '92che.dat' ...
'93che.dat' '94che.dat' '95che.dat' '96che.dat' '98che.dat' ...
'103che.dat' ...
'104che.dat' '105che.dat' '106che.dat' '107che.dat' '108che.dat' ...
'109che.dat' '110che.dat' '111che.dat' '112che.dat' '113che.dat' ...
'114che.dat' '115che.dat' '116che.dat' '117che.dat' '118che.dat' ...
'119che.dat' '120che.dat' '121che.dat' '122che.dat' '124che.dat' ...
'125che.dat' '127che.dat' '129che.dat' '130che.dat' '131che.dat' ...
'132che.dat' '133che.dat' '134che.dat' '136che.dat' '137che.dat' ...
'138che.dat' '139che.dat' '140che.dat' '141che.dat' '142che.dat' ...
'143che.dat' '144che.dat' '145che.dat' '146che.dat' '147che.dat' ...
'148che.dat' '149che.dat' '150che.dat' '151che.dat' '152che.dat' ...
'153che.dat' '154che.dat' '155che.dat' '156che.dat' '157che.dat' ...
'158che.dat' '159che.dat' '160che.dat' '161che.dat' '162che.dat' ...
'163che.dat' '164che.dat' '165che.dat' '166che.dat' '167che.dat' ...
'168che.dat' '169che.dat' '170che.dat' '171che.dat' '172che.dat' ...
'173che.dat' '174che.dat' '175che.dat' '176che.dat' '177che.dat' ...
'178che.dat' '179che.dat' '180che.dat' '181che.dat' '182che.dat' ...
'183che.dat' '184che.dat' '185che.dat' '186che.dat' '187che.dat' ...
'188che.dat' '189che.dat' '190che.dat' '191che.dat' '192che.dat' ...
'193che.dat' '194che.dat' '195che.dat' '196che.dat' '197che.dat' ...
'198che.dat' '199che.dat' '200che.dat' '201che.dat' '202che.dat' ...
'203che.dat' '204che.dat' '205che.dat' '206che.dat' '207che.dat' ...
'208che.dat' '209che.dat' '210che.dat' '211che.dat' '212che.dat' ...
'213che.dat' '214che.dat' '215che.dat' '216che.dat' '217che.dat' ...
'218che.dat' '219che.dat' '220che.dat' '221che.dat' '222che.dat' ...
'223che.dat' '224che.dat' '225che.dat' '226che.dat' '227che.dat' ...
'228che.dat' '229che.dat' '230che.dat' '231che.dat' '232che.dat' ...
Appendix A
'237che.dat' ...
'238che.dat' '239che.dat' '240che.dat' '241che.dat' '242che.dat' ...
'243che.dat' '244che.dat' '245che.dat' '246che.dat' '247che.dat' ...
'248che.dat' '249che.dat' '250che.dat' '251che.dat' '252che.dat' ...
'253che.dat' '254che.dat' '256che.dat' '257che.dat' '258che.dat' ...
'259che.dat' '260che.dat' '263che.dat' '264che.dat' '265che.dat' ...
'267che.dat' '268che.dat' '269che.dat' '270che.dat' '271che.dat' ...
'272che.dat' '273che.dat' '275che.dat' '277che.dat' '278che.dat' ...
'280che.dat' '281che.dat' '282che.dat' '283che.dat' '284che.dat' ...
'287che.dat' '289che.dat' '292che.dat' '294che.dat' '295che.dat' ...
'296che.dat' '297che.dat' '298che.dat' '299che.dat' '300che.dat' ...
'301che.dat' '302che.dat' '303che.dat' '304che.dat' '305che.dat' ...
'306che.dat' '307che.dat' '308che.dat' '309che.dat' '310che.dat' ...
'311che.dat' '312che.dat' '313che.dat' '314che.dat' '315che.dat' ...
'316che.dat' '317che.dat' '318che.dat' '320che.dat' '321che.dat' ...
'322che.dat' '323che.dat' '324che.dat' '325che.dat' '326che.dat' ...
'327che.dat' '328che.dat' '329che.dat' '330che.dat' '331che.dat' ...
'332che.dat' '333che.dat' '334che.dat' '335che.dat' '336che.dat' ...
'337che.dat' '338che.dat' '339che.dat' '340che.dat' '341che.dat' ...
'342che.dat' '343che.dat' '344che.dat' '345che.dat' '347che.dat' ...
'348che.dat' '349che.dat' '350che.dat' '351che.dat' '352che.dat' ...
'353che.dat' '354che.dat' '355che.dat' '356che.dat' '358che.dat' ...
'360che.dat' '362che.dat' '367che.dat' '368che.dat' '369che.dat' ...
'370che.dat' '371che.dat' '372che.dat' '373che.dat' '374che.dat' ...
'375che.dat' '376che.dat' '377che.dat' '378che.dat' '379che.dat' ...
'380che.dat' '381che.dat' '383che.dat' '384che.dat' '385che.dat' ...
'390che.dat' ...
'391che.dat' '392che.dat' '393che.dat' '394che.dat' '395che.dat' ...
'397che.dat' '398che.dat' '399che.dat' '400che.dat' '401che.dat' ...
'402che.dat' '403che.dat' '404che.dat' '406che.dat' '407che.dat' ...
'408che.dat' '409che.dat' '410che.dat' '411che.dat' '412che.dat' ...
'414che.dat' '415che.dat'};
fid = fopen('output.txt', 'wt');
for count=1:1:length(files) % get file name to read
filename = files{count};
%get the details
[l, b1, b2, b3, b4, rearv, sex] = lengthScript(filename);
%print the details to file
fprintf(fid, '%s % 6.2f % 6.2f % 6.2f % 6.2f % 6.2f % 6.2f % 1g \n', filename, l, b1, b2, b3, b4, rearv, sex);
end
Appendix A
lengthScript.m
function [l, b1, b2, b3, b4, rearv, sex] = lengthScript(filename)
%LENGTHSCRIPT finds various measures according to lobster %thoracomeres
% [L, B1, B2, B3, B4, REARV, SEX] = % LENGTHSCRIPT(FILENAME) takes in a
% filename of type filename.dat, retrieves point % information located in
% it and then uses this information to apply % measurements to the lobster.
%
% The l measurement is from the frontmost point of the % lobster to the
% centre rear section of the thoracomeres. B1 through % B4 is the
% measurements from the tip of each of the lateral % protuberances of the
% thoracomeres starting at the front (smallest) and % moving back one at a
% time to the rear set. The rearv measurement is the % measurement from
% the left and right rear of the thoracomeres before % rounding to meet at
% the centre at the rear. %
% All measurements are in millimetres and presented in % a double format.
%
% The final field attempts to sex the lobster through % the use of
% measurement statistics, returning a 2 if it is % unsure, 0 if it is male and a 1 if it is a
% female lobster.
% Author Mark Knights September 2007
% Set up required variables
l = 0.0; % length from point 1 to point 25
b1 = 0.0; % length from point 5 to point 45
b2 = 0.0; % length from point 10 to point 40
b3 = 0.0; % length from point 15 to point 35
b4 = 0.0; % length from point 20 to point 30
rearv = 0.0; % length from point 23 to point 27
sex = 2; % default unknown 0 = male, 1 = female
PIX2MM = 4.764; % not precise but average figure of images mum pixels per mm
% Load in file details
% Find the pixel lengths
l = (lengthBetween (fp(1,1), fp(1,2), fp(25,1), fp(25,2))/PIX2MM);
b1 = (lengthBetween (fp(5,1), fp(5,2), fp(45,1), fp(45,2))/PIX2MM);
b2 = (lengthBetween (fp(10,1), fp(10,2), fp(40,1), fp(40,2))/PIX2MM);
b3 = (lengthBetween (fp(15,1), fp(15,2), fp(35,1), fp(35,2))/PIX2MM);
b4 = (lengthBetween (fp(20,1), fp(20,2), fp(30,1), fp(30,2))/PIX2MM);
rearv = (lengthBetween (fp(23,1), fp(23,2), fp(27,1), fp(27,2))/PIX2MM);
% Estimate sex sex values are 0 = male, 1 = female and 2 = uncertain
sEstimate = l/rearv;
if sEstimate > 1.89 sex = 1;
elseif sEstimate <= 1.89 sex = 0;
Appendix B: Images by category
Category lists stating image files in following
categories;
•
Good
•
Blurred Image
•
Worm Presence
•
Point Occlusion
•
Worm Presence & Blurred Image
•
Point Occlusion & Blurred
•
Worm Presence & Point Occlusion
•
Worm Presence & Point Occlusion & Blurred
Good Quality:
1.jpg, 2.jpg, 4.jpg, 6.jpg, 7.jpg, 8.jpg, 9.jpg, 10.jpg, 11.jpg, 12.jpg, 13.jpg, 15.jpg, 16.jpg, 17.jpg, 18.jpg, 19.jpg, 20.jpg, 21.jpg, 22.jpg, 23.jpg, 24.jpg, 25.jpg, 26.jpg, 29.jpg, 31.jpg, 32.jpg, 33.jpg, 34.jpg, 35.jpg, 36.jpg, 37.jpg, 38.jpg, 40.jpg, 41.jpg, 42.jpg, 43.jpg, 44.jpg, 46.jpg, 47.jpg, 48.jpg, 49.jpg, 51.jpg, 52.jpg, 53.jpg, 54.jpg, 55.jpg, 56.jpg, 57.jpg, 58.jpg, 59.jpg 60.jpg, 61.jpg, 64.jpg, 65.jpg, 66.jpg, 67.jpg, 68.jpg, 69.jpg, 71.jpg, 72.jpg, 73.jpg, 74.jpg, 75.jpg, 77.jpg, 78.jpg, 79.jpg, 80.jpg, 81.jpg, 82.jpg, 83.jpg, 84.jpg, 85.jpg, 86.jpg, 87.jpg, 88.jpg, 89.jpg, 90.jpg, 91.jpg, 92.jpg, 93.jpg, 97.jpg, 98.jpg, 100.jpg, 101.jpg, 102.jpg, 103.jpg, 104.jpg, 105.jpg, 106.jpg, 110.jpg, 111.jpg, 112.jpg, 113.jpg, 114.jpg, 115.jpg, 117.jpg, 118.jpg, 125.jpg, 130.jpg, 131.jpg, 137.jpg, 141.jpg, 142.jpg, 145.jpg, 149.jpg, 150.jpg, 151.jpg, 158.jpg, 161.jpg, 162.jpg, 163.jpg, 164.jpg, 166.jpg, 171.jpg, 173.jpg, 174.jpg, 175.jpg, 177.jpg, 181.jpg, 182.jpg, 183.jpg, 185.jpg, 190.jpg, 191.jpg, 193.jpg, 194.jpg, 195.jpg, 197.jpg, 199.jpg, 200.jpg, 201.jpg, 202.jpg, 206.jpg, 207.jpg, 208.jpg, 209.jpg, 210.jpg, 211.jpg, 212.jpg, 213.jpg, 215.jpg, 216.jpg, 218.jpg, 220.jpg, 222.jpg, 223.jpg, 224.jpg, 225.jpg, 226.jpg, 227.jpg, 228.jpg, 229.jpg, 230.jpg, 231.jpg, 232.jpg, 233.jpg, 234.jpg, 238.jpg, 239.jpg, 241.jpg, 244.jpg, 246.jpg, 248.jpg, 249.jpg, 250.jpg, 251.jpg, 252.jpg, 254.jpg, 255.jpg, 256.jpg, 258.jpg, 259.jpg, 260.jpg, 261.jpg, 262.jpg, 263.jpg, 264.jpg, 265.jpg, 266.jpg, 267.jpg, 268.jpg, 269.jpg, 270.jpg, 271.jpg, 272.jpg, 273.jpg, 274.jpg, 275.jpg, 277.jpg, 278.jpg, 279.jpg, 280.jpg, 281.jpg, 285.jpg, 286.jpg, 287.jpg, 288.jpg, 289.jpg, 290.jpg, 292.jpg, 293.jpg, 298.jpg, 299.jpg, 301.jpg, 302.jpg, 308.jpg, 309.jpg, 311.jpg, 312.jpg, 321.jpg, 324.jpg, 330.jpg, 331.jpg, 332.jpg, 334.jpg, 335.jpg, 336.jpg, 337.jpg, 338.jpg, 339.jpg, 340.jpg, 341.jpg, 342.jpg, 344.jpg, 346.jpg, 349.jpg, 350.jpg, 351.jpg, 352.jpg, 353.jpg, 354.jpg, 356.jpg, 358.jpg, 359.jpg, 360.jpg, 361.jpg, 364.jpg.
Blurred Image:
3.jpg, 5.jpg, 14.jpg, 27.jpg, 28.jpg, 30.jpg, 39.jpg, 45.jpg, 50.jpg, 62.jpg, 63.jpg, 70.jpg, 76.jpg, 94.jpg, 95.jpg, 96.jpg, 99.jpg, 107.jpg, 108.jpg, 109.jpg, 116.jpg, 119.jpg, 120.jpg, 121.jpg, 122.jpg, 123.jpg, 124.jpg, 126.jpg, 127.jpg, 128.jpg, 129.jpg, 132.jpg, 133.jpg, 134.jpg, 135.jpg, 136.jpg, 138.jpg, 139.jpg, 140.jpg, 143.jpg, 144.jpg, 146.jpg, 147.jpg, 148.jpg, 152.jpg, 153.jpg, 154.jpg, 155.jpg, 156.jpg, 157.jpg, 159.jpg, 160.jpg, 165.jpg, 167.jpg, 168.jpg, 169.jpg, 170.jpg, 172.jpg, 176.jpg, 179.jpg, 180.jpg, 184.jpg, 186.jpg, 187.jpg, 188.jpg, 189.jpg, 192.jpg, 196.jpg, 198.jpg, 203.jpg, 204.jpg, 205.jpg, 214.jpg, 217.jpg, 219.jpg, 235.jpg, 236.jpg, 237.jpg, 240.jpg, 242.jpg, 243.jpg, 245.jpg, 247.jpg, 253.jpg, 257.jpg, 276.jpg, 282.jpg, 283.jpg, 291.jpg, 294.jpg, 295.jpg, 296.jpg, 297.jpg, 300.jpg, 303.jpg, 304.jpg, 305.jpg, 306.jpg, 307.jpg, 310.jpg, 313.jpg, 314.jpg, 315.jpg, 317.jpg, 318.jpg, 319.jpg, 322.jpg, 323.jpg, 325.jpg, 327.jpg, 328.jpg, 343.jpg, 345.jpg, 347.jpg, 348.jpg, 357.jpg.
Worm Presence:
367.jpg, 371.jpg, 373.jpg, 378.jpg, 382.jpg, 387.jpg, 389.jpg, 393.jpg, 396.jpg, 399.jpg, 400.jpg, 401.jpg, 405.jpg, 406.jpg, 407.jpg.
Point Occlusion:
Appendix B
Worm Presence & Blurred Image:
366.jpg, 368.jpg, 369.jpg, 370.jpg, 376.jpg, 385.jpg, 392.jpg, 395.jpg, 414.jpg.
Point Occlusion & Blurred Image: 221.jpg, 316.jpg, 333.jpg, 365.jpg.
Worm Presence & Point Occlusion:
374.jpg, 375.jpg, 377.jpg, 379.jpg, 380.jpg, 381.jpg, 383.jpg, 384.jpg, 388.jpg, 394.jpg, 397.jpg, 398.jpg, 408.jpg, 409.jpg, 411.jpg, 412.jpg, 415.jpg, 416.jpg.
Worm Presence & Point occlusion & Blurred Image:
Appendix C: Images by Training
Set
Lists the images utilised in the training sets and the
images utilised in the testing set
Appendix C
Training Sets Base Images
These images may have been modified according to a pre-processing policy. See section 3.2 for details.
5-image:
5.jpg, 89.jpg, 134.jpg, 209.jpg, 391.jpg.
10-image:
All included images in 5-image model, 49.jpg, 139.jpg, 148.jpg, 239.jpg, 374.jpg.
20-image:
All included images in 10-image model, 3.jpg, 47.jpg, 59.jpg, 67.jpg, 81.jpg, 132.jpg, 218.jpg, 228.jpg, 367.jpg, 375.jpg.
35-image:
All included images in 20-image model, 13.jpg, 15.jpg, 51.jpg, 110.jpg, 125.jpg, 136.jpg, 151.jpg, 159.jpg, 165.jpg, 166.jpg, 183.jpg, 387.jpg, 398.jpg, 408.jpg, 410.jpg.
50-image:
All included images in 35-image model, 6.jpg, 9.jpg, 12.jpg, 39.jpg, 42.jpg, 58.jpg, 117.jpg, 130.jpg, 146.jpg, 187.jpg, 208.jpg, 230.jpg, 234.jpg, 404.jpg, 407.jpg.
100-image:
All included images in 50-image model, 18.jpg, 28.jpg, 32.jpg, 43.jpg, 45.jpg, 46.jpg, 50.jpg, 53.jpg, 61.jpg, 64.jpg, 68.jpg, 69.jpg, 71.jpg, 78.jpg, 83.jpg, 87.jpg, 92.jpg, 94.jpg, 103.jpg, 111.jpg, 113.jpg, 142.jpg, 143.jpg, 147.jpg, 152.jpg, 162.jpg, 163.jpg, 175.jpg, 193.jpg, 201.jpg, 205.jpg, 207.jpg, 222.jpg, 224.jpg, 225.jpg, 232.jpg, 236.jpg, 240.jpg, 242.jpg, 247.jpg, 254.jpg, 256.jpg, 368.jpg, 369.jpg, 371.jpg, 376.jpg, 385.jpg, 386.jpg, 390.jpg, 400.jpg.
200-image:
Testing Set Base Images
These images may have been modified according to a pre-processing policy. See section 3.2 for details.
Test Set:
Appendix D: Output from Length
Script
The resulting file created by the measurement script,
lobsterTest.m
Appendix D
Appendix D
Appendix D
Appendix D