diff --git a/sobel filter analysis/mainAmund.m b/sobel filter analysis/mainAmund.m new file mode 100644 index 0000000000000000000000000000000000000000..28f23c23c6a8df8a664d9765b8cd588dc7bc2c1d --- /dev/null +++ b/sobel filter analysis/mainAmund.m @@ -0,0 +1,68 @@ +% Will go through all files in a folder and get the file path to all files given a file extension. +% Source: https://matlab.fandom.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F +% Specify the folder where the files live. +myFolder = uigetdir; +excel_file = 'GroundTruth.xlsx'; +T = readtable(excel_file); +%% Do the algorythm over all test images +num_test = 202; +distance = 300; +% Check to make sure that folder actually exists. Warn user if it doesn't. +if ~isfolder(myFolder) + errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder); + uiwait(warndlg(errorMessage)); + myFolder = uigetdir(); % Ask for a new one. + if myFolder == 0 + % User clicked Cancel + return; + end +end +% Get a list of all files in the folder with the desired file name pattern. +filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need. +theFiles = dir(filePattern); +% Just make sure user have not typed too large of num_test +if num_test > length(theFiles) + num_test = length(theFiles); + errorMessage = sprintf('Error: It appears that your specified num is larger than the number of images in the folder.'); + uiwait(warndlg(errorMessage)); +end +ratios = zeros(1, num_test); % empty list. Is going to be used to store the ratios of overlaps +successRates = zeros(1, num_test); +% Loop through the images and do whatever +for k = 1 : num_test + baseFileName = theFiles(k).name; + fullFileName = fullfile(theFiles(k).folder, baseFileName); % Path to image + fprintf(1, 'Now reading %s\n', baseFileName); + + img = imread(fullFileName); + + % Do what ever you want to the image here + % ---- + + [img_proc, img_box] = detectFish(img); + + % find the corresponding box for that image in marius' excel file: + m_box_x1 = T.Var4(k); + m_box_x2 = T.Var5(k); + m_box_y1 = T.Var2(k); + m_box_y2 = T.Var3(k); + + m_box = [m_box_x1, m_box_y1, m_box_x2-m_box_x1, m_box_y2-m_box_y1]; + ratios(k) = bboxOverlapRatio(img_box, m_box); % replace one of the 'img_box' with Marius' box + overlap_ratio = ratios(1,k); % just print the overlap value for this image to screen + + if ratios(1,k) >= 0.55 % everything over 0.7 is concidered good enough - a success + successRates(1,k) = 1; + else + successRates(1,k) = 0; + end + + img_proc = insertShape(img_proc,'FilledRectangle', m_box,'Color','green'); % insert Marius' rectangle into output image + + %figure, + %subplot(1,2,1), imshow(img), title('original'); + %subplot(1,2,2), imshow(img_proc), title('processed'); + + % --- + +end \ No newline at end of file