diff --git a/models/matlab/CVS/smiler.json b/models/matlab/CVS/smiler.json index 6ca2fd7..2aab4f7 100644 --- a/models/matlab/CVS/smiler.json +++ b/models/matlab/CVS/smiler.json @@ -7,19 +7,19 @@ "model_files": [], "parameters": { "size": { - "default": 512, - "description": "The dimensions that the image gets resized to when calculating the saliency map. Note that this is always a square.", - "valid_values": "Any integer greater than 0." - }, + "default": 512, + "description": "The dimensions that the image gets resized to when calculating the saliency map. Note that this is always a square.", + "valid_values": "Any integer greater than 0." + }, "quantile": { - "default": 0.1, - "description": "A parameter which specifies the proportion of regions (sorted by degree of similarity) from the neighbourhood which are included in the calculation.", - "valid_values": "A number greater than 0 and less than or equal to 1" - }, + "default": 0.1, + "description": "A parameter which specifies the proportion of regions (sorted by degree of similarity) from the neighbourhood which are included in the calculation.", + "valid_values": "A number greater than 0 and less than or equal to 1" + }, "modeltype": { - "default": "CovariancesOnly", - "description": "CovariancesOnly calculates saliency based on the covariances of the image patches, whereas SigmaPoints includes both covariances and means.", - "valid_values": ["CovariancesOnly", "SigmaPoints"] - } + "default": "CovariancesOnly", + "description": "CovariancesOnly calculates saliency based on the covariances of the image patches, whereas SigmaPoints includes both covariances and means.", + "valid_values": ["CovariancesOnly", "SigmaPoints"] + } } } diff --git a/models/matlab/FES/FES_wrap.m b/models/matlab/FES/FES_wrap.m index 6add831..43ccf3d 100644 --- a/models/matlab/FES/FES_wrap.m +++ b/models/matlab/FES/FES_wrap.m @@ -2,8 +2,8 @@ % saliency model in the common SMILER format. If you use results produced % by this model, please cite % the following paper: -% Tavakoli, Hamed Rezazadegan, Esa Rahtu, and Janne Heikkilä. "Fast and -% efficient saliency detection using sparse sampling and kernel +% Tavakoli, Hamed Rezazadegan, Esa Rahtu, and Janne Heikkilä. "Fast and +% efficient saliency detection using sparse sampling and kernel % density estimation." In Scandinavian Conference on Image Analysis, % pp. 666-675. Springer, Berlin, Heidelberg, 2011. % @@ -34,7 +34,7 @@ params = checkCommonParams(in_params); % get the path to smiler.json -pathroot = mfilename('fullpath'); +pathroot = mfilename('fullpath'); [pathroot, ~, ~] = fileparts(pathroot); % check the model-specific parameter fields diff --git a/models/matlab/FES/computeFinalSaliency.m b/models/matlab/FES/computeFinalSaliency.m index 3dcb4df..2af6b05 100644 --- a/models/matlab/FES/computeFinalSaliency.m +++ b/models/matlab/FES/computeFinalSaliency.m @@ -2,7 +2,7 @@ function saliency = computeFinalSaliency(img, pScale, sScale, alpha, sigma0, sigma1, p1) % function saliency = computeFinalSaliency(image, pScale, sScale, alpha, sigma0, sigma1, p1) % -% compute multi scale saliency over an image +% compute multi scale saliency over an image % % @input % img - a given image to process @@ -14,15 +14,15 @@ % p1 - P(1|x) [128x171 matrix] % @output % saliency - saliency of inputed image -% +% % please refer to the following paper for details -% Rezazadegan Tavakoli H, Rahtu E & Heikkil? J, +% Rezazadegan Tavakoli H, Rahtu E & Heikkil? J, % "Fast and efficient saliency detection using sparse sampling and kernel density estimation." % Proc. Scandinavian Conference on Image Analysis (SCIA 2011), 2011, Ystad, Sweden. % -% The code has been tested on Matlab 2010a (32-bit) running windows. +% The code has been tested on Matlab 2010a (32-bit) running windows. % This code is publicly available for demonstration and educational -% purposes, any commercial use without permission is strictly prohibited. +% purposes, any commercial use without permission is strictly prohibited. % % Please contact the author in case of any questions, comments, or Bug % reports @@ -57,5 +57,3 @@ saliency = mean(saliency, 3); saliency = (saliency - min(saliency(:))) / (max(saliency(:)) - min(saliency(:))); - - diff --git a/models/matlab/GBVS/.gitignore b/models/matlab/GBVS/.gitignore new file mode 100644 index 0000000..1384cea --- /dev/null +++ b/models/matlab/GBVS/.gitignore @@ -0,0 +1 @@ +util/mypath.mat \ No newline at end of file diff --git a/models/matlab/GBVS/GBVS_wrap.m b/models/matlab/GBVS/GBVS_wrap.m index b1ee12d..32f8436 100644 --- a/models/matlab/GBVS/GBVS_wrap.m +++ b/models/matlab/GBVS/GBVS_wrap.m @@ -1,5 +1,5 @@ % GBVS_wrap executes the Graph-Based Visual Saliency (GBVS) model in the -% SMILER format. If you use results produced by this model, please cite +% SMILER format. If you use results produced by this model, please cite % the following paper: % J. Harel, C. Koch, and P. Perona (2006). Graph-Based Visual Saliency. % Proc. Neural Information Processing Systems (NIPS) @@ -39,7 +39,7 @@ params = checkCommonParams(in_params); % get the path to smiler.json -pathroot = mfilename('fullpath'); +pathroot = mfilename('fullpath'); [pathroot, ~, ~] = fileparts(pathroot); % check the model-specific parameter fields @@ -77,7 +77,7 @@ params.channels = strrep(params.channels, 'C', 'D'); end params.dklcolorWeight = params.colorWeight; - + %% Reading the image img = checkImgInput(input_image, params.color_space); @@ -87,4 +87,4 @@ salmap = out.master_map_resized; % do any final post-processing as specified by the parameters -salmap = fmtOutput(salmap, params); \ No newline at end of file +salmap = fmtOutput(salmap, params); diff --git a/models/matlab/GBVS/gbvs.m b/models/matlab/GBVS/gbvs.m index be16829..a0770b5 100644 --- a/models/matlab/GBVS/gbvs.m +++ b/models/matlab/GBVS/gbvs.m @@ -1,7 +1,7 @@ function [out,motionInfo] = gbvs(img,param,prevMotionInfo) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % +% % % This computes the GBVS map for an image and puts it in master_map. % % % % If this image is part of a video sequence, motionInfo needs to be recycled in a % @@ -24,7 +24,7 @@ % Jonathan Harel, Last Revised Aug 2008. jonharel@gmail.com % % % ** Code modified from the original source code as part of SMILER -% All effort has been made to preserve original functionality while +% All effort has been made to preserve original functionality while % bringing code execution into a common format. ** % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -36,7 +36,7 @@ end if ( (nargin < 2) || (~exist('param')) || isempty(param) ) - param = makeGBVSParams(); + param = makeGBVSParams(); end [grframe,param] = initGBVS(param,size(img)); @@ -49,7 +49,7 @@ mymessage(param,'NOTE: Computing STANDARD Itti/Koch instead of Graph-Based Visual Saliency (GBVS)\n\n'); end -%%%% +%%%% %%%% STEP 1 : compute raw feature maps from image %%%% @@ -57,7 +57,7 @@ if ( size(img,3) == 3 ) imgcolortype = 1; else, imgcolortype = 2; end [rawfeatmaps motionInfo] = getFeatureMaps( img , param , prevMotionInfo ); -%%%% +%%%% %%%% STEP 2 : compute activation maps from feature maps %%%% @@ -74,7 +74,7 @@ map_types{fmapi} = mapsobj.description; for typei = 1 : numtypes if ( param.activationType == 1 ) - for lev = param.levels + for lev = param.levels mymessage(param,'making a graph-based activation (%s) feature map.\n',mapnames{fmapi}); i = i + 1; [allmaps{i}.map,tmp] = graphsalapply( mapsobj.maps.val{typei}{lev} , ... @@ -85,10 +85,10 @@ for centerLevel = param.ittiCenterLevels for deltaLevel = param.ittiDeltaLevels mymessage(param,'making a itti-style activation (%s) feature map using center-surround subtraction.\n',mapnames{fmapi}); - i = i + 1; + i = i + 1; center_ = mapsobj.maps.origval{typei}{centerLevel}; sz_ = size(center_); - surround_ = imresize( mapsobj.maps.origval{typei}{centerLevel+deltaLevel}, sz_ , 'bicubic' ); + surround_ = imresize( mapsobj.maps.origval{typei}{centerLevel+deltaLevel}, sz_ , 'bicubic' ); allmaps{i}.map = (center_ - surround_).^2; allmaps{i}.maptype = [ fmapi centerLevel deltaLevel ]; end @@ -97,8 +97,8 @@ end end - -%%%% + +%%%% %%%% STEP 3 : normalize activation maps %%%% @@ -109,11 +109,11 @@ if ( param.normalizationType == 1 ) mymessage(param,' using fast raise to power scheme\n ', i); algtype = 4; - [norm_maps{i}.map,tmp] = graphsalapply( allmaps{i}.map , grframe, param.sigma_frac_norm, param.num_norm_iters, algtype , param.tol ); + [norm_maps{i}.map,tmp] = graphsalapply( allmaps{i}.map , grframe, param.sigma_frac_norm, param.num_norm_iters, algtype , param.tol ); elseif ( param.normalizationType == 2 ) mymessage(param,' using graph-based scheme\n'); algtype = 1; - [norm_maps{i}.map,tmp] = graphsalapply( allmaps{i}.map , grframe, param.sigma_frac_norm, param.num_norm_iters, algtype , param.tol ); + [norm_maps{i}.map,tmp] = graphsalapply( allmaps{i}.map , grframe, param.sigma_frac_norm, param.num_norm_iters, algtype , param.tol ); else mymessage(param,' using global - mean local maxima scheme.\n'); norm_maps{i}.map = maxNormalizeStdGBVS( mat2gray(imresize(allmaps{i}.map,param.salmapsize, 'bicubic')) ); @@ -121,7 +121,7 @@ norm_maps{i}.maptype = allmaps{i}.maptype; end -%%%% +%%%% %%%% STEP 4 : average across maps within each feature channel %%%% @@ -139,7 +139,7 @@ end %%% divide each feature channel by number of maps in that channel for fmapi = 1 : length(mapnames) - if ( param.normalizeTopChannelMaps) + if ( param.normalizeTopChannelMaps) mymessage(param,'Performing additional top-level feature map normalization.\n'); if ( param.normalizationType == 1 ) algtype = 4; @@ -154,7 +154,7 @@ comb_norm_maps{fmapi} = cmaps{fmapi}; end -%%%% +%%%% %%%% STEP 5 : sum across feature channels %%%% @@ -185,7 +185,7 @@ master_map = mat2gray(master_map); end -if ( param.unCenterBias ) +if ( param.unCenterBias ) invCB = load('invCenterBias'); invCB = invCB.invCenterBias; centerNewWeight = 0.5; @@ -195,7 +195,7 @@ master_map = mat2gray(master_map); end -%%%% +%%%% %%%% save descriptive, rescaled (0-255) output for user %%%% diff --git a/models/matlab/GBVS/saltoolbox/makeGaborFilterGBVS.m b/models/matlab/GBVS/saltoolbox/makeGaborFilterGBVS.m index 188f464..6099c8d 100644 --- a/models/matlab/GBVS/saltoolbox/makeGaborFilterGBVS.m +++ b/models/matlab/GBVS/saltoolbox/makeGaborFilterGBVS.m @@ -20,9 +20,9 @@ % This file is part of the Saliency Toolbox - Copyright (C) 2006 % by Dirk Walther and the California Institute of Technology. -% The Saliency Toolbox is released under the GNU General Public -% License. See the enclosed COPYRIGHT document for details. -% For more information about this project see: +% The Saliency Toolbox is released under the GNU General Public +% License. See the enclosed COPYRIGHT document for details. +% For more information about this project see: % http://www.saliencytoolbox.net if isempty(varargin) @@ -40,7 +40,7 @@ if (sz == -1) sz = ceil(max_stddev*sqrt(10)); else - sz = floor(sz/2); + sz = floor(sz/2); end psi = pi / 180 * phase; diff --git a/models/matlab/GBVS/smiler.json b/models/matlab/GBVS/smiler.json index 10458a2..9243451 100644 --- a/models/matlab/GBVS/smiler.json +++ b/models/matlab/GBVS/smiler.json @@ -8,99 +8,99 @@ "model_files": [], "parameters": { "salmapmaxsize": { - "default": 32, - "description": "The maximum dimensions of the saliency map during calculation; setting to a large number will greatly increase computation time.", - "valid_values": "Any number greater than 0, recommended to not go above 60." - }, + "default": 32, + "description": "The maximum dimensions of the saliency map during calculation; setting to a large number will greatly increase computation time.", + "valid_values": "Any number greater than 0, recommended to not go above 60." + }, "channels": { - "default": "CIO", - "description": "Specification of the feature channels to use in the saliency calculation. C = Color, I = Intensity, O = Orientation, R = contRast, F = Flicker, M = Motion. Note that by default the C channel will be based on DKL space, unless a non-default value of color_space is set.", - "valid_values": "Any substring of CIORD (in any order). F and M currently " - }, + "default": "CIO", + "description": "Specification of the feature channels to use in the saliency calculation. C = Color, I = Intensity, O = Orientation, R = contRast, F = Flicker, M = Motion. Note that by default the C channel will be based on DKL space, unless a non-default value of color_space is set.", + "valid_values": "Any substring of CIORD (in any order). F and M currently " + }, "colorWeight": { - "default": 1, - "description": "Weight of the C channel; channel weights are relative", - "valid_values": "Any positive number" - }, + "default": 1, + "description": "Weight of the C channel; channel weights are relative", + "valid_values": "Any positive number" + }, "intensityWeight": { - "default": 1, - "description": "Weight of the I channel; channel weights are relative", - "valid_values": "Any positive number" - }, + "default": 1, + "description": "Weight of the I channel; channel weights are relative", + "valid_values": "Any positive number" + }, "orientationWeight": { - "default": 1, - "description": "Weight of the O channel; channel weights are relative", - "valid_values": "Any positive number" - }, + "default": 1, + "description": "Weight of the O channel; channel weights are relative", + "valid_values": "Any positive number" + }, "flickerWeight": { - "default": 1, - "description": "Weight of the F channel; channel weights are relative", - "valid_values": "Any positive number" - }, + "default": 1, + "description": "Weight of the F channel; channel weights are relative", + "valid_values": "Any positive number" + }, "motionWeight": { - "default": 1, - "description": "Weight of the M channel; channel weights are relative", - "valid_values": "Any positive number" - }, + "default": 1, + "description": "Weight of the M channel; channel weights are relative", + "valid_values": "Any positive number" + }, "dklcolorWeight": { - "default": 1, - "description": "Weight of the D channel; channel weights are relative", - "valid_values": "Any positive number" - }, + "default": 1, + "description": "Weight of the D channel; channel weights are relative", + "valid_values": "Any positive number" + }, "gaborangles": { - "default": [0, 45, 90, 135], - "description": "Angles of Gabor filters", - "valid_values": "A list of angles in degrees." - }, + "default": [0, 45, 90, 135], + "description": "Angles of Gabor filters", + "valid_values": "A list of angles in degrees." + }, "contrastwidth": { - "default": 0.1, - "description": "Length over which luminance variance is calculated for the contrast channel specified as a fraction of image width. Larger values will give smoother contrast maps.", - "valid_values": "A number between 0 and 1." - }, + "default": 0.1, + "description": "Length over which luminance variance is calculated for the contrast channel specified as a fraction of image width. Larger values will give smoother contrast maps.", + "valid_values": "A number between 0 and 1." + }, "flickerNewFrameWt": { - "default": 1, - "description": "A parameter to adjust how quickly frame information is updated to calculate flicker (which is the absolute difference between the current frame and the previous frame estimate). For value w, previous frame estimate becomes w*(current frame) + (1-w)*(previous estimate).", - "valid_values": "A number between 0 and 1, inclusive." - }, + "default": 1, + "description": "A parameter to adjust how quickly frame information is updated to calculate flicker (which is the absolute difference between the current frame and the previous frame estimate). For value w, previous frame estimate becomes w*(current frame) + (1-w)*(previous estimate).", + "valid_values": "A number between 0 and 1, inclusive." + }, "motionAngles": { - "default": [0, 45, 90, 135], - "description": "Angles of motion filters", - "valid_values": "A list of angles in degrees." - }, + "default": [0, 45, 90, 135], + "description": "Angles of motion filters", + "valid_values": "A list of angles in degrees." + }, "levels": { - "default": [2, 3, 4], - "description": "Resolution of feature maps relative to original image in image pyramid.", - "valid_values": "A set of integers with allowable minimum 2 and maximum 9." - }, + "default": [2, 3, 4], + "description": "Resolution of feature maps relative to original image in image pyramid.", + "valid_values": "A set of integers with allowable minimum 2 and maximum 9." + }, "multilevels": { - "default": [], - "description": "Provide a set of numbers (e.g. [1,2]) for additional node lattices across spatial scales.", - "valid_values": "A set of integers or an empty set." - }, + "default": [], + "description": "Provide a set of numbers (e.g. [1,2]) for additional node lattices across spatial scales.", + "valid_values": "A set of integers or an empty set." + }, "sigma_frac_act": { - "default": 0.15, - "description": "Sigma parameter in activation step, as fraction of image width.", - "valid_values": "A number between 0 and 1." - }, + "default": 0.15, + "description": "Sigma parameter in activation step, as fraction of image width.", + "valid_values": "A number between 0 and 1." + }, "sigma_frac_norm": { - "default": 0.06, - "description": "Sigma parameter in normalization step, as fraction of image width.", - "valid_values": "A number between 0 and 1." - }, + "default": 0.06, + "description": "Sigma parameter in normalization step, as fraction of image width.", + "valid_values": "A number between 0 and 1." + }, "num_norm_iters": { - "default": 1, - "description": "The number of normalization iterations.", - "valid_values": "An integer greater than or equal to 1." - }, + "default": 1, + "description": "The number of normalization iterations.", + "valid_values": "An integer greater than or equal to 1." + }, "tol": { - "default": 0.0001, - "description": "The stopping rule parameter for the distribution equilibrium calculation. Higher numbers make GBVS run faster, but the results are more approximate.", - "valid_values": "A positive number." - }, + "default": 0.0001, + "description": "The stopping rule parameter for the distribution equilibrium calculation. Higher numbers make GBVS run faster, but the results are more approximate.", + "valid_values": "A positive number." + }, "normalizationType": { - "default": 1, - "description": "The type of normalization used; 1 raises the map to a power, and 2 is graph-based normalization as described in the original paper. Authors no longer recommend 2, though it is not specified why.", - "valid_values": "1 or 2." - } + "default": 1, + "description": "The type of normalization used; 1 raises the map to a power, and 2 is graph-based normalization as described in the original paper. Authors no longer recommend 2, though it is not specified why.", + "valid_values": "1 or 2." + } } } diff --git a/models/matlab/GBVS/util/mypath.mat b/models/matlab/GBVS/util/mypath.mat deleted file mode 100644 index 5053709..0000000 Binary files a/models/matlab/GBVS/util/mypath.mat and /dev/null differ diff --git a/smiler_tools/smiler_tools/parameters.py b/smiler_tools/smiler_tools/parameters.py index 3785db1..e33f300 100644 --- a/smiler_tools/smiler_tools/parameters.py +++ b/smiler_tools/smiler_tools/parameters.py @@ -1,4 +1,5 @@ import copy +import array class ParameterMap(object): @@ -48,7 +49,18 @@ def get_parameters(self): return self._parameters.values() def get_matlab_struct(self, matlab_engine): - return self.get_pair_dict() + """ + https://www.mathworks.com/help/matlab/matlab_external/handling-data-returned-from-python.html + """ + struct = self.get_pair_dict() + for key in struct: + if isinstance(struct[key], int): + struct[key] *= 1.0 + if isinstance(struct[key], list): + if struct[key] and isinstance(struct[key][0], int): + struct[key] = matlab_engine.double( + matlab_engine.cell2mat(struct[key])) + return struct def clone(self): return copy.deepcopy(self)