diff --git a/gop b/gop new file mode 160000 index 0000000..c328456 --- /dev/null +++ b/gop @@ -0,0 +1 @@ +Subproject commit c32845663148d35917f932e4f16d3441b08f9c52 diff --git a/mcg/MCG-Full/src/aux/cands2labels.m b/mcg/MCG-Full/src/aux/cands2labels.m deleted file mode 100644 index 38c7787..0000000 --- a/mcg/MCG-Full/src/aux/cands2labels.m +++ /dev/null @@ -1,27 +0,0 @@ -% ------------------------------------------------------------------------ -% Copyright (C) -% Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -% University of California Berkeley (UCB) - USA -% -% Jordi Pont-Tuset -% Pablo Arbelaez -% June 2014 -% ------------------------------------------------------------------------ -% This file is part of the MCG package presented in: -% Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -% "Multiscale Combinatorial Grouping," -% Computer Vision and Pattern Recognition (CVPR) 2014. -% Please consider citing the paper if you use this code. -% ------------------------------------------------------------------------ -% -% function masks = cands2labels(candidates,ms) -% -% From a hierarchy (lp: leaves partition and ms: merging sequence) and a -% list of candidates as sets of labels (candidates), we get each candidate -% as a list of labels of the leaves partition lp. -% ------------------------------------------------------------------------ -function labels = cands2labels(candidates,ms) - labels = mex_cands2labels(double(ms),candidates); -end - - diff --git a/mcg/MCG-Full/src/aux/cands2masks.m b/mcg/MCG-Full/src/aux/cands2masks.m deleted file mode 100644 index 8b3ba9d..0000000 --- a/mcg/MCG-Full/src/aux/cands2masks.m +++ /dev/null @@ -1,27 +0,0 @@ -% ------------------------------------------------------------------------ -% Copyright (C) -% Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -% University of California Berkeley (UCB) - USA -% -% Jordi Pont-Tuset -% Pablo Arbelaez -% June 2014 -% ------------------------------------------------------------------------ -% This file is part of the MCG package presented in: -% Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -% "Multiscale Combinatorial Grouping," -% Computer Vision and Pattern Recognition (CVPR) 2014. -% Please consider citing the paper if you use this code. -% ------------------------------------------------------------------------ -% -% function masks = cands2masks(candidates,lp,ms) -% -% From a hierarchy (lp: leaves partition and ms: merging sequence) and a -% list of candidates as sets of labels (candidates), we get all the binary -% masks of these candidates -% ------------------------------------------------------------------------ -function masks = cands2masks(candidates,lp,ms) - masks = mex_cands2masks(double(lp),double(ms),candidates); -end - - diff --git a/mcg/MCG-Full/src/aux/create_train_samples.m b/mcg/MCG-Full/src/aux/create_train_samples.m deleted file mode 100644 index e461fbc..0000000 --- a/mcg/MCG-Full/src/aux/create_train_samples.m +++ /dev/null @@ -1,39 +0,0 @@ -% ------------------------------------------------------------------------ -% Copyright (C) -% Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -% University of California Berkeley (UCB) - USA -% -% Jordi Pont-Tuset -% Pablo Arbelaez -% June 2014 -% ------------------------------------------------------------------------ -% This file is part of the MCG package presented in: -% Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -% "Multiscale Combinatorial Grouping," -% Computer Vision and Pattern Recognition (CVPR) 2014. -% Please consider citing the paper if you use this code. -% ------------------------------------------------------------------------ -% -% Create random divisions of the training set for cross-validation -% -% ------------------------------------------------------------------------ - -% Create random divisions of the training set -id = '3'; -percentage_train = 0.5; -full_set = 'train2012'; - -% Get full ids -im_ids = database_ids('pascal2012',full_set); - -ids_a = sort(randperm(length(im_ids),floor(percentage_train*length(im_ids)))); -ids_b = setdiff(1:length(im_ids),ids_a); -im_ids_a = im_ids(ids_a); -im_ids_b = im_ids(ids_b); - -% Write to file -file_a = fullfile(root_dir,'datasets', 'pascal2012','gt_sets',[full_set '_' id 'a.txt']); -file_b = fullfile(root_dir,'datasets', 'pascal2012','gt_sets',[full_set '_' id 'b.txt']); - -dlmwrite(file_a,im_ids_a,'') -dlmwrite(file_b,im_ids_b,'') \ No newline at end of file diff --git a/mcg/MCG-Full/src/aux/gridbmap2seg.m b/mcg/MCG-Full/src/aux/gridbmap2seg.m deleted file mode 100644 index f5178c0..0000000 --- a/mcg/MCG-Full/src/aux/gridbmap2seg.m +++ /dev/null @@ -1,30 +0,0 @@ -% ------------------------------------------------------------------------ -% Copyright (C) -% Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -% University of California Berkeley (UCB) - USA -% -% Jordi Pont-Tuset -% Pablo Arbelaez -% June 2014 -% ------------------------------------------------------------------------ -% This file is part of the MCG package presented in: -% Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -% "Multiscale Combinatorial Grouping," -% Computer Vision and Pattern Recognition (CVPR) 2014. -% Please consider citing the paper if you use this code. -% ------------------------------------------------------------------------ -% seg = gridbmap2seg(gridbmap) -% -% From a binary boundary map in the countour grid (as ucm2), get -% the represented partition as matrix of labels in the image plane -% -% INPUT -% - gridbmap : Binary boundary map on contour grid. -% -% OUTPUT -% - seg : Segments labeled from 1..k. -function seg = gridbmap2seg(gridbmap) -tmp = gridbmap; -tmp(1:2:end,1:2:end)=1; -filled_contours = bwlabel(1-tmp',4); -seg = filled_contours(2:2:end,2:2:end)'; diff --git a/mcg/MCG-Full/src/aux/loadvar.m b/mcg/MCG-Full/src/aux/loadvar.m deleted file mode 100644 index 97a1ef4..0000000 --- a/mcg/MCG-Full/src/aux/loadvar.m +++ /dev/null @@ -1,43 +0,0 @@ -function varargout = loadvar(filename, varargin) -% Load the contents of a .MAT file directly into a returned variable - -% ====================================================================== -% Copyright (c) 2012 David Weiss -% -% Permission is hereby granted, free of charge, to any person obtaining -% a copy of this software and associated documentation files (the -% "Software"), to deal in the Software without restriction, including -% without limitation the rights to use, copy, modify, merge, publish, -% distribute, sublicense, and/or sell copies of the Software, and to -% permit persons to whom the Software is furnished to do so, subject to -% the following conditions: -% -% The above copyright notice and this permission notice shall be -% included in all copies or substantial portions of the Software. -% -% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -% LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -% ====================================================================== - -x = load(filename, varargin{:}); - -if nargin==1 - fs = fieldnames(x); - if numel(fs) == 1 - x = x.(fs{1}); - end - varargout{1} = x; -else - if nargout == numel(varargin) - for i = 1:numel(varargin) - varargout{i} = x.(varargin{i}); - end - else - varargout{1} = x; - end -end \ No newline at end of file diff --git a/mcg/MCG-Full/src/aux/matlab_multiarray.hpp b/mcg/MCG-Full/src/aux/matlab_multiarray.hpp deleted file mode 100644 index 7528b09..0000000 --- a/mcg/MCG-Full/src/aux/matlab_multiarray.hpp +++ /dev/null @@ -1,108 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright (C) -// Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -// University of California Berkeley (UCB) - USA -// -// Jordi Pont-Tuset -// Pablo Arbelaez -// June 2014 -// ------------------------------------------------------------------------ -// This file is part of the MCG package presented in: -// Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -// "Multiscale Combinatorial Grouping," -// Computer Vision and Pattern Recognition (CVPR) 2014. -// Please consider citing the paper if you use this code. -// ------------------------------------------------------------------------ -#ifndef IMAGEPLUS_MATLAB_MULTIARRAY_HPP -#define IMAGEPLUS_MATLAB_MULTIARRAY_HPP - -#include "mex.h" -#include "boost/multi_array.hpp" -#include - -template -bool dimension_coherence(const mxArray *data) -{ - return mxGetNumberOfDimensions(data)==D; -} - -template -bool type_coherence(const mxArray *data) -{ - if(mxGetClassID(data)==mxDOUBLE_CLASS) - return typeid(double)==typeid(T); - else if(mxGetClassID(data)==mxLOGICAL_CLASS) - return typeid(bool)==typeid(T); - else if(mxGetClassID(data)==mxSINGLE_CLASS) - return typeid(float)==typeid(T); - else if(mxGetClassID(data)==mxINT8_CLASS) - return typeid(char)==typeid(T); - else if(mxGetClassID(data)==mxUINT8_CLASS) - return typeid(unsigned char)==typeid(T); - else if(mxGetClassID(data)==mxINT16_CLASS) - return typeid(short int)==typeid(T); - else if(mxGetClassID(data)==mxUINT16_CLASS) - return typeid(unsigned short int)==typeid(T); - else if(mxGetClassID(data)==mxINT32_CLASS) - return typeid(int)==typeid(T); - else if(mxGetClassID(data)==mxUINT32_CLASS) - return typeid(unsigned int)==typeid(T); - else if(mxGetClassID(data)==mxINT64_CLASS) - return typeid(long long)==typeid(T); - else if(mxGetClassID(data)==mxUINT64_CLASS) - return typeid(unsigned long long)==typeid(T); - else - return false; -} - -template -class ConstMatlabMultiArray : public boost::const_multi_array_ref{ -public: - ConstMatlabMultiArray(const mxArray *data) : boost::const_multi_array_ref((T*)mxGetData(data), boost::extents[mxGetM(data)][mxGetN(data)], boost::fortran_storage_order()) - { - if(!type_coherence(data)) - mexErrMsgTxt("Data types not coherent" ); - if(!dimension_coherence<2>(data)) - mexErrMsgTxt("Data dimensions not coherent"); - } -}; - -template -class MatlabMultiArray : public boost::multi_array_ref -{ -public: - MatlabMultiArray(mxArray *data) : boost::multi_array_ref((T*)mxGetData(data), boost::extents[mxGetM(data)][mxGetN(data)], boost::fortran_storage_order()) - { - if(!type_coherence(data)) - mexErrMsgTxt("Data types not coherent" ); - if(!dimension_coherence<2>(data)) - mexErrMsgTxt("Data dimensions not coherent" ); - } -}; - -template -class ConstMatlabMultiArray3 : public boost::const_multi_array_ref{ -public: - ConstMatlabMultiArray3(const mxArray *data) : boost::const_multi_array_ref((T*)mxGetData(data), boost::extents[mxGetDimensions(data)[0]][mxGetDimensions(data)[1]][mxGetDimensions(data)[2]], boost::fortran_storage_order()) - { - if(!type_coherence(data)) - mexErrMsgTxt("Data types not coherent" ); - if(!dimension_coherence<3>(data)) - mexErrMsgTxt("Data dimensions not coherent"); - } -}; - -template -class MatlabMultiArray3 : public boost::multi_array_ref -{ -public: - MatlabMultiArray3(mxArray *data) : boost::multi_array_ref((T*)mxGetData(data), boost::extents[mxGetDimensions(data)[0]][mxGetDimensions(data)[1]][mxGetDimensions(data)[2]], boost::fortran_storage_order()) - { - if(!type_coherence(data)) - mexErrMsgTxt("Data types not coherent" ); - if(!dimension_coherence<3>(data)) - mexErrMsgTxt("Data dimensions not coherent" ); - } -}; - -#endif diff --git a/mcg/MCG-Full/src/aux/mex_cands2labels.cpp b/mcg/MCG-Full/src/aux/mex_cands2labels.cpp deleted file mode 100644 index ffb68c6..0000000 --- a/mcg/MCG-Full/src/aux/mex_cands2labels.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright (C) -// Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -// University of California Berkeley (UCB) - USA -// -// Jordi Pont-Tuset -// Pablo Arbelaez -// June 2014 -// ------------------------------------------------------------------------ -// This file is part of the MCG package presented in: -// Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -// "Multiscale Combinatorial Grouping," -// Computer Vision and Pattern Recognition (CVPR) 2014. -// Please consider citing the paper if you use this code. -// ------------------------------------------------------------------------ -#include "mex.h" - -#include -#include -#include -#include -#include "matlab_multiarray.hpp" - -using namespace std; - -void mexFunction( int nlhs, mxArray *plhs[], - int nrhs, const mxArray*prhs[] ) -{ - /* Check for proper number of arguments */ - if (nrhs != 2) { - mexErrMsgTxt("Two input arguments required."); - } else if (nlhs > 1) { - mexErrMsgTxt("Too many output arguments."); - } - - /* Input as a Multiarray */ - ConstMatlabMultiArray ms(prhs[0]); /* Merging sequence */ - ConstMatlabMultiArray cands(prhs[1]); /* Candidates */ - - /* Input sizes and checks */ - size_t n_sons_max= ms.shape()[1]-1; - size_t n_merges = ms.shape()[0]; - size_t n_leaves = ms[0][n_sons_max]-1; // n_merges+1; --> Not valid for non-binary trees - size_t n_regs = n_leaves+n_merges; - size_t n_cands = cands.shape()[0]; - size_t n_regs_max= cands.shape()[1]; - - /* Fill leaf labels */ - vector > tree_labels(n_regs); - for (size_t ii=0; ii > labels(n_cands); - for (size_t ii=0; ii::const_iterator list_it=labels[ii].begin(); list_it!=labels[ii].end(); ++list_it) - { - curr_pr[curr_jj] = *list_it+1; - curr_jj++; - } - mxSetCell(plhs[0], ii, curr_entry); - } -} - diff --git a/mcg/MCG-Full/src/aux/mex_cands2masks.cpp b/mcg/MCG-Full/src/aux/mex_cands2masks.cpp deleted file mode 100644 index b163203..0000000 --- a/mcg/MCG-Full/src/aux/mex_cands2masks.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright (C) -// Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -// University of California Berkeley (UCB) - USA -// -// Jordi Pont-Tuset -// Pablo Arbelaez -// June 2014 -// ------------------------------------------------------------------------ -// This file is part of the MCG package presented in: -// Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -// "Multiscale Combinatorial Grouping," -// Computer Vision and Pattern Recognition (CVPR) 2014. -// Please consider citing the paper if you use this code. -// ------------------------------------------------------------------------ -#include "mex.h" - -#include -#include -#include -#include -#include "matlab_multiarray.hpp" - -using namespace std; - -void mexFunction( int nlhs, mxArray *plhs[], - int nrhs, const mxArray*prhs[] ) -{ - /* Check for proper number of arguments */ - if (nrhs != 3) { - mexErrMsgTxt("Three input arguments required."); - } else if (nlhs > 3) { - mexErrMsgTxt("Too many output arguments."); - } - - /* Input as a Multiarray */ - ConstMatlabMultiArray lp(prhs[0]); /* Leaves partition */ - ConstMatlabMultiArray ms(prhs[1]); /* Merging sequence */ - ConstMatlabMultiArray cands(prhs[2]); /* Candidates */ - - /* Input sizes and checks */ - size_t sm = lp.shape()[0]; - size_t sn = lp.shape()[1]; - size_t n_sons_max= ms.shape()[1]-1; - size_t n_merges = ms.shape()[0]; - size_t n_leaves = ms[0][n_sons_max]-1; // n_merges+1; --> Not valid for non-binary trees - size_t n_regs = n_leaves+n_merges; - size_t n_cands = cands.shape()[0]; - size_t n_regs_max= cands.shape()[1]; - - - /* Create the list of activated pixels in each leave region */ - vector > x_coords(n_regs); - vector > y_coords(n_regs); - for (size_t xx=0; xx out_masks(plhs[0]); - - for (size_t ii=0; ii::iterator itx = x_coords[cands[ii][jj]-1].begin(); - list::iterator ity = y_coords[cands[ii][jj]-1].begin(); - for( ; itx!=x_coords[cands[ii][jj]-1].end(); ++itx, ++ity) - { - out_masks[*itx][*ity][ii] = true; - } - } - } -} - diff --git a/mcg/MCG-Full/src/aux/mex_intersect_hierarchies.cpp b/mcg/MCG-Full/src/aux/mex_intersect_hierarchies.cpp deleted file mode 100644 index 5a49414..0000000 --- a/mcg/MCG-Full/src/aux/mex_intersect_hierarchies.cpp +++ /dev/null @@ -1,197 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright (C) -// Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -// University of California Berkeley (UCB) - USA -// -// Jordi Pont-Tuset -// Pablo Arbelaez -// June 2014 -// ------------------------------------------------------------------------ -// This file is part of the MCG package presented in: -// Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -// "Multiscale Combinatorial Grouping," -// Computer Vision and Pattern Recognition (CVPR) 2014. -// Please consider citing the paper if you use this code. -// ------------------------------------------------------------------------ -#include "mex.h" -#include -#include -#include -#include "boost/multi_array.hpp" - -/* Arguments */ -#define PARTS prhs[0] -#define MERSEQS prhs[1] -#define INT_PART plhs[0] -#define LUT plhs[1] - -void mexFunction( int nlhs, mxArray *plhs[], - int nrhs, const mxArray*prhs[] ) -{ - int num_dims = mxGetNumberOfDimensions(PARTS); - const int* in_dims = mxGetDimensions(PARTS); - - std::size_t num_parts; - if (num_dims==3) - num_parts = in_dims[2]; - else if (num_dims==2) - num_parts = 1; - else - mexErrMsgTxt("Input partitions must be 3- or 2-dimensional"); - - std::size_t s_x = in_dims[0]; - std::size_t s_y = in_dims[1]; - - if(mxGetClassID(PARTS)!=mxUINT32_CLASS) - mexErrMsgTxt("Input must be UINT32"); - - /* Input as a Multiarray */ - boost::multi_array_ref parts((int*)mxGetPr(PARTS), boost::extents[in_dims[0]][in_dims[1]][num_parts], boost::fortran_storage_order()); - - /* Handy typedefs */ - typedef std::vector vector_type; - typedef std::set set_type; - typedef std::map map_type; - typedef std::pair pair_type; - typedef std::map imap_type; - typedef std::pair ipair_type; - - /* Create output intersection partition */ - INT_PART = mxCreateNumericMatrix(s_x, s_y, mxUINT32_CLASS, mxREAL); - boost::multi_array_ref int_part((int*)mxGetPr(INT_PART), boost::extents[s_x][s_y], boost::fortran_storage_order()); - - /* Scan all partitions */ - int num_regions; - map_type out_lut; - imap_type label_lut; - int next_label = 1; - int curr_label = 0; - for(std::size_t xx=0; xx ilabel_lut; - for(map_type::const_iterator it=out_lut.begin(); it!=out_lut.end(); ++it) - { - ilabel_lut.insert(std::pair((*it).second, (*it).first)); - } - - /* Perform the mergings, if provided */ - if(nrhs==2) - { - if (!mxIsCell(MERSEQS)) - mexErrMsgTxt("Second argument mer_seqs must be a cell"); - - int num_hierarchies = mxGetNumberOfElements(MERSEQS); - - for(std::size_t ii=0; ii::iterator it = ilabel_lut.find(*set_it); - if (it==ilabel_lut.end()) - mexErrMsgTxt("The label should be at the lut"); - (*it).second.push_back(parent_label); - } - } - } - } - - /* Store the LUT as a cell */ - int dims_out[1]; - dims_out[0] = num_regions; - LUT = mxCreateCellArray(1, dims_out); - - for(std::map::const_iterator it=ilabel_lut.begin(); it!=ilabel_lut.end(); ++it) - { - mxArray* curr_entry = mxCreateNumericMatrix(1, (*it).second.size(), mxUINT32_CLASS, mxREAL); - int* curr_pr = (int*)mxGetPr(curr_entry); - std::size_t curr_jj = 0; - for(vector_type::const_iterator vec_it=(*it).second.begin(); vec_it!=(*it).second.end(); ++vec_it) - { - curr_pr[curr_jj] = *vec_it; - curr_jj++; - } - mxSetCell(LUT, (std::size_t)((*it).first-1), curr_entry); - } -} diff --git a/mcg/MCG-Full/src/aux/mex_ucm2hier.cpp b/mcg/MCG-Full/src/aux/mex_ucm2hier.cpp deleted file mode 100644 index c410e71..0000000 --- a/mcg/MCG-Full/src/aux/mex_ucm2hier.cpp +++ /dev/null @@ -1,268 +0,0 @@ -// ------------------------------------------------------------------------ -// Copyright (C) -// Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -// University of California Berkeley (UCB) - USA -// -// Jordi Pont-Tuset -// Pablo Arbelaez -// June 2014 -// ------------------------------------------------------------------------ -// This file is part of the MCG package presented in: -// Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -// "Multiscale Combinatorial Grouping," -// Computer Vision and Pattern Recognition (CVPR) 2014. -// Please consider citing the paper if you use this code. -// ------------------------------------------------------------------------ -#include "mex.h" -#include "matlab_multiarray.hpp" -#include -#include -#include -#include -#include - -using namespace std; - - -struct cont_elem -{ - cont_elem(size_t new_x, size_t new_y, size_t new_n1_x, size_t new_n1_y, size_t new_n2_x, size_t new_n2_y) - : x(new_x), y(new_y), n1_x(new_n1_x), n1_y(new_n1_y), n2_x(new_n2_x), n2_y(new_n2_y) - { - } - - size_t x; - size_t y; - size_t n1_x; - size_t n1_y; - size_t n2_x; - size_t n2_y; -}; - -void insert_labels_to_merge(double lab1,double lab2,list >& to_merge) -{ - list >::iterator l1 = to_merge.begin(); - for( ; l1!=to_merge.end(); ++l1) - if (l1->find(lab1) != l1->end()) - break; - list >::iterator l2 = to_merge.begin(); - for( ; l2!=to_merge.end(); ++l2) - if (l2->find(lab2) != l2->end()) - break; - - if (l1==to_merge.end() && l2==to_merge.end()) // Neither label found --> New set - { - set to_put; - to_put.insert(lab1); - to_put.insert(lab2); - to_merge.push_back(to_put); - } - else if (l1==to_merge.end() && l2!=to_merge.end()) // Found one of the two in one set --> Add the other - l2->insert(lab1); - else if (l1!=to_merge.end() && l2==to_merge.end()) // Found one of the two in one set --> Add the other - l1->insert(lab2); - else if (l1!=l2) // Both found in different sets --> Merge the two sets - { - l1->insert(l2->begin(), l2->end()); - to_merge.erase(l2); - } -} - - -void mexFunction( int nlhs, mxArray *plhs[], - int nrhs, const mxArray*prhs[] ) -{ - if(nrhs!=2) - mexErrMsgTxt("There should be 2 input parameters"); - - /* Input parameters */ - ConstMatlabMultiArray lp(prhs[0]); - ConstMatlabMultiArray ucm2(prhs[1]); - - std::size_t sx = lp.shape()[0]; - std::size_t sy = lp.shape()[1]; - - - /*-------------------------------------------------------------*/ - /* Create LUT of contour positions and sets of labels to merge */ - /*-------------------------------------------------------------*/ - typedef map > > map_type; - map_type ucm_th_leaves_pairs; - - /* Scan horizontal contours*/ - for (std::size_t xx=2; xx<2*sx; xx+=2) - { - for (std::size_t yy=1; yy<2*sy; yy+=2) - { - if (ucm2[xx][yy]>0) - { - cont_elem cont(xx,yy,(xx/2)-1,(yy-1)/2,(xx/2),(yy-1)/2); - double lab1 = min(lp[cont.n1_x][cont.n1_y],lp[cont.n2_x][cont.n2_y]); - double lab2 = max(lp[cont.n1_x][cont.n1_y],lp[cont.n2_x][cont.n2_y]); - - /* Get the sets of regions to be merged */ - /* In one threshold there can be more than one region forming */ - map_type::iterator map_it = ucm_th_leaves_pairs.find(ucm2[xx][yy]); - if (map_it==ucm_th_leaves_pairs.end()) // New ucm threshold - { - set set_to_put; - set_to_put.insert(lab1); - set_to_put.insert(lab2); - list > to_put; - to_put.push_back(set_to_put); // Add up and down neighbors - ucm_th_leaves_pairs.insert(map_type::value_type(ucm2[xx][yy], to_put)); - } - else - insert_labels_to_merge(lab1,lab2,map_it->second); - } - } - } - - /* Scan vertical contours*/ - for (std::size_t xx=1; xx<2*sx; xx+=2) - { - for (std::size_t yy=2; yy<2*sy; yy+=2) - { - if (ucm2[xx][yy]>0) - { - cont_elem cont(xx,yy,(xx-1)/2,(yy/2)-1,(xx-1)/2,(yy/2)); - - double lab1 = min(lp[cont.n1_x][cont.n1_y],lp[cont.n2_x][cont.n2_y]); - double lab2 = max(lp[cont.n1_x][cont.n1_y],lp[cont.n2_x][cont.n2_y]); - - /* Get the sets of regions to be merged */ - /* In one threshold there can be more than one region forming */ - map_type::iterator map_it = ucm_th_leaves_pairs.find(ucm2[xx][yy]); - if (map_it==ucm_th_leaves_pairs.end()) // New ucm threshold - { - set set_to_put; - set_to_put.insert(lab1); - set_to_put.insert(lab2); - list > to_put; - to_put.push_back(set_to_put); // Add left and right neighbors - ucm_th_leaves_pairs.insert(map_type::value_type(ucm2[xx][yy], to_put)); - } - else - insert_labels_to_merge(lab1,lab2,map_it->second); - } - } - } - - /* Number of thresholds is number of mergings */ - int n_merges = ucm_th_leaves_pairs.size(); - /*-------------------------------------------------------------*/ - - - /*-----------------------------------------------------------*/ - /* Scan all thresholds of the UCM in increasing order and */ - /* do the mergings of the N regions that 'disappear' */ - /*-----------------------------------------------------------*/ - - /* Get number of leaves */ - double curr_max = 0; - for (std::size_t xx=0; xx lut(n_leaves); - vector > ilut(n_leaves); - for (size_t ll=0; ll parent_labels; - vector > children_labels; - vector start_ths(n_leaves,0); - - map_type::iterator it = ucm_th_leaves_pairs.begin(); - for ( ; it!=ucm_th_leaves_pairs.end(); ++it) - { - list >& leaves_to_merge = it->second; - list > regs_to_merge; - - list >::iterator it3 = leaves_to_merge.begin(); - for ( ; it3!=leaves_to_merge.end(); ++it3) - { - /* Get the labels of the children regions from the leave labels */ - set::iterator it4 = it3->begin(); - set::iterator it4b = it3->begin(); - ++it4b; - - for( ; it4b!=it3->end(); ++it4b) - insert_labels_to_merge(lut[*it4-1],lut[*it4b-1],regs_to_merge); - } - - it3 = regs_to_merge.begin(); - for ( ; it3!=regs_to_merge.end(); ++it3) - { - curr_max += 1; - ilut.push_back(set()); - - /* Update LUT */ - set to_update(*it3); - while(!to_update.empty()) - { - /* Get the first to update */ - double curr = *(to_update.begin()); - to_update.erase(to_update.begin()); - if (lut[curr-1]!=curr) - to_update.insert(lut[curr-1]); - - set::iterator it5 = ilut[curr-1].begin(); - for( ; it5!=ilut[curr-1].end(); ++it5) - { - lut[*it5-1] = curr_max; - ilut[curr_max-1].insert(*it5); - } - ilut[curr-1].clear(); - } - - /* Copy the labels to the merging sequence */ - children_labels.push_back(list(it3->begin(),it3->end())); - n_max_children = max(n_max_children,it3->size()); - - /* Add parent to the LUT and to out*/ - lut.push_back(curr_max); - parent_labels.push_back(curr_max); - - /* Store the start contour threshold */ - start_ths.push_back(it->first); - } - } - double n_regs = curr_max; - /*-----------------------------------------------------------*/ - - if(n_regs!=start_ths.size()) - mexErrMsgTxt("Oh oh"); - - /* Output allocation */ - plhs[0] = mxCreateDoubleMatrix(parent_labels.size(),n_max_children+1,mxREAL); - MatlabMultiArray ms_out(plhs[0]); - plhs[1] = mxCreateDoubleMatrix(n_regs,1,mxREAL); - MatlabMultiArray start_ths_out(plhs[1]); - plhs[2] = mxCreateDoubleMatrix(n_regs,1,mxREAL); - MatlabMultiArray end_ths_out(plhs[2]); - - /* Copy data to output */ - for (size_t ii=0; ii::iterator it4 = children_labels[ii].begin(); - for (size_t jj=0 ; it4!=children_labels[ii].end(); ++it4, ++jj) - { - ms_out[ii][jj] = *it4; - end_ths_out[*it4-1][0] = start_ths_out[parent_labels[ii]-1][0]; - } - } - end_ths_out[n_regs-1][0] = 1; -} - diff --git a/mcg/MCG-Full/src/aux/ms_matrix2struct.m b/mcg/MCG-Full/src/aux/ms_matrix2struct.m deleted file mode 100644 index 06363b6..0000000 --- a/mcg/MCG-Full/src/aux/ms_matrix2struct.m +++ /dev/null @@ -1,24 +0,0 @@ -% ------------------------------------------------------------------------ -% Copyright (C) -% Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -% University of California Berkeley (UCB) - USA -% -% Jordi Pont-Tuset -% Pablo Arbelaez -% June 2014 -% ------------------------------------------------------------------------ -% This file is part of the MCG package presented in: -% Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -% "Multiscale Combinatorial Grouping," -% Computer Vision and Pattern Recognition (CVPR) 2014. -% Please consider citing the paper if you use this code. -% ------------------------------------------------------------------------ - -function ms_struct = ms_matrix2struct( ms_matrix ) - for ii=1:size(ms_matrix,1) - ms_struct(ii).parent = ms_matrix(ii,end); %#ok - children = ms_matrix(ii,1:end-1); - children(children==0) = []; - ms_struct(ii).children = children; %#ok - end -end diff --git a/mcg/MCG-Full/src/aux/plot_one_soa.m b/mcg/MCG-Full/src/aux/plot_one_soa.m deleted file mode 100644 index 7e7f8a1..0000000 --- a/mcg/MCG-Full/src/aux/plot_one_soa.m +++ /dev/null @@ -1,26 +0,0 @@ -% ------------------------------------------------------------------------ -% Copyright (C) -% Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -% University of California Berkeley (UCB) - USA -% -% Jordi Pont-Tuset -% Pablo Arbelaez -% June 2014 -% ------------------------------------------------------------------------ -% This file is part of the MCG package presented in: -% Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -% "Multiscale Combinatorial Grouping," -% Computer Vision and Pattern Recognition (CVPR) 2014. -% Please consider citing the paper if you use this code. -% ------------------------------------------------------------------------ - -function new_legends = plot_one_soa(soa, id, measure, color, old_legends) -if isfield(soa,id) - plot(soa.(id).mean_n_masks, soa.(id).(measure), color) - new_legends = {old_legends{:}, soa.(id).id}; -else - new_legends = old_legends; -end - -end - diff --git a/mcg/MCG-Full/src/aux/seg2gridbmap.m b/mcg/MCG-Full/src/aux/seg2gridbmap.m deleted file mode 100644 index a2471b4..0000000 --- a/mcg/MCG-Full/src/aux/seg2gridbmap.m +++ /dev/null @@ -1,105 +0,0 @@ -% ------------------------------------------------------------------------ -% Copyright (C) -% Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -% University of California Berkeley (UCB) - USA -% -% Jordi Pont-Tuset -% Pablo Arbelaez -% June 2014 -% ------------------------------------------------------------------------ -% This file is part of the MCG package presented in: -% Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -% "Multiscale Combinatorial Grouping," -% Computer Vision and Pattern Recognition (CVPR) 2014. -% Please consider citing the paper if you use this code. -% ------------------------------------------------------------------------ - -function [gridbmap, idx_neighbors, junctions] = seg2gridbmap(seg, borders) -% [gridbmap, idx_neighbors, junctions] = seg2gridbmap(seg, borders) -% -% From a segmentation, compute a binary boundary map in the countoru grid -% -% INPUTS -% seg Segments labeled from 1..k. -% borders Whether boundary with borders is selected (1), not (0), or only -% on those non-0 regions (2) -% -% OUTPUTS -% gridbmap Binary boundary map on contour grid. -% -% Jordi Pont-Tuset -% January 2012 - -if nargin==0 - %% Dummy test - seg = [1 1 1 - 1 1 1 - 2 3 4]; -else - seg = double(seg); -end -if nargin<2 - borders = 0; -end - -%% To gridbmap -gridbmap = zeros(size(seg)*2 +1); -gridbmap(2:2:end, 3:2:end-1) = (seg(:,1:end-1)~=seg(:,2:end)); -gridbmap(3:2:end-1, 2:2:end) = (seg(1:end-1,:)~=seg(2:end,:)); - -if nargout>1 - %% Neighbor indices - idx_neighbors.matrix_min = zeros(size(seg)*2 +1); - idx_neighbors.matrix_max = zeros(size(seg)*2 +1); - - idx_neighbors.matrix_min(2:2:end, 3:2:end-1) = gridbmap(2:2:end, 3:2:end-1).*min(seg(:,1:end-1), seg(:,2:end)); - idx_neighbors.matrix_max(2:2:end, 3:2:end-1) = gridbmap(2:2:end, 3:2:end-1).*max(seg(:,1:end-1), seg(:,2:end)); - - idx_neighbors.matrix_min(3:2:end-1, 2:2:end) = gridbmap(3:2:end-1, 2:2:end).*min(seg(1:end-1,:), seg(2:end,:)); - idx_neighbors.matrix_max(3:2:end-1, 2:2:end) = gridbmap(3:2:end-1, 2:2:end).*max(seg(1:end-1,:), seg(2:end,:)); - if borders - idx_neighbors.matrix_max(1, 2:2:end) = seg(1,:); - idx_neighbors.matrix_max(end, 2:2:end) = seg(end,:); - idx_neighbors.matrix_max(2:2:end, 1) = seg(:,1); - idx_neighbors.matrix_max(2:2:end, end) = seg(:,end); - end -end - - -if nargout>2 - %% Junctions - junctions.gridbmap = imfilter(gridbmap, [0 1 0; 1 0 1; 0 1 0]); - junctions.gridbmap = double(junctions.gridbmap>2); % Juntion with more than 2 neighbors - junctions.gridbmap(2:2:end, 2:2:end) = 0; - - tmp_seg = zeros(size(gridbmap)); - tmp_seg(2:2:end, 2:2:end) = seg; - - [y,x] = find(junctions.gridbmap); - - junctions.points = []; - for ii=1:length(x) - junctions.points(ii).x = x(ii); - junctions.points(ii).y = y(ii); - junctions.points(ii).neighs = ... - sort(unique([tmp_seg(y(ii)+1, x(ii)+1) - tmp_seg(y(ii)-1, x(ii)+1) - tmp_seg(y(ii)-1, x(ii)-1) - tmp_seg(y(ii)+1, x(ii)-1)])); - end -end - -if borders==1 - % Add borders of the image - gridbmap(2:2:end-1, 1) = 1; - gridbmap(2:2:end-1, end) = 1; - gridbmap(1, 2:2:end-1) = 1; - gridbmap(end, 2:2:end-1) = 1; -elseif borders==2 - gridbmap(2:2:end-1, 1) = (seg(:,1)~=0); - gridbmap(2:2:end-1, end) = (seg(:,end)~=0); - gridbmap(1, 2:2:end-1) = (seg(1,:)~=0); - gridbmap(end, 2:2:end-1) = (seg(end,:)~=0); -end - -% gridbmap = logical(gridbmap); \ No newline at end of file diff --git a/mcg/MCG-Full/src/aux/ucm2hier.m b/mcg/MCG-Full/src/aux/ucm2hier.m deleted file mode 100644 index 7eb2d86..0000000 --- a/mcg/MCG-Full/src/aux/ucm2hier.m +++ /dev/null @@ -1,55 +0,0 @@ -% ------------------------------------------------------------------------ -% Copyright (C) -% Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -% University of California Berkeley (UCB) - USA -% -% Jordi Pont-Tuset -% Pablo Arbelaez -% June 2014 -% ------------------------------------------------------------------------ -% This file is part of the MCG package presented in: -% Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -% "Multiscale Combinatorial Grouping," -% Computer Vision and Pattern Recognition (CVPR) 2014. -% Please consider citing the paper if you use this code. -% ------------------------------------------------------------------------ -% hierarchy = ucm2hier(ucm) -% ------------------------------------------------------------------------ -% Reads a UCM from file or directly as a matrix and converts it to a -% hierarcgy of regions (leaves partition and merging_sequence) where -% we accept non binary mergings, that is, more than one merging for -% a given threshold. -% ------------------------------------------------------------------------ - -function hierarchy = ucm2hier(ucm) -% UCM can be a file or the matrix -if ischar(ucm) % ucm refers to a file - % Get UCM -> Must be saved as a variable named 'ucm2' or 'ucm.strength' - load(ucm); - if ~exist('ucm2', 'var') - ucm2 = ucm.strength; - end -elseif (size(ucm,1)>2 && size(ucm,2)>2) % It is a full ucm - ucm2 = ucm; - clear ucm; -else - error('UCM type not accepted'); -end - -% Get leaves segmentation -tmp_ucm = ucm2; -tmp_ucm(1:2:end,1:2:end)=1; % Make the gridbmap connected -labels = bwlabel(tmp_ucm' == 0, 8); % Transposed for the scanning to be from - % left to right and from up to down -labels = labels'; - -% --------------------------- - -hierarchy.ucm2 = ucm2; -hierarchy.leaves_part = labels(2:2:end, 2:2:end); - -% To hierarchy -[hierarchy.ms_matrix, hierarchy.start_ths, hierarchy.end_ths] = mex_ucm2hier(hierarchy.leaves_part, hierarchy.ucm2); - -% Store it also as a struct -hierarchy.ms_struct = ms_matrix2struct(hierarchy.ms_matrix); diff --git a/mcg/MCG-Full/src/aux/write_jaccard_to_file.m b/mcg/MCG-Full/src/aux/write_jaccard_to_file.m deleted file mode 100644 index 62bccf7..0000000 --- a/mcg/MCG-Full/src/aux/write_jaccard_to_file.m +++ /dev/null @@ -1,23 +0,0 @@ -% ------------------------------------------------------------------------ -% Copyright (C) -% Universitat Politecnica de Catalunya BarcelonaTech (UPC) - Spain -% University of California Berkeley (UCB) - USA -% -% Jordi Pont-Tuset -% Pablo Arbelaez -% June 2014 -% ------------------------------------------------------------------------ -% This file is part of the MCG package presented in: -% Arbelaez P, Pont-Tuset J, Barron J, Marques F, Malik J, -% "Multiscale Combinatorial Grouping," -% Computer Vision and Pattern Recognition (CVPR) 2014. -% Please consider citing the paper if you use this code. -% ------------------------------------------------------------------------ -function write_jaccard_to_file( stats, filename ) - -fid = fopen(filename,'w'); -fprintf(fid, 'ncands\tjac_class\tjac_instance\n'); -fprintf(fid, '%d\t%f\t%f\n', [stats.mean_n_masks; stats.jaccard_class; stats.jaccard_object]); -fclose(fid); - -