%% ========================================================================
% Display Documents under different Topics : (Training and Testing)
% =========================================================================
% Code Written by Pulak Purkait : Date oct, 2012
% ----------------------------------------------
% ECSU, Indian Statistical Institute Kolkata
% For any questions/bug related issues, send email to: pulak_r@isical.ac.in
% Referece 
%      P. Purkait and B chanda, Image upscaling using multiple dictionaries
%      of natural image patches, ACCV 2012    
% =========================================================================

ImageType  = 'gray';
IsOriginalData = 0;
% sz = sqrt(par.no_words);

% ovrlap = par.ovrlap;
% doc_size = (patch_size-ovrlap)*sz+ovrlap;
% Topic.Pz_d = Topic.Pd_z.*repmat(Topic.Pz, size(Topic.Pd_z, 1), 1);

% Following two lines are for display Train documents
% --------------------------------------------------
% [srt, indx] = sort(Topic.Pz_d , 2, 'descend');

dirPath = 'TrainTopic/Topic';

% Following two lines are for display test documents
% --------------------------------------------------
% [srt, indx] = sort(Topic.tPdz , 2, 'descend');
% OXh = Xorg;
% dirPath = 'TestTopic/TopicNN';

for ii = 1:par.no_topics
    id = find(indx == ii);
    disp(['number of document under the topic ' num2str(ii) ' is ' num2str(numel(id))]);
    tdoc = numel(id); 
    
    % documents under topic ii : docs_ii
    docs_ii = zeros(par.patch_size^2, tdoc);
    
    for nd = 1:tdoc  
        docs_ii(:, nd) = OXh(:, id(nd));
    end
    
    I = DispDictionary(docs_ii, ImageType, IsOriginalData);
    imwrite(I, [dirPath int2str(ii) '.png']);
    
end


