function R = LIS_getR(testImageNumber)
% LIS_getR         Get the data term R for test image, matrix R is stored in mat-file.
%               
% This function allows me to simply input R as a single integer instead of
% a large matrix, and then retrieve the R matrix from a file stored on a
% given catlog on my computer. 
% Now, for the EMP8 prefixed functions, this file is OBSOLETE
% now you may generate R by texclassify() instead (or your preferred function)
%
% ex: R = LIS_getR(104);

% R was/is stored in cat_R  = my_matlab_path('.r\aug12'), 
%         ex: ...\tctdata\results\aug12\R101D01go3.mat
% Dictionaries used are now stored (moved since R were made) in 
% my_matlab_path('.d\aug12')   ex: ...\tctdata\dictionaries\aug12\D01go3.mat
% They were made using vecMet 'g' (N=17), K=200, s=3 (javaormp) august 2012
% made by m-file: TexDictLearn.m   (which now is replaced by texdictlearn.m)
% 

% comments sent to Mohammed May 9. 2017
% Nice to read that there still is some interest in texture classification, 
% it has been some years since I used it. The m-files presented on 
% http://www.ux.uis.no/~karlsk/tct/index.html are mainly tools, not complete programs,
% but the files EMP8_exN.m gives some examples of how to use (some of) the tools.
% Note that EMP8-files are newer and based on a better and more flexible  
% cost model (Energy Minimization on Potts-model 8 neighbors), 
% the LIS-files (Labeled Image Segmentation) were made for a more simple 
% cost model and should perhaps only be considered as a step on the road to the EMP8-model.
% Nevertheless, I kept some functions LIS*.m for some tasks that were not changed.
% The LIS_getR function is intentionally not included as it is a function that 
% depends on the actual way the R-matrix (data matrix) is stored on the system YOU use,
% it just retrieves the cost matrix. If it may be any help for you I attach 
% the file that works on my systems (I have used several, and thus the file is 
% probably more complicated that what you will need. A simple load() will often do.)

% (more correct) comments sent to Ariel Briceno August 1. 2017
% The missing LIS_GetR() on the web-page is ''an error'' in the set of files 
% partly due to the fact that the files are (a mixture of files) from different steps in the development.
% The OLD files, prefix LIS, are the ones that use LIS_GetR().
% The NEWER files, prefix EMP8, should not use LIS_GetR(), but there are some exceptions:
% -	EMP8_argin() uses it to retrieve my ‘old’ stored data-files, here the input option to give R as a single integer should simply be removed
% -	ex12 and ex12v use it to compare NEW files (prefix EMP8) to older files (prefix LIS) as in ex01
% (this convinced me that the new files are the better ones)
% I think the EMP8 files are the better ones.
% 
% If you for some reason want to use the LIS-prefix files (they have some possibilities which were removed in the newer files)
% The files where LIS_GetR() is used may be updated: the line replaced by:
% % HERE YOU INSERT CODE THAT retrieve the R matrix (IxJxM) previeous stored OR THAT make it, ex: texclassify(testim, Dcell, ‘option’,value, ..)
% The R-matrices may be quite large and take some time to generate, it may be useful to store them somewhere.
% The R-matrices are now made by texclassify() which is much faster that how I made the R-matrices before and thus it is often not needed to store them.


if isunix()
    cat_sep = '/';
else
    cat_sep = '\';
end
cat_R  = my_matlab_path(['.r',cat_sep,'aug12']);   % results aug12
n3 = 'go3';

if (testImageNumber < 100)
    testImageNumber = testImageNumber + 100;
end

% set the dictionary files (Df)
if (testImageNumber == 101)
    Df = {['D01',n3],['D02',n3],['D03',n3],['D04',n3],['D05',n3]};
elseif (testImageNumber == 102)
    Df = {['D06',n3],['D07',n3],['D08',n3],['D09',n3],['D10',n3]};
elseif (testImageNumber == 103)
    Df = {['D11',n3],['D12',n3],['D13',n3],['D14',n3],['D15',n3]};
elseif (testImageNumber == 104)
    Df = {['D16',n3],['D17',n3],['D18',n3],['D19',n3],['D20',n3]};
elseif (testImageNumber == 105)
    Df = {['D21',n3],['D22',n3],['D23',n3],['D24',n3],['D25',n3]};
elseif (testImageNumber == 106)
    Df = {['D26',n3],['D27',n3],['D28',n3],['D29',n3],['D30',n3],...
        ['D31',n3],['D32',n3],['D33',n3],['D34',n3],['D35',n3],...
        ['D36',n3],['D37',n3],['D38',n3],['D39',n3],['D40',n3],['D41',n3]};
elseif (testImageNumber == 107)
    Df = {['D42',n3],['D43',n3],['D44',n3],['D45',n3],['D46',n3],...
        ['D47',n3],['D48',n3],['D49',n3],['D50',n3],['D51',n3],...
        ['D52',n3],['D53',n3],['D54',n3],['D55',n3],['D56',n3],['D57',n3]};
elseif (testImageNumber == 108)
    Df = {['D58',n3],['D59',n3],['D60',n3],['D61',n3],['D62',n3],...
        ['D63',n3],['D64',n3],['D65',n3],['D66',n3],['D67',n3]};
elseif (testImageNumber == 109)
    Df = {['D68',n3],['D69',n3],['D70',n3],['D71',n3],['D72',n3],...
        ['D73',n3],['D74',n3],['D75',n3],['D76',n3],['D77',n3]};
elseif (testImageNumber == 110)
    Df = {['D78',n3],['D79',n3]};
elseif (testImageNumber == 111)
    Df = {['D80',n3],['D81',n3]};
elseif (testImageNumber == 112)
    Df = {['D82',n3],['D83',n3]};
elseif (testImageNumber == 113)
    Df = {['D84',n3],['D85',n3]};
else
    error('LIS_getR: The image is not relevant. Return.');
end

rfile = [cat_R,cat_sep,'R',int2str(testImageNumber),Df{1},'.mat'];
disp(rfile);
if exist(rfile,'file')
    res = load(rfile);   % the data term is named R2 in the file
    R = res.R2;
else
    error(['LIS_getR: Could not find file ',rfile]);
end

return


