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: cropImages2.m
    path of file: ./repos/brainSurfer/scripts/misc
    
    the code of the file until where you have to start completion: function cropImages2(inFiles,fig)

    
function cropImages2(inFiles,fig)
% cropImages(inFiles,plot,emptyComponent)
%
% cropImages takes as input a bunch of images (tested only with PNGs so far
% but any kind should work) and crops them so as to maximally remove the
% largest connected segment of pixels. If you have some complex object that
% contains lots of colors and it is set against a single colored
% background, this script will crop the image to remove as much of the
% background as possible. It works well with brain figures generated by
% brainSurfer (removing background and the colorbar) and is completely
% agnostic to the color of the background. Cropped images will be saved in
% the same directory as the input images, but appended by the string
% '_cropped'.
%
% If inFiles is empty, you will be prompted to select files to crop using
% uipickfiles (if you don't have uipickfiles either google it and add it to
% your matlab path or use a full file path in the input arguments). Files
% are assumed to have 3 color channels (i.e., rgb)
%
% If plot is empty or set to 'false' no figures will be generated.
% Otherwise, cropImages will produce figures showing which parts of the
% image are incrementally removed as the image is converted from RGB to
% greyscale, then to a binarized image.
%
% emptyComponent should be left empty or set to 1 for default settings.
% This will force the script to assume that the largest connected component
% in the image is empty space that needs to be removed. In case the script
% fails but you know which connected component corresponds to the empty
% space, then you can provide it here (e.g., you resized the window in
% brainSurfer by a lot and now it's the second largest component, second to
% the brain itself). If you do so, set emptyComponent to some number n
% (other than 1) which will be assumed to be the nth largest connected
% component.
%
% Alex Teghipco // alex.teghipco@uci.edu // 2021

if isempty(fig)
    fig = 'false';
end

if isempty(inFiles)
    [inFiles,pth] = uigetfile('*','MultiSelect','on');
    if ~iscell(inFiles)
        inFiles = {inFiles};
    end