function translatedTemplate = MGetBack( part_row,part_col, MAX1map,...
        ARGMAX1map, M1RowShift, M1ColShift, M1OriShift,...
        template,GaborSymbol, nGaborOri )

selectedRow = template.selectedRow;
selectedCol = template.selectedCol;
selectedOri = template.selectedOri;
translatedTemplate = zeros(size(MAX1map{1}));
for iGabor = 1:length(selectedRow)
    gabor_row = part_row + selectedRow(iGabor);
    gabor_col = part_col + selectedCol(iGabor);
    gabor_ori = selectedOri(iGabor) + 1;
    % more generally: gabor_scale = selectedScale(iGabor) + 1;
    gabor_scale = 1;
    if gabor_row <= 0 || gabor_col <= 0 || gabor_row > size(translatedTemplate,1) || gabor_col > size(translatedTemplate,2)
        continue;
    end
    
    % strength of this Gabor symbol (between 0 and 1)
    S1score = MAX1map{(gabor_scale-1)*nGaborOri+gabor_ori}(gabor_row,gabor_col);
    S1score = S1score - 3; % These two parameters are just for display purpose
    priorS1 = 0.5;
    strength = priorS1 * exp(S1score) / ( (1-priorS1) + priorS1 * exp(S1score) );
    strength = max(0.8,strength);
    
    % Gabor movements
    gabor_trace = ARGMAX1map{(gabor_scale-1)*nGaborOri+gabor_ori}(gabor_row,gabor_col) + 1;
    gabor_dr = single(M1RowShift{(gabor_scale-1)*nGaborOri+gabor_ori}(gabor_trace));
    gabor_dc = single(M1ColShift{(gabor_scale-1)*nGaborOri+gabor_ori}(gabor_trace));
    gabor_do = single(M1OriShift{(gabor_scale-1)*nGaborOri+gabor_ori}(gabor_trace));
    gabor_row = gabor_row + gabor_dr;
    gabor_col = gabor_col + gabor_dc;
    gabor_ori = gabor_do + 1; % note: gabor_do is already the transformed orientation
    while gabor_ori > nGaborOri
        gabor_ori = gabor_ori - nGaborOri;
    end
    while gabor_ori <= 0
        gabor_ori = gabor_ori + nGaborOri;
    end

    % Gabor symbol
    patch = strength * GaborSymbol{(gabor_scale-1)*nGaborOri+gabor_ori};

    % below: the bounding box for Gabor inside the image
    top2 = gabor_row - floor(size(patch,1)/2);
    left2 = gabor_col - floor(size(patch,2)/2);
    for c = 1:size(patch,2)
        for r = 1:size(patch,1)
            c2 = left2 + c - 1;
            r2 = top2 + r - 1;
            if r2 <= 0 || r2 > size(translatedTemplate,1) || c2 <= 0 || c2 > size(translatedTemplate,2)
                continue;
            end
            val = patch(r,c);
            if val > translatedTemplate(r2,c2)
                translatedTemplate(r2,c2) = val;
            end
        end
    end
end