compare multi images with all images in referenced folders using matlab

时间:2015-07-28 17:01:13

标签: excel image matlab

I have some reference image (I'll call this images as Ref\animal.jpg', 'Ref\food.jpg', 'Ref\gon.jpg ... etc ). Then in each folder i want to compare Image1, Image2, ..., ImageN to each referenced image . I want to summarize the results of the comparison by writing to an Excel file (which has the same name as the folder) (in A1) 'Image 1 = ok', (in B1) 'Image 2 = no', ..., (in the Nth row, 1st column) 'Image N = ok'.

i got the following error , when i use single image its working well but multi images in reference images ( second line ) i got cellfun error .

Error using cellfun Input #2 expected to be a cell array, was double instead.

any one please can correct the following code ??

%The base file path
path = 'D:';
% Relative reference to reference images
 ImageRefLocations = {'Ref\RefI1.jpg', 'Ref\RefI2.png', 'Ref\RefI3.jpg'};
 %Base Image location
 baseImage = fullfile(path, ImageRefLocations(:));
 %The pattern used to choose the folders
 folderPattern = 'folder*';
 %The image extension
 [~, ~, ext] = unique(cellfun(@(f) fileparts(f), baseImage, 'uni', 0));

 %The excel extension
 ExcelExt = '.xlsx';

 msg = {' = no'; ' = ok'};

i0 = cellfun(@(f) imread(f), baseImage, 'uni', 0);

%Get the path of the folders
srcFolders = dir(fullfile(path, folderPattern));
isDir = [srcFolders.isdir];
srcFolders = {srcFolders(isDir).name}';
PathedFolders = fullfile(path, srcFolders);
excelFiles = fullfile(path, strcat(srcFolders, ExcelExt));

 for i = 1:length(PathedFolders)
f = PathedFolders{i};

after this line i got error ...

Error using cellfun Input #2 expected to be a cell array, was double instead.

Images = cellfun(@(x) dir(fullfile(f, ['*', x])), ext, 'uni', 0);
Images = vertcat(Images{:});

if isempty(Images)
    continue
end

Images = {Images.name}';
[~, ImageNames, ~] = cellfun(@(x) fileparts(x), Images, 'uni', 0);
ImageList = fullfile(f, Images);

match = zeros(size(ImageList));

for j = 1:length(ImageList)
    image = imread(ImageList{j});

    for k = 1:length(i0)
        if ~all(size(image) == size(i0{k}))
            continue
        end

        match(j) = all(image(:) == i0{k}(:));

        if match(j)
            continue
        end
    end
end

matchMessage = strcat(Images, msg(match + 1));

xlswrite(excelFiles{i}, matchMessage)
 end

0 个答案:

没有答案