You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.5 KiB
Matlab

function Locations=postprocess_codebook(Locations,patchClassList,voteSpread,scales)
% voteSpread - the standard deviation of the Gaussian used to smooth the Locations
indPatchesInClass=find(patchClassList>0);
numCodebookEntries=length(indPatchesInClass);
numClasses=length(Locations);
if nargin<4 || isempty(scales)
%smooth codebook entries across spatial position
gauss=gauss2D(voteSpread);
for i=1:numCodebookEntries
for c=1:numClasses
%gauss=gauss2D(voteSpread.*scales(c));
Locations{c}{i}=conv2(Locations{c}{i},gauss,'same');
Locations{c}{i}=single(Locations{c}{i});
end
end
else
%smooth codebook entries across spatial position and scale
sigmaScale=1
gauss=gauss3D([voteSpread,voteSpread,sigmaScale]);
for i=1:numCodebookEntries
[a,b]=size(Locations{find(scales==1)}{i});
allLocations=[];
%make vote weight arrays for different scales the same size, in order to be able
%to smooth across them
for c=1:numClasses
origSize{c}(1:2)=size(Locations{c}{i});
allLocations(:,:,c)=imresize(Locations{c}{i},[a,b],'bilinear');
end
allLocations=convn(allLocations,gauss,'same');
%return vote weight arrays to original sizes
for c=1:numClasses
%Locations{c}{i}=imresize(allLocations(:,:,c),scales(c),'bilinear');
Locations{c}{i}=imresize(allLocations(:,:,c),origSize{c},'bilinear');
Locations{c}{i}=single(Locations{c}{i});
end
end
end
disp('finished postprocessing codebook')