├── .gitattributes ├── .gitignore ├── COS_code ├── Cluster2img.m ├── Cosaliency_main.m ├── Gauss_normal.m ├── GetCoWeight.m ├── GetImVector.m ├── GetPositionW.m ├── GetSalWeight.m ├── Save_result.m ├── Single_saliency_main.m ├── colorspace.m ├── fn_RGB2Lab.m ├── gabor_fn.m └── kmeansPP.m ├── Demo_Cosaliency.m ├── Demo_single.m ├── Readme.txt ├── img_data ├── co_saliency_data │ └── football_player │ │ ├── 1181509254_83b4637c24.jpg │ │ ├── 1404827026_c17d926f18.jpg │ │ ├── 2279822388_5fd4f69026.jpg │ │ ├── 2279824890_ae67849e1d.jpg │ │ ├── 2400031115_389b150fd2.jpg │ │ ├── 2400032729_6aa1a2c9a6.jpg │ │ ├── 2802728933_48c608c880.jpg │ │ ├── 2803707385_ab4588bce3.jpg │ │ └── 413703262_61e3287314.jpg └── single_data │ ├── 0_21_21422.jpg │ └── 1_45_45397.jpg └── img_output ├── 1_45_45397_org.png └── 1_45_45397_single.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must end with two \r 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /COS_code/Cluster2img.m: -------------------------------------------------------------------------------- 1 | function [ Saliency_Map_single ] = Cluster2img( Cluster_Map, SaliencyWeight_all, Bin_num) 2 | %CLUSTER2IMG Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | Saliency_sig_temp=Cluster_Map; 6 | for j=1:Bin_num 7 | Saliency_sig_temp(Saliency_sig_temp==j)=SaliencyWeight_all(j); 8 | end 9 | Saliency_Map_single = imfilter(Saliency_sig_temp, fspecial('gaussian', [3, 3], 3)); 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /COS_code/Cosaliency_main.m: -------------------------------------------------------------------------------- 1 | function [ Saliency_Map_co, All_img] = Cosaliency_main( data, img_num, Scale, Bin_num) 2 | %% COSALIENCY_DCS Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | %% ------ Obtain the co-saliency for multiple images------------- 6 | %----- obtaining the features ----- 7 | All_vector = []; 8 | All_DisVector = []; 9 | All_img = []; 10 | for i=1:img_num 11 | img = data.image{i}; 12 | [imvector, temp_img, DisVector]=GetImVector(img, Scale, Scale,0); 13 | All_vector=[All_vector; imvector]; 14 | All_DisVector=[All_DisVector; DisVector]; 15 | All_img=[All_img temp_img]; 16 | end 17 | 18 | % ---- clustering via Kmeans++ ------- 19 | [idx,ctrs] = kmeansPP(All_vector',Bin_num); 20 | idx=idx'; 21 | ctrs=ctrs'; 22 | 23 | %----- clustering idx map --------- 24 | Cluster_Map = reshape(idx, Scale, Scale*img_num); 25 | 26 | %----- computing the Contrast cue ------- 27 | Sal_weight_co= Gauss_normal(GetSalWeight( ctrs,idx )); 28 | %----- computing the Spatial cue ------- 29 | Dis_weight_co= Gauss_normal(GetPositionW( idx, All_DisVector, Scale, Bin_num )); 30 | %----- computing the Corresponding cue ------- 31 | co_weight_co= Gauss_normal(GetCoWeight( idx, Scale, Scale )); 32 | 33 | %----- combining the Co-Saliency cues ----- 34 | SaliencyWeight=(Sal_weight_co .* Dis_weight_co .* co_weight_co); 35 | 36 | %----- generating the co-saliency map ----- 37 | Saliency_Map_co = Cluster2img( Cluster_Map, SaliencyWeight, Bin_num); 38 | 39 | end 40 | 41 | -------------------------------------------------------------------------------- /COS_code/Gauss_normal.m: -------------------------------------------------------------------------------- 1 | function [ output_args ] = Gauss_normal( input_args ) 2 | %GAUSS_NORMAL Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | output_args=input_args; 6 | 7 | [H W]=size(input_args); 8 | if W==1 9 | % output_args = 1 ./ (1 + exp(-input_args+max(input_args)/2)); 10 | output_args=gaussmf(input_args,[(max(input_args)-min(input_args))/2 max(input_args)]); 11 | else 12 | if H==W 13 | output_args=gaussmf(input_args,[(max(max(input_args))-min(min(input_args)))/2 max(max(input_args))]); 14 | % output_args = 1 ./ (1 + exp(-input_args+max(max(input_args))/2)); 15 | else 16 | for i = 1: W/H 17 | output_args(:,H*(i-1)+1:H*(i))=gaussmf(input_args(:,H*(i-1)+1:H*(i)),... 18 | [(max(max(input_args(:,H*(i-1)+1:H*(i))))-min(min(input_args(:,H*(i-1)+1:H*(i)))))... 19 | /2 max(max(input_args(:,H*(i-1)+1:H*(i))))]); 20 | % output_args(:,H*(i-1)+1:H*(i))= 1 ./ (1 + exp(-input_args(:,H*(i-1)+1:H*(i))... 21 | % +max(max(input_args(:,H*(i-1)+1:H*(i))))/2)); 22 | end 23 | end 24 | end 25 | end 26 | 27 | -------------------------------------------------------------------------------- /COS_code/GetCoWeight.m: -------------------------------------------------------------------------------- 1 | function [ co_weight] = GetCoWeight( idx, ScaleH, ScaleW ) 2 | % Get the co-weight between images 3 | 4 | Image_num = size(idx,1)/( ScaleH* ScaleW); 5 | Bin_num = max(idx); 6 | Img_Idx = reshape(idx, ScaleH, ScaleW*Image_num); 7 | 8 | Bin_Idx=zeros(Bin_num, Image_num); 9 | for i=1:Bin_num 10 | for j=1:Image_num 11 | Bin_Idx(i,j)=size(Img_Idx(Img_Idx(:, ScaleW*(j-1)+1:ScaleW*j)==i),1)/size(Img_Idx(Img_Idx==i),1); 12 | end 13 | end 14 | 15 | co_weight=zeros(Bin_num,1); 16 | for j=1:Bin_num 17 | Bin_Idx(j,:)=Bin_Idx(j,:)/sum(Bin_Idx(j,:)); 18 | co_weight(j)=mean((Bin_Idx(j,:)))/(std(Bin_Idx(j,:))+1); 19 | end 20 | 21 | end 22 | 23 | -------------------------------------------------------------------------------- /COS_code/GetImVector.m: -------------------------------------------------------------------------------- 1 | function [ All_vector All_img Dis_Vector] = GetImVector( img_data, ScaleH, ScaleW ,need_texture) 2 | % Get the vector of image 3 | % Input: 4 | % img_data: the RGB image. 5 | % ScaleH, ScaleW: image resize scale. 6 | % need_texture: 0-without Gabor, 1-with Gabor. 7 | % 8 | % Output: 9 | % All_vector: The image feature vector (color, texture); 10 | % All_img: The resized image; 11 | % Dis_Vector: The image cetner distance; 12 | 13 | if need_texture % Gabor parameters 14 | N=8; 15 | lambda = 8; 16 | theta = 0; 17 | psi = [0 pi/2]; 18 | gamma = 0.5; 19 | bw = 1; 20 | end 21 | 22 | All_img = imresize(img_data, [ScaleH, ScaleW]); 23 | 24 | if need_texture 25 | img_in = im2double(rgb2gray(All_img)); 26 | Gabor_img = zeros(ScaleH, ScaleW, N); 27 | for n=1:N 28 | gb = gabor_fn(bw,gamma,psi(1),lambda,theta)... 29 | + 1i * gabor_fn(bw,gamma,psi(2),lambda,theta); 30 | % gb is the n-th gabor filter 31 | Gabor_img(:,:,n) = imfilter(img_in, gb, 'symmetric'); 32 | % filter output to the n-th channel 33 | theta = theta + 2*pi/N; 34 | % next orientation 35 | end 36 | Gabor_img = sum(abs(Gabor_img).^2, 3).^0.5; 37 | end 38 | 39 | img2 = colorspace('Lab<-RGB',All_img); 40 | All_vector=zeros( ScaleH*ScaleW,3); 41 | 42 | if need_texture 43 | All_vector=zeros( ScaleH*ScaleW,4); 44 | end 45 | 46 | Dis_Vector=zeros( ScaleH*ScaleW,1); 47 | for j=1:ScaleH 48 | for i=1:ScaleW 49 | All_vector(j +(i-1)*ScaleH,1)=round(img2(j, i, 1)); 50 | All_vector(j +(i-1)*ScaleH,2)=round(img2(j, i, 2)); 51 | All_vector(j +(i-1)*ScaleH,3)=round(img2(j, i, 3)); 52 | if need_texture 53 | All_vector(j +(i-1)*ScaleH,4)=Gabor_img(j, i); 54 | end 55 | Dis_Vector(j +(i-1)*ScaleH)=round(sqrt((i-ScaleW/2)^2+(j-ScaleH/2)^2)); 56 | end 57 | end 58 | 59 | 60 | end 61 | 62 | -------------------------------------------------------------------------------- /COS_code/GetPositionW.m: -------------------------------------------------------------------------------- 1 | function [ Dis_weight ] = GetPositionW( idx, All_DisVector, ScaleW, Bin_num ) 2 | %GETPOSITIONW Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | Dis_weight=zeros(Bin_num,1); 6 | 7 | for i=1:Bin_num 8 | % Dis_weight(i)=1/(sum(All_DisVector(idx==i))/size(All_DisVector(idx==i),1)+1); 9 | x=sum(All_DisVector(idx==i))/size(All_DisVector(idx==i),1); 10 | Dis_weight(i)=gaussmf(x,[ScaleW 0]); 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /COS_code/GetSalWeight.m: -------------------------------------------------------------------------------- 1 | function [ Sal_weight ] = GetSalWeight( ctrs ,idx) 2 | %GETSALWEIGHT Summary of this function goes here 3 | 4 | bin_num=size(ctrs,1); 5 | bin_weight=zeros(bin_num,1); 6 | for i=1:bin_num 7 | bin_weight(i)=size(find(idx==i),1); 8 | end 9 | bin_weight=bin_weight/size(idx,1); 10 | Y = squareform(pdist(ctrs)).*repmat(bin_weight, [1, bin_num]); 11 | Sal_weight=sum(Y)'; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /COS_code/Save_result.m: -------------------------------------------------------------------------------- 1 | function [ h ] = Save_result( data, para, result) 2 | %SAVE_RESULT Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | for i=1:para.img_num 6 | im = data.image{i}; 7 | [imH imW imC] = size(im); 8 | imwrite(im, [para.result_path para.files_list(i,1).name '_org.png'],'png'); 9 | 10 | cosal = result.final_map(:, (1 + (i-1)*para.Scale):(i*para.Scale)); 11 | imwrite(imresize(cosal, [imH imW]), [para.result_path para.files_list(i,1).name(1:end-4) '_cosaliency.png'],'png'); 12 | 13 | sigsal = result.single_map(:, (1 + (i-1)*para.Scale):(i*para.Scale)); 14 | imwrite(imresize(sigsal, [imH imW]), [para.result_path para.files_list(i,1).name(1:end-4) '_single.png'],'png'); 15 | end 16 | 17 | h=1; 18 | end 19 | 20 | -------------------------------------------------------------------------------- /COS_code/Single_saliency_main.m: -------------------------------------------------------------------------------- 1 | function [ Saliency_Map_single ] = Single_saliency_main( data, img_num, Scale, Bin_num_single) 2 | %SINGLE_SALIENCY_MAIN Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | Saliency_Map_single = zeros([Scale,Scale*img_num]); 6 | 7 | for i=1:img_num 8 | img = data.image{i}; 9 | [imvector, ~, DisVector]=GetImVector(img, Scale, Scale,0); 10 | [idx,ctrs] = kmeansPP(imvector',Bin_num_single); 11 | idx=idx'; ctrs=ctrs'; 12 | Cluster_Map = reshape(idx, Scale, Scale); 13 | Sal_weight=GetSalWeight( ctrs,idx ); 14 | Dis_weight = GetPositionW( idx, DisVector, Scale, Bin_num_single ); 15 | Sal_weight= Gauss_normal(Sal_weight); 16 | Dis_weight= Gauss_normal(Dis_weight); 17 | SaliencyWeight_all=(Sal_weight .* Dis_weight); 18 | Saliency_sig_final = Cluster2img( Cluster_Map, SaliencyWeight_all, Bin_num_single); 19 | 20 | Saliency_Map_single(:,1+(i-1)*Scale:Scale+(i-1)*Scale)=Saliency_sig_final; 21 | end 22 | 23 | end 24 | 25 | -------------------------------------------------------------------------------- /COS_code/colorspace.m: -------------------------------------------------------------------------------- 1 | function varargout = colorspace(Conversion,varargin) 2 | %COLORSPACE Transform a color image between color representations. 3 | % B = COLORSPACE(S,A) transforms the color representation of image A 4 | % where S is a string specifying the conversion. The input array A 5 | % should be a real full double array of size Mx3 or MxNx3. The output B 6 | % is the same size as A. 7 | % 8 | % S tells the source and destination color spaces, S = 'dest<-src', or 9 | % alternatively, S = 'src->dest'. Supported color spaces are 10 | % 11 | % 'RGB' sRGB IEC 61966-2-1 12 | % 'YCbCr' Luma + Chroma ("digitized" version of Y'PbPr) 13 | % 'JPEG-YCbCr' Luma + Chroma space used in JFIF JPEG 14 | % 'YDbDr' SECAM Y'DbDr Luma + Chroma 15 | % 'YPbPr' Luma (ITU-R BT.601) + Chroma 16 | % 'YUV' NTSC PAL Y'UV Luma + Chroma 17 | % 'YIQ' NTSC Y'IQ Luma + Chroma 18 | % 'HSV' or 'HSB' Hue Saturation Value/Brightness 19 | % 'HSL' or 'HLS' Hue Saturation Luminance 20 | % 'HSI' Hue Saturation Intensity 21 | % 'XYZ' CIE 1931 XYZ 22 | % 'Lab' CIE 1976 L*a*b* (CIELAB) 23 | % 'Luv' CIE L*u*v* (CIELUV) 24 | % 'LCH' CIE L*C*H* (CIELCH) 25 | % 'CAT02 LMS' CIE CAT02 LMS 26 | % 27 | % All conversions assume 2 degree observer and D65 illuminant. 28 | % 29 | % Color space names are case insensitive and spaces are ignored. When 30 | % sRGB is the source or destination, it can be omitted. For example 31 | % 'yuv<-' is short for 'yuv<-rgb'. 32 | % 33 | % For sRGB, the values should be scaled between 0 and 1. Beware that 34 | % transformations generally do not constrain colors to be "in gamut." 35 | % Particularly, transforming from another space to sRGB may obtain 36 | % R'G'B' values outside of the [0,1] range. So the result should be 37 | % clamped to [0,1] before displaying: 38 | % image(min(max(B,0),1)); % Clamp B to [0,1] and display 39 | % 40 | % sRGB (Red Green Blue) is the (ITU-R BT.709 gamma-corrected) standard 41 | % red-green-blue representation of colors used in digital imaging. The 42 | % components should be scaled between 0 and 1. The space can be 43 | % visualized geometrically as a cube. 44 | % 45 | % Y'PbPr, Y'CbCr, Y'DbDr, Y'UV, and Y'IQ are related to sRGB by linear 46 | % transformations. These spaces separate a color into a grayscale 47 | % luminance component Y and two chroma components. The valid ranges of 48 | % the components depends on the space. 49 | % 50 | % HSV (Hue Saturation Value) is related to sRGB by 51 | % H = hexagonal hue angle (0 <= H < 360), 52 | % S = C/V (0 <= S <= 1), 53 | % V = max(R',G',B') (0 <= V <= 1), 54 | % where C = max(R',G',B') - min(R',G',B'). The hue angle H is computed on 55 | % a hexagon. The space is geometrically a hexagonal cone. 56 | % 57 | % HSL (Hue Saturation Lightness) is related to sRGB by 58 | % H = hexagonal hue angle (0 <= H < 360), 59 | % S = C/(1 - |2L-1|) (0 <= S <= 1), 60 | % L = (max(R',G',B') + min(R',G',B'))/2 (0 <= L <= 1), 61 | % where H and C are the same as in HSV. Geometrically, the space is a 62 | % double hexagonal cone. 63 | % 64 | % HSI (Hue Saturation Intensity) is related to sRGB by 65 | % H = polar hue angle (0 <= H < 360), 66 | % S = 1 - min(R',G',B')/I (0 <= S <= 1), 67 | % I = (R'+G'+B')/3 (0 <= I <= 1). 68 | % Unlike HSV and HSL, the hue angle H is computed on a circle rather than 69 | % a hexagon. 70 | % 71 | % CIE XYZ is related to sRGB by inverse gamma correction followed by a 72 | % linear transform. Other CIE color spaces are defined relative to XYZ. 73 | % 74 | % CIE L*a*b*, L*u*v*, and L*C*H* are nonlinear functions of XYZ. The L* 75 | % component is designed to match closely with human perception of 76 | % lightness. The other two components describe the chroma. 77 | % 78 | % CIE CAT02 LMS is the linear transformation of XYZ using the MCAT02 79 | % chromatic adaptation matrix. The space is designed to model the 80 | % response of the three types of cones in the human eye, where L, M, S, 81 | % correspond respectively to red ("long"), green ("medium"), and blue 82 | % ("short"). 83 | 84 | % Pascal Getreuer 2005-2010 85 | 86 | 87 | %%% Input parsing %%% 88 | if nargin < 2, error('Not enough input arguments.'); end 89 | [SrcSpace,DestSpace] = parse(Conversion); 90 | 91 | if nargin == 2 92 | Image = varargin{1}; 93 | elseif nargin >= 3 94 | Image = cat(3,varargin{:}); 95 | else 96 | error('Invalid number of input arguments.'); 97 | end 98 | 99 | FlipDims = (size(Image,3) == 1); 100 | 101 | if FlipDims, Image = permute(Image,[1,3,2]); end 102 | if ~isa(Image,'double'), Image = double(Image)/255; end 103 | if size(Image,3) ~= 3, error('Invalid input size.'); end 104 | 105 | SrcT = gettransform(SrcSpace); 106 | DestT = gettransform(DestSpace); 107 | 108 | if ~ischar(SrcT) && ~ischar(DestT) 109 | % Both source and destination transforms are affine, so they 110 | % can be composed into one affine operation 111 | T = [DestT(:,1:3)*SrcT(:,1:3),DestT(:,1:3)*SrcT(:,4)+DestT(:,4)]; 112 | Temp = zeros(size(Image)); 113 | Temp(:,:,1) = T(1)*Image(:,:,1) + T(4)*Image(:,:,2) + T(7)*Image(:,:,3) + T(10); 114 | Temp(:,:,2) = T(2)*Image(:,:,1) + T(5)*Image(:,:,2) + T(8)*Image(:,:,3) + T(11); 115 | Temp(:,:,3) = T(3)*Image(:,:,1) + T(6)*Image(:,:,2) + T(9)*Image(:,:,3) + T(12); 116 | Image = Temp; 117 | elseif ~ischar(DestT) 118 | Image = rgb(Image,SrcSpace); 119 | Temp = zeros(size(Image)); 120 | Temp(:,:,1) = DestT(1)*Image(:,:,1) + DestT(4)*Image(:,:,2) + DestT(7)*Image(:,:,3) + DestT(10); 121 | Temp(:,:,2) = DestT(2)*Image(:,:,1) + DestT(5)*Image(:,:,2) + DestT(8)*Image(:,:,3) + DestT(11); 122 | Temp(:,:,3) = DestT(3)*Image(:,:,1) + DestT(6)*Image(:,:,2) + DestT(9)*Image(:,:,3) + DestT(12); 123 | Image = Temp; 124 | else 125 | Image = feval(DestT,Image,SrcSpace); 126 | end 127 | 128 | %%% Output format %%% 129 | if nargout > 1 130 | varargout = {Image(:,:,1),Image(:,:,2),Image(:,:,3)}; 131 | else 132 | if FlipDims, Image = permute(Image,[1,3,2]); end 133 | varargout = {Image}; 134 | end 135 | 136 | return; 137 | 138 | 139 | function [SrcSpace,DestSpace] = parse(Str) 140 | % Parse conversion argument 141 | 142 | if ischar(Str) 143 | Str = lower(strrep(strrep(Str,'-',''),'=','')); 144 | k = find(Str == '>'); 145 | 146 | if length(k) == 1 % Interpret the form 'src->dest' 147 | SrcSpace = Str(1:k-1); 148 | DestSpace = Str(k+1:end); 149 | else 150 | k = find(Str == '<'); 151 | 152 | if length(k) == 1 % Interpret the form 'dest<-src' 153 | DestSpace = Str(1:k-1); 154 | SrcSpace = Str(k+1:end); 155 | else 156 | error(['Invalid conversion, ''',Str,'''.']); 157 | end 158 | end 159 | 160 | SrcSpace = alias(SrcSpace); 161 | DestSpace = alias(DestSpace); 162 | else 163 | SrcSpace = 1; % No source pre-transform 164 | DestSpace = Conversion; 165 | if any(size(Conversion) ~= 3), error('Transformation matrix must be 3x3.'); end 166 | end 167 | return; 168 | 169 | 170 | function Space = alias(Space) 171 | Space = strrep(strrep(Space,'cie',''),' ',''); 172 | 173 | if isempty(Space) 174 | Space = 'rgb'; 175 | end 176 | 177 | switch Space 178 | case {'ycbcr','ycc'} 179 | Space = 'ycbcr'; 180 | case {'hsv','hsb'} 181 | Space = 'hsv'; 182 | case {'hsl','hsi','hls'} 183 | Space = 'hsl'; 184 | case {'rgb','yuv','yiq','ydbdr','ycbcr','jpegycbcr','xyz','lab','luv','lch'} 185 | return; 186 | end 187 | return; 188 | 189 | 190 | function T = gettransform(Space) 191 | % Get a colorspace transform: either a matrix describing an affine transform, 192 | % or a string referring to a conversion subroutine 193 | switch Space 194 | case 'ypbpr' 195 | T = [0.299,0.587,0.114,0;-0.1687367,-0.331264,0.5,0;0.5,-0.418688,-0.081312,0]; 196 | case 'yuv' 197 | % sRGB to NTSC/PAL YUV 198 | % Wikipedia: http://en.wikipedia.org/wiki/YUV 199 | T = [0.299,0.587,0.114,0;-0.147,-0.289,0.436,0;0.615,-0.515,-0.100,0]; 200 | case 'ydbdr' 201 | % sRGB to SECAM YDbDr 202 | % Wikipedia: http://en.wikipedia.org/wiki/YDbDr 203 | T = [0.299,0.587,0.114,0;-0.450,-0.883,1.333,0;-1.333,1.116,0.217,0]; 204 | case 'yiq' 205 | % sRGB in [0,1] to NTSC YIQ in [0,1];[-0.595716,0.595716];[-0.522591,0.522591]; 206 | % Wikipedia: http://en.wikipedia.org/wiki/YIQ 207 | T = [0.299,0.587,0.114,0;0.595716,-0.274453,-0.321263,0;0.211456,-0.522591,0.311135,0]; 208 | case 'ycbcr' 209 | % sRGB (range [0,1]) to ITU-R BRT.601 (CCIR 601) Y'CbCr 210 | % Wikipedia: http://en.wikipedia.org/wiki/YCbCr 211 | % Poynton, Equation 3, scaling of R'G'B to Y'PbPr conversion 212 | T = [65.481,128.553,24.966,16;-37.797,-74.203,112.0,128;112.0,-93.786,-18.214,128]; 213 | case 'jpegycbcr' 214 | % Wikipedia: http://en.wikipedia.org/wiki/YCbCr 215 | T = [0.299,0.587,0.114,0;-0.168736,-0.331264,0.5,0.5;0.5,-0.418688,-0.081312,0.5]*255; 216 | case {'rgb','xyz','hsv','hsl','lab','luv','lch','cat02lms'} 217 | T = Space; 218 | otherwise 219 | error(['Unknown color space, ''',Space,'''.']); 220 | end 221 | return; 222 | 223 | 224 | function Image = rgb(Image,SrcSpace) 225 | % Convert to sRGB from 'SrcSpace' 226 | switch SrcSpace 227 | case 'rgb' 228 | return; 229 | case 'hsv' 230 | % Convert HSV to sRGB 231 | Image = huetorgb((1 - Image(:,:,2)).*Image(:,:,3),Image(:,:,3),Image(:,:,1)); 232 | case 'hsl' 233 | % Convert HSL to sRGB 234 | L = Image(:,:,3); 235 | Delta = Image(:,:,2).*min(L,1-L); 236 | Image = huetorgb(L-Delta,L+Delta,Image(:,:,1)); 237 | case {'xyz','lab','luv','lch','cat02lms'} 238 | % Convert to CIE XYZ 239 | Image = xyz(Image,SrcSpace); 240 | % Convert XYZ to RGB 241 | T = [3.2406, -1.5372, -0.4986; -0.9689, 1.8758, 0.0415; 0.0557, -0.2040, 1.057]; 242 | R = T(1)*Image(:,:,1) + T(4)*Image(:,:,2) + T(7)*Image(:,:,3); % R 243 | G = T(2)*Image(:,:,1) + T(5)*Image(:,:,2) + T(8)*Image(:,:,3); % G 244 | B = T(3)*Image(:,:,1) + T(6)*Image(:,:,2) + T(9)*Image(:,:,3); % B 245 | % Desaturate and rescale to constrain resulting RGB values to [0,1] 246 | AddWhite = -min(min(min(R,G),B),0); 247 | R = R + AddWhite; 248 | G = G + AddWhite; 249 | B = B + AddWhite; 250 | % Apply gamma correction to convert linear RGB to sRGB 251 | Image(:,:,1) = gammacorrection(R); % R' 252 | Image(:,:,2) = gammacorrection(G); % G' 253 | Image(:,:,3) = gammacorrection(B); % B' 254 | otherwise % Conversion is through an affine transform 255 | T = gettransform(SrcSpace); 256 | temp = inv(T(:,1:3)); 257 | T = [temp,-temp*T(:,4)]; 258 | R = T(1)*Image(:,:,1) + T(4)*Image(:,:,2) + T(7)*Image(:,:,3) + T(10); 259 | G = T(2)*Image(:,:,1) + T(5)*Image(:,:,2) + T(8)*Image(:,:,3) + T(11); 260 | B = T(3)*Image(:,:,1) + T(6)*Image(:,:,2) + T(9)*Image(:,:,3) + T(12); 261 | Image(:,:,1) = R; 262 | Image(:,:,2) = G; 263 | Image(:,:,3) = B; 264 | end 265 | 266 | % Clip to [0,1] 267 | Image = min(max(Image,0),1); 268 | return; 269 | 270 | 271 | function Image = xyz(Image,SrcSpace) 272 | % Convert to CIE XYZ from 'SrcSpace' 273 | WhitePoint = [0.950456,1,1.088754]; 274 | 275 | switch SrcSpace 276 | case 'xyz' 277 | return; 278 | case 'luv' 279 | % Convert CIE L*uv to XYZ 280 | WhitePointU = (4*WhitePoint(1))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); 281 | WhitePointV = (9*WhitePoint(2))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); 282 | L = Image(:,:,1); 283 | Y = (L + 16)/116; 284 | Y = invf(Y)*WhitePoint(2); 285 | U = Image(:,:,2)./(13*L + 1e-6*(L==0)) + WhitePointU; 286 | V = Image(:,:,3)./(13*L + 1e-6*(L==0)) + WhitePointV; 287 | Image(:,:,1) = -(9*Y.*U)./((U-4).*V - U.*V); % X 288 | Image(:,:,2) = Y; % Y 289 | Image(:,:,3) = (9*Y - (15*V.*Y) - (V.*Image(:,:,1)))./(3*V); % Z 290 | case {'lab','lch'} 291 | Image = lab(Image,SrcSpace); 292 | % Convert CIE L*ab to XYZ 293 | fY = (Image(:,:,1) + 16)/116; 294 | fX = fY + Image(:,:,2)/500; 295 | fZ = fY - Image(:,:,3)/200; 296 | Image(:,:,1) = WhitePoint(1)*invf(fX); % X 297 | Image(:,:,2) = WhitePoint(2)*invf(fY); % Y 298 | Image(:,:,3) = WhitePoint(3)*invf(fZ); % Z 299 | case 'cat02lms' 300 | % Convert CAT02 LMS to XYZ 301 | T = inv([0.7328, 0.4296, -0.1624;-0.7036, 1.6975, 0.0061; 0.0030, 0.0136, 0.9834]); 302 | L = Image(:,:,1); 303 | M = Image(:,:,2); 304 | S = Image(:,:,3); 305 | Image(:,:,1) = T(1)*L + T(4)*M + T(7)*S; % X 306 | Image(:,:,2) = T(2)*L + T(5)*M + T(8)*S; % Y 307 | Image(:,:,3) = T(3)*L + T(6)*M + T(9)*S; % Z 308 | otherwise % Convert from some gamma-corrected space 309 | % Convert to sRGB 310 | Image = rgb(Image,SrcSpace); 311 | % Undo gamma correction 312 | R = invgammacorrection(Image(:,:,1)); 313 | G = invgammacorrection(Image(:,:,2)); 314 | B = invgammacorrection(Image(:,:,3)); 315 | % Convert RGB to XYZ 316 | T = inv([3.2406, -1.5372, -0.4986; -0.9689, 1.8758, 0.0415; 0.0557, -0.2040, 1.057]); 317 | Image(:,:,1) = T(1)*R + T(4)*G + T(7)*B; % X 318 | Image(:,:,2) = T(2)*R + T(5)*G + T(8)*B; % Y 319 | Image(:,:,3) = T(3)*R + T(6)*G + T(9)*B; % Z 320 | end 321 | return; 322 | 323 | 324 | function Image = hsv(Image,SrcSpace) 325 | % Convert to HSV 326 | Image = rgb(Image,SrcSpace); 327 | V = max(Image,[],3); 328 | S = (V - min(Image,[],3))./(V + (V == 0)); 329 | Image(:,:,1) = rgbtohue(Image); 330 | Image(:,:,2) = S; 331 | Image(:,:,3) = V; 332 | return; 333 | 334 | 335 | function Image = hsl(Image,SrcSpace) 336 | % Convert to HSL 337 | switch SrcSpace 338 | case 'hsv' 339 | % Convert HSV to HSL 340 | MaxVal = Image(:,:,3); 341 | MinVal = (1 - Image(:,:,2)).*MaxVal; 342 | L = 0.5*(MaxVal + MinVal); 343 | temp = min(L,1-L); 344 | Image(:,:,2) = 0.5*(MaxVal - MinVal)./(temp + (temp == 0)); 345 | Image(:,:,3) = L; 346 | otherwise 347 | Image = rgb(Image,SrcSpace); % Convert to sRGB 348 | % Convert sRGB to HSL 349 | MinVal = min(Image,[],3); 350 | MaxVal = max(Image,[],3); 351 | L = 0.5*(MaxVal + MinVal); 352 | temp = min(L,1-L); 353 | S = 0.5*(MaxVal - MinVal)./(temp + (temp == 0)); 354 | Image(:,:,1) = rgbtohue(Image); 355 | Image(:,:,2) = S; 356 | Image(:,:,3) = L; 357 | end 358 | return; 359 | 360 | 361 | function Image = lab(Image,SrcSpace) 362 | % Convert to CIE L*a*b* (CIELAB) 363 | WhitePoint = [0.950456,1,1.088754]; 364 | 365 | switch SrcSpace 366 | case 'lab' 367 | return; 368 | case 'lch' 369 | % Convert CIE L*CH to CIE L*ab 370 | C = Image(:,:,2); 371 | Image(:,:,2) = cos(Image(:,:,3)*pi/180).*C; % a* 372 | Image(:,:,3) = sin(Image(:,:,3)*pi/180).*C; % b* 373 | otherwise 374 | Image = xyz(Image,SrcSpace); % Convert to XYZ 375 | % Convert XYZ to CIE L*a*b* 376 | X = Image(:,:,1)/WhitePoint(1); 377 | Y = Image(:,:,2)/WhitePoint(2); 378 | Z = Image(:,:,3)/WhitePoint(3); 379 | fX = f(X); 380 | fY = f(Y); 381 | fZ = f(Z); 382 | Image(:,:,1) = 116*fY - 16; % L* 383 | Image(:,:,2) = 500*(fX - fY); % a* 384 | Image(:,:,3) = 200*(fY - fZ); % b* 385 | end 386 | return; 387 | 388 | 389 | function Image = luv(Image,SrcSpace) 390 | % Convert to CIE L*u*v* (CIELUV) 391 | WhitePoint = [0.950456,1,1.088754]; 392 | WhitePointU = (4*WhitePoint(1))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); 393 | WhitePointV = (9*WhitePoint(2))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); 394 | 395 | Image = xyz(Image,SrcSpace); % Convert to XYZ 396 | Denom = Image(:,:,1) + 15*Image(:,:,2) + 3*Image(:,:,3); 397 | U = (4*Image(:,:,1))./(Denom + (Denom == 0)); 398 | V = (9*Image(:,:,2))./(Denom + (Denom == 0)); 399 | Y = Image(:,:,2)/WhitePoint(2); 400 | L = 116*f(Y) - 16; 401 | Image(:,:,1) = L; % L* 402 | Image(:,:,2) = 13*L.*(U - WhitePointU); % u* 403 | Image(:,:,3) = 13*L.*(V - WhitePointV); % v* 404 | return; 405 | 406 | 407 | function Image = lch(Image,SrcSpace) 408 | % Convert to CIE L*ch 409 | Image = lab(Image,SrcSpace); % Convert to CIE L*ab 410 | H = atan2(Image(:,:,3),Image(:,:,2)); 411 | H = H*180/pi + 360*(H < 0); 412 | Image(:,:,2) = sqrt(Image(:,:,2).^2 + Image(:,:,3).^2); % C 413 | Image(:,:,3) = H; % H 414 | return; 415 | 416 | 417 | function Image = cat02lms(Image,SrcSpace) 418 | % Convert to CAT02 LMS 419 | Image = xyz(Image,SrcSpace); 420 | T = [0.7328, 0.4296, -0.1624;-0.7036, 1.6975, 0.0061; 0.0030, 0.0136, 0.9834]; 421 | X = Image(:,:,1); 422 | Y = Image(:,:,2); 423 | Z = Image(:,:,3); 424 | Image(:,:,1) = T(1)*X + T(4)*Y + T(7)*Z; % L 425 | Image(:,:,2) = T(2)*X + T(5)*Y + T(8)*Z; % M 426 | Image(:,:,3) = T(3)*X + T(6)*Y + T(9)*Z; % S 427 | return; 428 | 429 | 430 | function Image = huetorgb(m0,m2,H) 431 | % Convert HSV or HSL hue to RGB 432 | N = size(H); 433 | H = min(max(H(:),0),360)/60; 434 | m0 = m0(:); 435 | m2 = m2(:); 436 | F = H - round(H/2)*2; 437 | M = [m0, m0 + (m2-m0).*abs(F), m2]; 438 | Num = length(m0); 439 | j = [2 1 0;1 2 0;0 2 1;0 1 2;1 0 2;2 0 1;2 1 0]*Num; 440 | k = floor(H) + 1; 441 | Image = reshape([M(j(k,1)+(1:Num).'),M(j(k,2)+(1:Num).'),M(j(k,3)+(1:Num).')],[N,3]); 442 | return; 443 | 444 | 445 | function H = rgbtohue(Image) 446 | % Convert RGB to HSV or HSL hue 447 | [M,i] = sort(Image,3); 448 | i = i(:,:,3); 449 | Delta = M(:,:,3) - M(:,:,1); 450 | Delta = Delta + (Delta == 0); 451 | R = Image(:,:,1); 452 | G = Image(:,:,2); 453 | B = Image(:,:,3); 454 | H = zeros(size(R)); 455 | k = (i == 1); 456 | H(k) = (G(k) - B(k))./Delta(k); 457 | k = (i == 2); 458 | H(k) = 2 + (B(k) - R(k))./Delta(k); 459 | k = (i == 3); 460 | H(k) = 4 + (R(k) - G(k))./Delta(k); 461 | H = 60*H + 360*(H < 0); 462 | H(Delta == 0) = nan; 463 | return; 464 | 465 | 466 | function Rp = gammacorrection(R) 467 | Rp = zeros(size(R)); 468 | i = (R <= 0.0031306684425005883); 469 | Rp(i) = 12.92*R(i); 470 | Rp(~i) = real(1.055*R(~i).^0.416666666666666667 - 0.055); 471 | return; 472 | 473 | 474 | function R = invgammacorrection(Rp) 475 | R = zeros(size(Rp)); 476 | i = (Rp <= 0.0404482362771076); 477 | R(i) = Rp(i)/12.92; 478 | R(~i) = real(((Rp(~i) + 0.055)/1.055).^2.4); 479 | return; 480 | 481 | 482 | function fY = f(Y) 483 | fY = real(Y.^(1/3)); 484 | i = (Y < 0.008856); 485 | fY(i) = Y(i)*(841/108) + (4/29); 486 | return; 487 | 488 | 489 | function Y = invf(fY) 490 | Y = fY.^3; 491 | i = (Y < 0.008856); 492 | Y(i) = (fY(i) - 4/29)*(108/841); 493 | return; 494 | -------------------------------------------------------------------------------- /COS_code/fn_RGB2Lab.m: -------------------------------------------------------------------------------- 1 | function [L,a,b] = fn_RGB2Lab(R,G,B) 2 | %RGB2LAB Convert an image from RGB to CIELAB 3 | % 4 | % function [L, a, b] = RGB2Lab(R, G, B) 5 | % function [L, a, b] = RGB2Lab(I) 6 | % function I = RGB2Lab(...) 7 | % 8 | % RGB2Lab takes red, green, and blue matrices, or a single M x N x 3 image, 9 | % and returns an image in the CIELAB color space. RGB values can be 10 | % either between 0 and 1 or between 0 and 255. Values for L are in the 11 | % range [0,100] while a and b are roughly in the range [-110,110]. The 12 | % output is of type double. 13 | % 14 | % This transform is based on ITU-R Recommendation BT.709 using the D65 15 | % white point reference. The error in transforming RGB -> Lab -> RGB is 16 | % approximately 10^-5. 17 | % 18 | % See also LAB2RGB. 19 | 20 | % By Mark Ruzon from C code by Yossi Rubner, 23 September 1997. 21 | % Updated for MATLAB 5 28 January 1998. 22 | % Updated for MATLAB 7 30 March 2009. 23 | 24 | if nargin == 1 25 | B = double(R(:,:,3)); 26 | G = double(R(:,:,2)); 27 | R = double(R(:,:,1)); 28 | end 29 | 30 | if max(max(R)) > 1.0 || max(max(G)) > 1.0 || max(max(B)) > 1.0 31 | R = double(R) / 255; 32 | G = double(G) / 255; 33 | B = double(B) / 255; 34 | end 35 | 36 | % Set a threshold 37 | T = 0.008856; 38 | 39 | [M, N] = size(R); 40 | s = M * N; 41 | RGB = [reshape(R,1,s); reshape(G,1,s); reshape(B,1,s)]; 42 | 43 | % RGB to XYZ 44 | MAT = [0.412453 0.357580 0.180423; 45 | 0.212671 0.715160 0.072169; 46 | 0.019334 0.119193 0.950227]; 47 | XYZ = MAT * RGB; 48 | 49 | % Normalize for D65 white point 50 | X = XYZ(1,:) / 0.950456; 51 | Y = XYZ(2,:); 52 | Z = XYZ(3,:) / 1.088754; 53 | 54 | XT = X > T; 55 | YT = Y > T; 56 | ZT = Z > T; 57 | 58 | Y3 = Y.^(1/3); 59 | 60 | fX = XT .* X.^(1/3) + (~XT) .* (7.787 .* X + 16/116); 61 | fY = YT .* Y3 + (~YT) .* (7.787 .* Y + 16/116); 62 | fZ = ZT .* Z.^(1/3) + (~ZT) .* (7.787 .* Z + 16/116); 63 | 64 | L = reshape(YT .* (116 * Y3 - 16.0) + (~YT) .* (903.3 * Y), M, N); 65 | a = reshape(500 * (fX - fY), M, N); 66 | b = reshape(200 * (fY - fZ), M, N); 67 | 68 | if nargout < 2 69 | L = cat(3,L,a,b); 70 | end 71 | -------------------------------------------------------------------------------- /COS_code/gabor_fn.m: -------------------------------------------------------------------------------- 1 | function gb=gabor_fn(bw,gamma,psi,lambda,theta) 2 | % bw = bandwidth, (1) 3 | % gamma = aspect ratio, (0.5) 4 | % psi = phase shift, (0) 5 | % lambda= wave length, (>=2) 6 | % theta = angle in rad, [0 pi) 7 | 8 | sigma = lambda/pi*sqrt(log(2)/2)*(2^bw+1)/(2^bw-1); 9 | sigma_x = sigma; 10 | sigma_y = sigma/gamma; 11 | 12 | sz=fix(8*max(sigma_y,sigma_x)); 13 | if mod(sz,2)==0, sz=sz+1;end 14 | 15 | % alternatively, use a fixed size 16 | % sz = 60; 17 | 18 | [x y]=meshgrid(-fix(sz/2):fix(sz/2),fix(sz/2):-1:fix(-sz/2)); 19 | % x (right +) 20 | % y (up +) 21 | 22 | % Rotation 23 | x_theta=x*cos(theta)+y*sin(theta); 24 | y_theta=-x*sin(theta)+y*cos(theta); 25 | 26 | gb=exp(-0.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi); 27 | % imshow(gb/2+0.5); -------------------------------------------------------------------------------- /COS_code/kmeansPP.m: -------------------------------------------------------------------------------- 1 | function [L,C] = kmeansPP(X,k) 2 | %KMEANS Cluster multivariate data using the k-means++ algorithm. 3 | % [L,C] = kmeans(X,k) produces a 1-by-size(X,2) vector L with one class 4 | % label per column in X and a size(X,1)-by-k matrix C containing the 5 | % centers corresponding to each class. 6 | 7 | % Version: 07/08/11 8 | % Authors: Laurent Sorber (Laurent.Sorber@cs.kuleuven.be) 9 | % 10 | % References: 11 | % [1] J. B. MacQueen, "Some Methods for Classification and Analysis of 12 | % MultiVariate Observations", in Proc. of the fifth Berkeley 13 | % Symposium on Mathematical Statistics and Probability, L. M. L. Cam 14 | % and J. Neyman, eds., vol. 1, UC Press, 1967, pp. 281-297. 15 | % [2] D. Arthur and S. Vassilvitskii, "k-means++: The Advantages of 16 | % Careful Seeding", Technical Report 2006-13, Stanford InfoLab, 2006. 17 | 18 | L = []; 19 | L1 = 0; 20 | 21 | while length(unique(L)) ~= k 22 | 23 | C = X(:,1+round(rand*(size(X,2)-1))); 24 | L = ones(1,size(X,2)); 25 | for i = 2:k 26 | D = X-C(:,L); 27 | D = cumsum(sqrt(dot(D,D))); 28 | if D(end) == 0, C(:,i:k) = X(:,ones(1,k-i+1)); return; end 29 | C(:,i) = X(:,find(rand < D/D(end),1)); 30 | [tmp,L] = max(bsxfun(@minus,2*real(C'*X),dot(C,C).')); 31 | end 32 | 33 | while any(L ~= L1) 34 | L1 = L; 35 | for i = 1:k, l = L==i; C(:,i) = sum(X(:,l),2)/sum(l); end 36 | [tmp,L] = max(bsxfun(@minus,2*real(C'*X),dot(C,C).'),[],1); 37 | end 38 | 39 | end 40 | -------------------------------------------------------------------------------- /Demo_Cosaliency.m: -------------------------------------------------------------------------------- 1 | %% The demo for Cluster-based Co-saliency Detection in multiple images 2 | 3 | clc;close all;clear; 4 | 5 | addpath('./COS_code'); 6 | 7 | %% image set 8 | para.img_set_name= 'football_player'; 9 | para.img_path=['./img_data/co_saliency_data/', para.img_set_name, '/']; 10 | para.result_path = ['./img_output/', para.img_set_name, '/']; 11 | 12 | if (~exist(para.result_path, 'dir')) 13 | mkdir(para.result_path); 14 | end 15 | 16 | %% co-saliency parameters 17 | para.files_list=dir([para.img_path '*.jpg']); 18 | para.img_num=length(para.files_list); 19 | % image resize scale 20 | para.Scale=200; 21 | %clustering number on multi-image 22 | para.Bin_num=min(max(2 * para.img_num,10),30); 23 | %clustering number on single-image 24 | para.Bin_num_single=6; 25 | 26 | %% read images 27 | data.image = cell(para.img_num,1); 28 | 29 | for img_idx = 1:para.img_num 30 | data.image{img_idx} = imread([para.img_path, para.files_list(img_idx).name]); 31 | end 32 | 33 | %% cosaliency detection 34 | [ result.cos_map, result.All_img] = Cosaliency_main( data, para.img_num, para.Scale, para.Bin_num); 35 | 36 | %% single sliency detection 37 | result.single_map = Single_saliency_main( data, para.img_num, para.Scale, para.Bin_num_single); 38 | 39 | %% combine saliency map 40 | result.final_map = result.single_map .* result.cos_map; 41 | 42 | %% save the results 43 | figure(1),subplot(3,1,1), imshow(result.All_img),title('Input images'); 44 | subplot(3,1,2), imshow(result.single_map),colormap(gray),title('Single Saliency'); 45 | subplot(3,1,3), imshow(result.final_map),colormap(gray),title('Co-Saliency'); 46 | Save_result( data, para, result); 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Demo_single.m: -------------------------------------------------------------------------------- 1 | % The demo for Cluster-based Saliency Detection in single image 2 | 3 | clc;close all;clear; 4 | 5 | addpath('./COS_code'); 6 | 7 | para.img_path='./img_data/single_data/'; 8 | para.result_path = './img_output/'; 9 | para.img_name = '1_45_45397.jpg'; 10 | 11 | %--- cluster number ------- 12 | para.Bin_num_single=6; 13 | %---- scaling the image --- 14 | para.Scale=300; 15 | 16 | data.image{1}=imread([para.img_path para.img_name]); 17 | [orgH, orgW, channel]=size(data.image{1}); 18 | 19 | % single sliency detection 20 | single_map = Single_saliency_main( data, 1, para.Scale, para.Bin_num_single); 21 | 22 | Saliency_Map_single=imresize(Gauss_normal(single_map), [orgH, orgW]); 23 | imwrite(data.image{1},[para.result_path para.img_name(1:end-4) '_org.png'],'png'); 24 | imwrite(Saliency_Map_single, [para.result_path para.img_name(1:end-4) '_single.png'],'png'); 25 | 26 | figure,subplot(1,2,1), imshow(data.image{1}),title('Input images'); 27 | subplot(1,2,2),imshow(Saliency_Map_single),title('Single Saliency'); 28 | 29 | 30 | -------------------------------------------------------------------------------- /Readme.txt: -------------------------------------------------------------------------------- 1 | The Matlab code for Cluster-based Co-saliency Detection 2 | 3 | -------------------------------------------------------------------------------- 4 | Please cite the following publication if you used or was inspired by this code/work: 5 | 6 | Huazhu Fu, Xiaochun Cao, Zhuowen Tu, "Cluster-based Co-saliency Detection", 7 | IEEE Transactions on Image Processing, vol. 22, no. 10, pp. 3766-3778, 2013. 8 | 9 | -------------------------------------------------------------------------------- 10 | This code is wrote by MATLAB, and it can run under Windows, Unix, Mac. 11 | If you find any bugs, please contact Huazhu Fu (huazhufu@gmail.com). 12 | 13 | -------------------------------------------------------------------------------- 14 | DEMOS: 15 | 1. Demo_Single.m : The demo for Cluster-based Saliency Detection in single image 16 | 17 | 2. Demo_Cosaliency.m : The demo for Cluster-based Co-saliency Detection in multiple images 18 | 19 | -------------------------------------------------------------------------------- 20 | Update: 21 | 22 | 2014.10.1: We re-organized the single/co-saliency function structure. 23 | 2014.08.19: We extracted the 'imread()' from the 'GetImVector' function. -------------------------------------------------------------------------------- /img_data/co_saliency_data/football_player/1181509254_83b4637c24.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/co_saliency_data/football_player/1181509254_83b4637c24.jpg -------------------------------------------------------------------------------- /img_data/co_saliency_data/football_player/1404827026_c17d926f18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/co_saliency_data/football_player/1404827026_c17d926f18.jpg -------------------------------------------------------------------------------- /img_data/co_saliency_data/football_player/2279822388_5fd4f69026.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/co_saliency_data/football_player/2279822388_5fd4f69026.jpg -------------------------------------------------------------------------------- /img_data/co_saliency_data/football_player/2279824890_ae67849e1d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/co_saliency_data/football_player/2279824890_ae67849e1d.jpg -------------------------------------------------------------------------------- /img_data/co_saliency_data/football_player/2400031115_389b150fd2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/co_saliency_data/football_player/2400031115_389b150fd2.jpg -------------------------------------------------------------------------------- /img_data/co_saliency_data/football_player/2400032729_6aa1a2c9a6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/co_saliency_data/football_player/2400032729_6aa1a2c9a6.jpg -------------------------------------------------------------------------------- /img_data/co_saliency_data/football_player/2802728933_48c608c880.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/co_saliency_data/football_player/2802728933_48c608c880.jpg -------------------------------------------------------------------------------- /img_data/co_saliency_data/football_player/2803707385_ab4588bce3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/co_saliency_data/football_player/2803707385_ab4588bce3.jpg -------------------------------------------------------------------------------- /img_data/co_saliency_data/football_player/413703262_61e3287314.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/co_saliency_data/football_player/413703262_61e3287314.jpg -------------------------------------------------------------------------------- /img_data/single_data/0_21_21422.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/single_data/0_21_21422.jpg -------------------------------------------------------------------------------- /img_data/single_data/1_45_45397.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_data/single_data/1_45_45397.jpg -------------------------------------------------------------------------------- /img_output/1_45_45397_org.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_output/1_45_45397_org.png -------------------------------------------------------------------------------- /img_output/1_45_45397_single.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/Cosaliency_tip2013/a91e6375820e3e2c6ce3857ad5756a1b1a565dd1/img_output/1_45_45397_single.png --------------------------------------------------------------------------------