% ------------------------------------------------------------------------
% This is a demo of generating human language description for high 
% resolution remote sensing image with a pre-trained CNN model.
% Please first download and install the MatConvNet Toolkit and release
% the matlabcode folder to its root dictionay.
% 
% Copyright (2017): Zhenwei Shi, Zhengxia Zou, Beihang University.
% Date: Mar., 2017
% Version: 1.0
% ------------------------------------------------------------------------
% Citation:
% Hierarchical Suppression Method for Hyperspectral Target Detection. 
% IEEE Transactions on Geoscience and Remote Sensing. Article in Press.
% Author:
% Zhengxia Zou (zhengxiazou@buaa.edu.cn) 
% Zhenwei Shi (shizhenwei@buaa.edu.cn)
% ------------------------------------------------------------------------

% initial model
run initialize;

% set image path and image tpye
imgFolderPath = '..\test data\google\';
imgType = '*.jpg';

dirs_img = dir(strcat(imgFolderPath, imgType)); 
[FileNum, c1] = size(dirs_img);
for i = 1:FileNum
    
    % read image
    ImgFileName = dirs_img(i).name;
    ImgFilePath = strcat(imgFolderPath, ImgFileName);
    im = imresize(imread(ImgFilePath), 1.0);
    
    tic
    % key inst detect
    KI = keyInstDetection(im, net, w_KI, Opts);
    % env element extract
    Env = envInfoExtract(im, net, w_Env, Opts);
    % scene type evaluation
    Scn = scnTypeEval(im, net, w_Scn, Opts);
    % generating sentences
    sentences = genSentences(im, KI, Env, Scn, Opts);
    toc
    
    % display sentences
    sentences
    
end
