Selecte search program understanding

Keywords: MATLAB Python pip

1. Background

Take on the previous blog post, because the selective search (ss) algorithm is needed in fast RCNN, so the SS paper and program are understood.

In SS paper, we propose to use multiple color spaces to extract the same features in each color space. First, we get the initial region according to the previous algorithm, and then merge the proposed regions according to similarity criteria to get the final proposal. Principle Understanding Reference Blog http://blog.csdn.net/mao_kun/article/details/50576003 . The complete code of SS has matlab version and python version, which can be found on the internet. Just install it according to the instructions. Many programs in the matlab version are written in C++ as the underlying language, so the interface of C++ in MATLAB should be installed first. The Python version only needs a simple pip installation of SS in command. The code is found on the author's home page, as well as in my download channel. The following is the understanding and application of MATLAB code.

2. Code understanding

% This demo shows how to use the software described in our IJCV paper: 
%   Selective Search for Object Recognition,
%   J.R.R. Uijlings, K.E.A. van de Sande, T. Gevers, A.W.M. Smeulders, IJCV 2013
%%
close all;clear;clc;
addpath('Dependencies');

fprintf('Demo of how to run the code for:\n');
fprintf('   J. Uijlings, K. van de Sande, T. Gevers, A. Smeulders\n');
fprintf('   Segmentation as Selective Search for Object Recognition\n');
fprintf('   IJCV 2013\n\n');

% Compile anisotropic gaussian filter
if(~exist('anigauss'))
    fprintf('Compiling the anisotropic gauss filtering of:\n');
    fprintf('   J. Geusebroek, A. Smeulders, and J. van de Weijer\n');
    fprintf('   Fast anisotropic gauss filtering\n');
    fprintf('   IEEE Transactions on Image Processing, 2003\n');
    fprintf('Source code/Project page:\n');
    fprintf('   http://staff.science.uva.nl/~mark/downloads.html#anigauss\n\n');
    mex Dependencies/anigaussm/anigauss_mex.c Dependencies/anigaussm/anigauss.c -output anigauss
end

if(~exist('mexCountWordsIndex'))
    mex Dependencies/mexCountWordsIndex.cpp
end

% Compile the code of Felzenszwalb and Huttenlocher, IJCV 2004.
if(~exist('mexFelzenSegmentIndex'))
    fprintf('Compiling the segmentation algorithm of:\n');
    fprintf('   P. Felzenszwalb and D. Huttenlocher\n');
    fprintf('   Efficient Graph-Based Image Segmentation\n');
    fprintf('   International Journal of Computer Vision, 2004\n');
    fprintf('Source code/Project page:\n');
    fprintf('   http://www.cs.brown.edu/~pff/segment/\n');
    fprintf('Note: A small Matlab wrapper was made.\n');
%     fprintf('   
    mex Dependencies/FelzenSegment/mexFelzenSegmentIndex.cpp -output mexFelzenSegmentIndex;
end

%%
% Parameters. Note that this controls the number of hierarchical
% segmentations which are combined.
colorTypes = {'Hsv', 'Lab', 'RGI', 'H', 'Intensity'};%Here is quality All color spaces of patterns
colorType = colorTypes{3}; % Single color space for demo
% colorType = colorTypes(1:2); stay demo Can not achieve multiple color spaces
% RGI More areas containing masses were obtained.
% H The deviation is large.


% Here you specify which similarity functions to use in merging
simFunctionHandles = {@SSSimColourTextureSizeFillOrig, @SSSimTextureSizeFill, @SSSimBoxFillOrig, @SSSimSize};%quality Similarity criterion of patterns
simFunctionHandles = simFunctionHandles(1:2); % Two different merging strategies

% Thresholds for the Felzenszwalb and Huttenlocher segmentation algorithm.
% Note that by default, we set minSize = k, and sigma = 0.8.
k = 200; % controls size of segments of initial segmentation. 
minSize = k;
sigma = 0.8;
%%
% As an example, use a single image
% Original example
% images = {'000015.jpg'};
%Vehicle pictures
% im=imread('C:\Users\Administrator\Desktop\SSmatlab\Pseudo-color Enhancement Program\vehicle.jpg');
% bird
im=imread('C:\Users\Administrator\Desktop\SSmatlab\Pseudo-color Enhancement Program\bird.jpg');
%Breast picture
% load('C:\Users\Administrator\Desktop\data base\Breast data\ICYL.mat');
% im= ICYL(3,:,:);
% im=reshape(im,[1000 600]);
% n=max(im(:));
% map=colormap(jet(n));
% res = grs2rgb1(im,map);
% im=res;
% figure 
% imshow(im, 'DisplayRange',[]);
% title('ICY');

%%

% Perform Selective Search
[boxes blobIndIm blobBoxes hierarchy] = Image2HierarchicalGrouping(im, sigma, k, minSize, colorType, simFunctionHandles);
boxes = BoxRemoveDuplicates(boxes);

% save('C:\Users\Administrator\Desktop\SSmatlab\Pseudo-color Enhancement Program\vehicle.mat','boxes');
% save('C:\Users\Administrator\Desktop\SSmatlab\Pseudo-color Enhancement Program\breast.mat','boxes');
save('C:\Users\Administrator\Desktop\SSmatlab\Pseudo-color Enhancement Program\bird.mat','boxes');

% Show boxes
ShowRectsWithinImage(boxes, 5, 5, im);Proposals for visualization

% % Show blobs which result from first similarity function
hBlobs = RecreateBlobHierarchyIndIm(blobIndIm, blobBoxes, hierarchy{1});
ShowBlobs(hBlobs, 5, 5, im);%Visual segmentation of proposals

% Display all boxes on the original image
figure
imshow(im)
hold on
for i=1:size(boxes,1)
    x=boxes(i,1);
    y=boxes(i,2);
    w=boxes(i,4)-boxes(i,2);
    h=boxes(i,3)-boxes(i,1);
    rectangle('Position',[x,y,w,h],'EdgeColor','w','LineWidth',1)
    hold on
end
After running the original S S program, you can replace the image in demo with your own color image and get a region proposal independent of the class.

Different proposals can be obtained by choosing different color spaces. In practice, more proposals can be found when choosing RGI color spaces containing masses. Later, RGI's proposal will be used as input of fast RCNN, and then optimized continuously.


Posted by pastijalan on Tue, 11 Jun 2019 12:10:38 -0700