Skip to content

Commit

Permalink
removed some redundant files, testMIL left to be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
tsogkas committed Feb 4, 2017
1 parent 377297a commit 61c688b
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 542 deletions.
24 changes: 12 additions & 12 deletions computeHistogramFeatures.m
@@ -1,18 +1,20 @@
function [features] = computeHistogramFeatures(im,fine,usechi2,smooth,ratio)
function features = computeHistogramFeatures(im)
% Extracts color,brighteness and texture features based on chi-square
% histogram differences.
%
% [features] = computeHistogramFeatures(im,fine,b,usechi2,smooth,ratio)
%
% Stavros Tsogkas <stavros.tsogkas@ecp.fr>
% Last update: August 2015
% Stavros Tsogkas <tsogkas@cs.toronto.edu>
% Last update: February 2017

if nargin<2, fine = true; end; % compute features at finer scale
if nargin<3, usechi2 = [1 1 1 1]; end; % use chi-square distance or other
if nargin<4, smooth = 'savgol'; end; % use savgol filtering
if nargin<5, ratio = 2; end; % ratio between rectangle filter sides

scales = [6:2:14, 16:4:28, 32:8:48]; if fine, scales = [4, scales]; end
opts.fine = true; % compute features at finer scale
opts.usechi2 = [1 1 1 1]; % use chi-square distance or other
opts.smooth = 'savgol'; % use savgol filtering
opts.ratio = 2; % ratio between rectangle filter sides
opts = parseVarargin(opts, varargin);

scales = [6:2:14, 16:4:28, 32:8:48]; if opts.fine, scales = [4, scales]; end
thetas = (0:7)*pi/8;
nScales = length(scales);
nOrient = length(thetas);
Expand Down Expand Up @@ -48,7 +50,7 @@
imrot = imrot(pad+1-hMargin:end-pad+hMargin,pad+1-wMargin:end-pad+wMargin,:);
for c=1:nChannels
hgrad = computeHistogramGradient(imrot(:,:,c),nBins(c),...
scale,thetas(o),[h0,w0],usechi2(c),smooth,csim,ratio);
scale,thetas(o),[h0,w0],opts.usechi2(c),opts.smooth,csim,ratio);
if size(hgrad,1)~=h || size(hgrad,2)~=w
hgrad = imresize(hgrad, [h,w],'bilinear');
end
Expand Down Expand Up @@ -118,7 +120,6 @@
% used to scale values into the unit interval
abmin = -73;
abmax = 95;
% gamma = 2.5; lab = RGB2Lab(im.^gamma);
lab = applycform(im, makecform('srgb2lab'));
lab(:,:,1) = lab(:,:,1) ./ 100;
lab(:,:,2) = (lab(:,:,2) - abmin) ./ (abmax-abmin);
Expand Down Expand Up @@ -147,7 +148,6 @@

% --- Get subsampling rates and pyramid level indexes ---------------------
function [step, pyramidLevel] = assignPyramidLevel(scales)

% step: step between rectangle scales in the same level of the pyramid
% pyramidLevel: index of pyramid level according to scale

Expand All @@ -173,4 +173,4 @@
% Pad images to avoid wrong symmetry responses at larger scales
for isub = 1:4
impyr{isub} = padarray(impyr{isub},[pad pad],'replicate');
end
end
6 changes: 3 additions & 3 deletions computeSpectralFeature.m
@@ -1,4 +1,4 @@
function [sPb,eigVec] = computeSpectralFeature(psym,nvec,radius,sigmaW,sigmaOE)
function [spb,eigVec] = computeSpectralFeature(psym,nvec,radius,sigmaW,sigmaOE)
% function [sPb,eigVec] = computeSpectralFeature(psym,nvec,radius,sigmaW,sigmaOE)
%
% Calculate spectral feature. Code based on the code for Berkeley global
Expand Down Expand Up @@ -69,7 +69,7 @@
ch_per = [2 3 4 5 6 7 8 1]; % change theta sequence to [0,pi) clockwise

eigVec = zeros(height,width,nvec-1);
sPb = zeros(height, width, norient);
spb = zeros(height, width, norient);
for v = 1 : nvec
if EigVal(v) > 0,
eigVec(:,:,v) = vect(:,:,v)/sqrt(EigVal(v));
Expand All @@ -78,7 +78,7 @@
for o = 1 : norient,
theta = dtheta*o;
f = oeFilter(sigmaOE, support, theta, deriv, hil);
sPb(:,:,ch_per(o)) = sPb(:,:,ch_per(o)) + abs(applyFilter(f, eigVec(:,:,v)));
spb(:,:,ch_per(o)) = spb(:,:,ch_per(o)) + abs(applyFilter(f, eigVec(:,:,v)));
end
end
end
Expand Down
117 changes: 0 additions & 117 deletions external/PS_primal_sketch/filtering/nonmax.m

This file was deleted.

33 changes: 0 additions & 33 deletions loadScores.m

This file was deleted.

63 changes: 33 additions & 30 deletions saveSpectralFeatures.m
@@ -1,51 +1,54 @@
function saveSpectralFeatures(set, nvec, radius, sigma)
function saveSpectralFeatures(model, nvec, radius, sigma)
% Compute spectral feature for all images in one of the train, val, test
% sets of the BSDS500 dataset.
%
% computeAllSpectralFeatures(set,nvec,radius,sigma);
% saveSpectralFeatures(set,nvec,radius,sigma);
%
% set: one of {'train', 'val', 'test'}.
% model: model used to compute soft symmetry responses that are fed as
% input to the spectral clustering algorithm.
% nvec: number of eigenvectors used {default = 50}.
% radius: radius for intervening contour cue {default = 5}.
% sigma: sigma for intervening contour cue. {default = 0.1}
%
% Stavros Tsogkas <stavros.tsogkas@ecp.fr>
% Last update: August 2013
% Stavros Tsogkas <tsogkas@cs.toronto.edu>
% Last update: February 2017

if nargin<1, set = 'train'; end
if nargin<2, nvec = 50; end % number of eigenvectors computed
if nargin<3, radius = 5; end % radius for intervening contour cue
if nargin<4, sigma = 0.1; end % sigma for intervening contour cue

% Set paths
directories = setupDirectories();
switch set
case 'train'
imagePath = directories.bsds500imTrain;
case 'val'
imagePath = directories.bsds500imVal;
case 'test'
imagePath = directories.bsds500imTest;
otherwise
error('ERROR:Wrong dataset!')
% Load model
if ischar(model)
spbModel = load(fullfile(paths.models,model)); spbModel = spbModel.spbModel;
elseif isstruct(model)
spbModel = model;
else error('Input model must be a path to a mat-file or a struct.')
end
s = load(fullfile(directories.models,'rpbModel_600K_color_loglikeNOR_balanced_trainval.mat'));
w = s.rpbModel.w;
savePath = fullfile(directories.spectral,['spectral_' num2str(nvec)],set);
imageList = dir(fullfile(imagePath,'*jpg'));

% Create directory where spectral features will be stored
mkdir(fullfile(path.spectral,['eigenvec' num2str(nvec)]));

% Read image paths
imageList = [dir(fullfile(paths.bsds500imTrain,'*jpg'));
dir(fullfile(paths.bsds500imVal, '*jpg'));
dir(fullfile(paths.bsds500imTest, '*jpg'))];

% Compute and store spectral features
for i = 1:length(imageList)
[~,iid,~] = fileparts(imageList(i).name);
if ~exist(fullfile(savePath,['spectral_' num2str(iid) '.mat']),'file')
fprintf('Extracting spectral features from %s set image %d/%d (iid = %s)\n',...
savePath = fullfile(path.spectral, ['eigenvec' num2str(nvec)], ['spectral_' num2str(iid) '.mat']);
if ~exist(savePath,'file')
fprintf('Extracting spectral features for image %d/%d (iid = %s)\n',...
set, i, length(imageList), iid);
im = im2double(imread(fullfile(imagePath, imageList(i).name)));
ridges = rpb(im,'color',true,w);
[spectral,eigVec] = computeSpectralFeature(ridges.thin,nvec,radius,sigma);
img = im2double(imread(fullfile(imagePath, imageList(i).name)));
spb = spbMIL(img,spbModel.featureSet,true,spbModel.w);
[spectral,eigVec] = computeSpectralFeature(spb.thin,nvec,radius,sigma);
spectral = single(spectral);
% for iv=1:size(eigVec,3)
% fig = figure; imagesc(eigVec(:,:,iv)); print(fig,'-depsc2',sprintf('eigVec%d_%s.eps',iv+1,iid))
% end
save(fullfile(savePath,['spectral_' num2str(iid)]),'spectral')
% for iv=1:size(eigVec,3)
% fig = figure; imagesc(eigVec(:,:,iv));
% print(fig,'-depsc2',sprintf('eigVec%d_%s.eps',iv+1,iid))
% end
save(savePath,'spectral')
end
end

3 changes: 3 additions & 0 deletions setPaths.m
Expand Up @@ -26,4 +26,7 @@
% models
paths.models = fullfile(paths.output,'mil','models');

% path for storing spectral features
path.spectral = fullfile(paths.output, 'spectral');


0 comments on commit 61c688b

Please sign in to comment.