You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: CBIG_MMLDA_add_text_to_forest_plot.m
    path of file: ./repos/CBIG/stable_projects/disorder_subtypes/Sun2019_ADJointFactors/utilities/GLM
    
    the code of the file until where you have to start completion: function CBIG_MMLDA_add_text_to_forest_plot(forest_plot, file_pvalue, out_dir, p_thresh, k, compare_factor_names)
% This function takes in the raw forest plot and p values, and add text to 
% the forest plot, such as 'F2 - F1', 'Latter is worse'.
% The final figure will be saved in the same directory as out_dir, with a
% postfix name of '_compPlot.png' to the original file name.
% Currently only available for k = 2, 3, 4 
%
% Input:
%      - forest_plot:
%        The file name of the raw forest plot
%      - file_pvalue:
%        The file name of the text file containing number of subjects and 
%        p-values
%        file_pvalue is assumed to have the following format: 1st row is the 
%        number of subjects, 2nd row is the omnibus p-value, 3rd to the
%        last rows are the pairwise p-values.
%      - out_dir:
%        The full path to directory where the raw GLM plot & p value text 
%        files are
%      - p_thresh:
%        The final threshold after correcting multiple comparisons

    
function CBIG_MMLDA_add_text_to_forest_plot(forest_plot, file_pvalue, out_dir, p_thresh, k, compare_factor_names)
% This function takes in the raw forest plot and p values, and add text to 
% the forest plot, such as 'F2 - F1', 'Latter is worse'.
% The final figure will be saved in the same directory as out_dir, with a
% postfix name of '_compPlot.png' to the original file name.
% Currently only available for k = 2, 3, 4 
%
% Input:
%      - forest_plot:
%        The file name of the raw forest plot
%      - file_pvalue:
%        The file name of the text file containing number of subjects and 
%        p-values
%        file_pvalue is assumed to have the following format: 1st row is the 
%        number of subjects, 2nd row is the omnibus p-value, 3rd to the
%        last rows are the pairwise p-values.
%      - out_dir:
%        The full path to directory where the raw GLM plot & p value text 
%        files are
%      - p_thresh:
%        The final threshold after correcting multiple comparisons
%        p-values stronger than p_thresh will be highlighted in blue.
%      - k:
%        Number of factors
%      - compare_factor_names:
%        (optional) cell array of factor names. Default is {'F2 - F1'}
%
% Written by Siyi Tang and CBIG under MIT license: https://github.com/ThomasYeoLab/CBIG/blob/master/LICENSE.md

%% read in the forest plot
img = imread(forest_plot);
[file_path, file_name, ext] = fileparts(forest_plot);

%% draw composite plots
% k = 2
if k == 2
    outerBox = imread('/templates_plots/box_template_k2.png');
    
    img = imresize(img, [80,510]);
    
    mask = outerBox;
    
    for i = 50:(size(img,1)+49)
        for j = 210:635
            if mask(i,j,1)== 255 && mask(i,j,2)==255 && mask(i,j,3)==255
                mask(i,j,:) = img(i-49,j-160,:);
            end