MatLab Code

Files form directory into array:

files_Arr = dir('C:\SomeDirectory\EXP*'); %to only get files starting with EXP


files_Arr = dir('C:\SomeDirectory\**\EXP*'); %goes through subdirectories


files_Arr([files_Arr.isdir]) = []; %to get rid of . and .. and other directories

Normalized gray image:

#similar to imshow(im, [])
dicomIM = mat2gray(dicomIM);

Max of entire matrix:

max(A(:));

To create empty cell array:

newCellArray = cell(0,2) %empty rows, 2 columns

To make a table:

cell2table
array2table

To flip inverse images in DICOM:

if dicomInfo.PhotometricInterpretation == 'MONOCHROME1'
        dicomIM = imcomplement(dicomIM);
end

Apply LUT to image in DICOM:

    try
        %There are 3 LUTS in Item_1, Item_2, Item_3 - normal, harder,
        %softer
        LUT1 = dicomInfo.VOILUTSequence.Item_1.LUTData;
        %Expand to LUT16 to comply with Matlab's intlut 65K requirement
        LUT16 = uint16(zeros(size(LUT1,1)*4, 1));
        for i=1:size(LUT1,1)
            for k=0:3
                LUT16(i*4-k, 1) = LUT1(i,1);
            end
        end
        %Original DICOM image needs to be multiplied by 4 to correlate with
        %LUT16
        dicomIM = intlut(dicomIM.*4, LUT16);
    catch ME
        continue; 
    end

Write table to a file:

writetable(finalTable, strcat(outfolder,'filename.csv'));