user
Voitko muuntaa tämän MATLAB-skriptin funktioksi:
%% Rakenna taulukko hakukuvan tiedoista
search Image InfoStruct=dir (imageFolder + "\\*.jpg");
search Image Info=struct2table (search ImageInfoStruct);
search ImageInfo=convertvars (search Image Info,@iscell, 'string');
search ImageInfo.Properties. VariableNames {'name' }='tiedostonimi';
name=extractBefore(search ImageInfo.filename, '.');
search Image Info=addvars (search ImageInfo, name, 'Before',1);

imageDS=imageDatastore (fullfile (search ImageInfo.folder, search ImageInfo.filename));
imageRGB=readall(imageDS);

image=cellfun (@(x) x(:,:,channelToCorrelate), imageRGB, UniformOutput=false);
search Image Info=addvars (search ImageInfo, image, imageRGB, 'After',1);
search ImageM-cellfun (@(x) size (x,1), search ImageInfo.image);
search ImageN=cellfun (@(x) size (x, 2), search ImageInfo.image);
search ImageInfo=addvars (search ImageInfo, search ImageM, search ImageN, 'After', 2);
assistant
Olen muuttanut MATLAB-skriptin funktioksi nimeltä `buildSearchImageInfo`. Funktio ottaa syöttöargumentteina `imageFolder` ja `channelToCorrelate` ja palauttaa `searchImageInfo`-taulukon.
```matlab
function searchImageInfo = buildSearchImageInfo(imageFolder, channelToCorrelate)
    % Rakenna taulukko hakukuvatiedoista
    searchImageInfoStruct = dir(fullfile(imageFolder, "*.jpg"));
    searchImageInfo = struct2table(searchImageInfoStruct);
    searchImageInfo = convertvars(searchImageInfo, @iscell, 'string');
    searchImageInfo.Properties.VariableNames{'name'} = 'tiedostonimi';
    
    name = extractBefore(searchImageInfo.filename, '.');
    searchImageInfo = addvars(searchImageInfo, name, 'Before', 1);
    
    imageDS = imageDatastore(fullfile(searchImageInfo.folder, searchImageInfo.filename));
    imageRGB = readall(imageDS);
    
    image = cellfun(@(x) x(:, :, channelToCorrelate), imageRGB, 'UniformOutput', false);
    searchImageInfo = addvars(searchImageInfo, kuva, imageRGB, 'After', 1);
    
    searchImageM = cellfun(@(x) size(x, 1), searchImageInfo.image);
    searchImageN = cellfun(@(x) size(x, 2), searchImageInfo.image);
    searchImageInfo = addvars(searchImageInfo, searchImageM, searchImageN, 'After', 2);
end
```
Voit kutsua tätä funktiota MATLAB-skriptissäsi antamalla `imageFolder` ja `channelToCorrelate` syöttöargumentteina seuraavasti:
```matlab
imageFolder = 'path/to/image/folder';
channelToCorrelate = 1; % Esimerkiksi 1 RGB-kuvien punaiselle kanavalle.
searchImageInfo = buildSearchImageInfo(imageFolder, channelToCorrelate);
```