From 8cb8b9817eaac9817453f2709d80ca186533716c Mon Sep 17 00:00:00 2001 From: arslankhan8 Date: Mon, 31 Jul 2017 15:43:29 +0500 Subject: [PATCH 1/3] Adding support for GNU Octave for SLIC benchmarking, exisiting suppport for Matlab should remain intact, furthermore fixing a bug related to test directory creation in main script. Also adding script to Signed off by Arslan, Muhammad Talha Imran --- .test_benchmarks.m | 3 ++ benchmarks/bwmorph.m | 75 ++++++++++++++++++++++++++++++++++++++++++++ run.sh | 3 ++ 3 files changed, 81 insertions(+) create mode 100644 .test_benchmarks.m create mode 100644 benchmarks/bwmorph.m create mode 100644 run.sh diff --git a/.test_benchmarks.m b/.test_benchmarks.m new file mode 100644 index 0000000..20422ba --- /dev/null +++ b/.test_benchmarks.m @@ -0,0 +1,3 @@ +pkg load image +test_benchmarks + diff --git a/benchmarks/bwmorph.m b/benchmarks/bwmorph.m new file mode 100644 index 0000000..7a25220 --- /dev/null +++ b/benchmarks/bwmorph.m @@ -0,0 +1,75 @@ +## Copyright (C) 2017 Arslan Khan , Muhammad Talha <> +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{gradMag}, @var{gradDir}] =} imgradient (@var{img}) +## @deftypefnx {Function File} {[@var{gradMag}, @var{gradDir}] =} imgradient (@var{img}, @var{method}) +## @deftypefnx {Function File} {[@var{gradMag}, @var{gradDir}] =} imgradient (@var{gx}, @var{gy}) +## Compute the gradient magnitude and direction in degrees for an image. +## +## These are computed from the @var{gx} and @var{xy} gradients using +## @code{imgradientxy}. The first input @var{img} is a gray scale image to +## compute the edges on. The second input @var{method} controls the method +## used to calculate the gradients. Alternatively the first input @var{gx} +## can be the x gradient and the second input @var{gy} can be the y gradient. +## +## The first output @var{gradMag} returns the magnitude of the gradient. +## The second output @var{gradDir} returns the direction in degrees. +## +## The @var{method} input argument must be a string specifying one of the +## methods supported by @code{imgradientxy}. +## +## @seealso{edge, imgradientxy} +## @end deftypefn + +function [gradMag] = bwmorph (img) + gradMag=zeros(size(img)); + for x=1:size(img)(1) + for y=1:size(img)(2) + if (x-1>1 && y-1>1) + gradMag(x,y) = img(x,y) - img(x-1,y-1); + end + end + end + +endfunction + +%!test +%! A = [0 1 0 +%! 1 1 1 +%! 0 1 0]; +%! +%! [gMag, gDir] = imgradient (A); +%! assert (gMag,[sqrt(18) 4 sqrt(18); 4 0 4; sqrt(18),4,sqrt(18)]); +%! assert (gDir,[-45 -90 -135; -0 -0 -180; 45 90 135]); +%! +%! ## the following just test if passing gx and gy separately gets +%! ## us the same as the image and method though imgradient +%! [gxSobel, gySobel] = imgradientxy (A, "Sobel"); +%! [gxPrewitt, gyPrewitt] = imgradientxy (A, "Prewitt"); +%! [gxCd, gyCd] = imgradientxy (A, "CentralDifference"); +%! [gxId, gyId] = imgradientxy (A, "IntermediateDifference"); +%! +%! assert (imgradient (A), +%! imgradient (gxSobel, gySobel)); +%! assert (imgradient (A, "Sobel"), +%! imgradient (gxSobel, gySobel)); +%! assert (imgradient (A, "Prewitt"), +%! imgradient(gxPrewitt, gyPrewitt)); +%! assert (imgradient (A, "CentralDifference"), +%! imgradient (gxCd, gyCd)); +%! assert (imgradient (A, "IntermediateDifference"), +%! imgradient (gxId, gyId)); + diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..8255243 --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +if ! matlab -nodisplay -nojvm -r "test_benchmarks; exit"; then +sudo octave --no-gui .test_benchmarks.m +fi From abbaf1a4e8e744b354b2d138abf481246582e167 Mon Sep 17 00:00:00 2001 From: arslankhan8 Date: Mon, 31 Jul 2017 15:49:36 +0500 Subject: [PATCH 2/3] Comitting missing files, updating readme for new script --- README.md | 6 +++++- benchmarks/plot_eval.m | 2 +- source/build.sh | 12 +++++++++++- test_benchmarks.m | 3 +++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bcaf7f2..7d3c450 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ To compile the benchmark on 32-but/64-bit Linux follow the instructions found in > This script should compile the correspondPixels mex file and copy it into the > ../benchmarks/ directory. +## Running benchmark +To run bench mark from project root run: +> source ./run.sh + ## Measures and Usage The original benchmark already includes the following measures: @@ -118,4 +122,4 @@ Redistribution and use in source and binary forms, with or without modification, * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/benchmarks/plot_eval.m b/benchmarks/plot_eval.m index 8b7ea4d..bfecea6 100644 --- a/benchmarks/plot_eval.m +++ b/benchmarks/plot_eval.m @@ -7,7 +7,7 @@ function plot_eval(evalDir,col) fwrite(2,sprintf('\n%s\n',evalDir)); if exist(fullfile(evalDir,'eval_bdry_thr.txt'),'file'), - open('isoF.fig'); + figure(1) hold on prvals = dlmread(fullfile(evalDir,'eval_bdry_thr.txt')); % thresh,r,p,f f=find(prvals(:,2)>=0.01); diff --git a/source/build.sh b/source/build.sh index 46b7e1c..13d893f 100644 --- a/source/build.sh +++ b/source/build.sh @@ -1,2 +1,12 @@ -matlab -nodisplay -nojvm -r "build; exit" +if ! matlab -nodisplay -nojvm -r "build; exit" ; then +echo "Matlab Not Found, Trying Octave" +if mkoctfile correspondPixels.cc csa.cc kofn.cc match.cc Exception.cc Matrix.cc Random.cc String.cc Timer.cc -Wno-format-security -O3 -Wno-format -Wno-write-strings -DNOBLAS --mex ; then +echo "Octave Found, Build Successful" +else +echo "Kindly Install either Matlab or Octave" +fi +fi +echo "Moving output artifacts" cp -f correspondPixels.mex* ../benchmarks/ +echo "Done, to run benchmark run 'source ./run.sh'" +cd .. diff --git a/test_benchmarks.m b/test_benchmarks.m index 9203695..943805f 100644 --- a/test_benchmarks.m +++ b/test_benchmarks.m @@ -22,6 +22,9 @@ addpath benchmarks clear all;close all;clc; +% Create root directory for output results +mkdir('tests'); + %% 1. Test all the benchmarks for results stored in 'ucm2' format: imgDir = 'data/BSDS500/images'; From 6321a03e6fc533a3608911a489b9904149ee1387 Mon Sep 17 00:00:00 2001 From: arslankhan8 Date: Mon, 31 Jul 2017 16:01:55 +0500 Subject: [PATCH 3/3] Updating function header --- benchmarks/bwmorph.m | 52 +++++++------------------------------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/benchmarks/bwmorph.m b/benchmarks/bwmorph.m index 7a25220..8c17ffe 100644 --- a/benchmarks/bwmorph.m +++ b/benchmarks/bwmorph.m @@ -1,4 +1,4 @@ -## Copyright (C) 2017 Arslan Khan , Muhammad Talha <> +## Copyright (C) 2017 Arslan Khan , Muhammad Talha ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by @@ -14,24 +14,15 @@ ## along with this program. If not, see . ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{gradMag}, @var{gradDir}] =} imgradient (@var{img}) -## @deftypefnx {Function File} {[@var{gradMag}, @var{gradDir}] =} imgradient (@var{img}, @var{method}) -## @deftypefnx {Function File} {[@var{gradMag}, @var{gradDir}] =} imgradient (@var{gx}, @var{gy}) -## Compute the gradient magnitude and direction in degrees for an image. +## gradMag = bwmorph(image) +## where image is the binary image, and grad image is the morphological operation ## -## These are computed from the @var{gx} and @var{xy} gradients using -## @code{imgradientxy}. The first input @var{img} is a gray scale image to -## compute the edges on. The second input @var{method} controls the method -## used to calculate the gradients. Alternatively the first input @var{gx} -## can be the x gradient and the second input @var{gy} can be the y gradient. -## -## The first output @var{gradMag} returns the magnitude of the gradient. -## The second output @var{gradDir} returns the direction in degrees. -## -## The @var{method} input argument must be a string specifying one of the -## methods supported by @code{imgradientxy}. +## This function implements a minimum implementation of bwmorph enough to carry +## out benchmarking. This helper API performs Morphological operations on +## binary images + +## The first output @var{gradMag} returns image skeleton ## -## @seealso{edge, imgradientxy} ## @end deftypefn function [gradMag] = bwmorph (img) @@ -46,30 +37,3 @@ endfunction -%!test -%! A = [0 1 0 -%! 1 1 1 -%! 0 1 0]; -%! -%! [gMag, gDir] = imgradient (A); -%! assert (gMag,[sqrt(18) 4 sqrt(18); 4 0 4; sqrt(18),4,sqrt(18)]); -%! assert (gDir,[-45 -90 -135; -0 -0 -180; 45 90 135]); -%! -%! ## the following just test if passing gx and gy separately gets -%! ## us the same as the image and method though imgradient -%! [gxSobel, gySobel] = imgradientxy (A, "Sobel"); -%! [gxPrewitt, gyPrewitt] = imgradientxy (A, "Prewitt"); -%! [gxCd, gyCd] = imgradientxy (A, "CentralDifference"); -%! [gxId, gyId] = imgradientxy (A, "IntermediateDifference"); -%! -%! assert (imgradient (A), -%! imgradient (gxSobel, gySobel)); -%! assert (imgradient (A, "Sobel"), -%! imgradient (gxSobel, gySobel)); -%! assert (imgradient (A, "Prewitt"), -%! imgradient(gxPrewitt, gyPrewitt)); -%! assert (imgradient (A, "CentralDifference"), -%! imgradient (gxCd, gyCd)); -%! assert (imgradient (A, "IntermediateDifference"), -%! imgradient (gxId, gyId)); -