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: compute_surfNorm.m
    path of file: ./repos/photometric-stereo
    
    the code of the file until where you have to start completion: function N = compute_surfNorm(I, L, M)
%COMPUTE_SURFNORM Computes the surface normals given images, their
%corresponding light directions, and the gray mask
%
%   N = compute_surfNorm(I, L)
%
%computes the surface normals "N", a m-by-n-by-3 matrix, from the
%images "I", a p-by-1 cell array whose each element is an image, their
%corresponding lightings "L", a p-by-3 matrix whose each row is the
%lighting direction for the corresponding image in "I", and the gray mask
%"M".
%
%Author: Xiuming Zhang (GitHub: xiumingzhang), National Univ. of Singapore
%

assert(size(I, 1)==size(L, 1), 'I and L mismatched!');

    
function N = compute_surfNorm(I, L, M)
%COMPUTE_SURFNORM Computes the surface normals given images, their
%corresponding light directions, and the gray mask
%
%   N = compute_surfNorm(I, L)
%
%computes the surface normals "N", a m-by-n-by-3 matrix, from the
%images "I", a p-by-1 cell array whose each element is an image, their
%corresponding lightings "L", a p-by-3 matrix whose each row is the
%lighting direction for the corresponding image in "I", and the gray mask
%"M".
%
%Author: Xiuming Zhang (GitHub: xiumingzhang), National Univ. of Singapore
%

assert(size(I, 1)==size(L, 1), 'I and L mismatched!');
p = size(I, 1);

%------------------------ Collect intensity at a point for all images, T

% Get image dimensions
im = I{1};
[im_h, im_w, ~] = size(im);

% Initialize T, a im_h-by-im_w-by-p matrix, whose (h, w, :) holds the
% intensities at (h, w) for all p different lightings
T = zeros(im_h, im_w, p);

% For each image
for idx = 1:p
    im = I{idx};
    % Loop thru each pixel
    for h = 1:im_h
        for w = 1:im_w
            % If in the mask
            if M(h, w)
                r = im(h, w, 1);
                g = im(h, w, 2);
                b = im(h, w, 3);
                inten = norm(double([r g b]));
                T(h, w, idx) = inten;
            end