Hi,
I am working on character recogntiion and my images are in gray images.
here in the code on read all images but I am facing error.
function [images, labels, imageFiles] = readDataset(dirPath) imageFiles = ''; % Get a list of all files and folders in this folder.
files = dir(dirPath); % Get a logical vector that tells which is a directory.
dirFlags = [files.isdir]; % Extract only those that are directories.
subFolders = files(dirFlags); % add all image file name
for i = 1 : length(subFolders) subDir = subFolders(i).name; if subDir == '.' | strcmp(subDir, '..') == 1 continue; end files = dir(strcat(dirPath, '/', subDir)); fileFlags = ~[files.isdir]; files = files(fileFlags); for j = 1: length(files) filename = strcat(subDir, '/', files(j).name); imageFiles = strvcat(imageFiles, filename); end end % shuffle file list
idx = randperm(length(imageFiles)); imageFiles = imageFiles(idx, :); % read images and labels
images = []; labels = []; for j = 1: length(imageFiles) filenames = strsplit(imageFiles(j, :), '/'); a = str2num(filenames{1}); labels = [labels, str2num(filenames{1})]; img = imread(strcat(dirPath, '/', imageFiles(j, :))); %img = rgb2gray(img);
img = imresize(img, [32, 32]); img = double(img) / 255; images(:, :, length(labels)) = img; end labels = reshape(labels, [length(labels), 1]); images = reshape(images, [32, 32, 1, length(labels)]);end
Best Answer