Question
I have the following code i want to convert images jpg (TrainingData) into cell arrays ,where each cell containing a 28-by-28 matrix representing a synthetic image of fingerprint dataDir= fullfile('Data/'); exts = {'.jpg','.png','.tif','BMP'}; imds = imageDatastore(fullfile(dataDir),... 'IncludeSubfolders',true,'FileExtensions','.jpg','LabelSource','foldernames'); countEachLabel(imds); [TrainData, TestData] = splitEachLabel(imds, 0.5); size(TrainData); countEachLabel(TrainData); for i = 1:numImages img = readimage(TrainData, i); img = imbinarize(img); end
Expert Answer
John Michell
PhD Expert
Answered Aug 24, 2026
sz = size(img);
RB = 28; CB = 28;
NRB = floor(sz(1)/RB);
LOR = sz(1) - NRB*RB;
NCB = floor(sz(2)/CB);
LOC = sz(2) - NCB*CB;
if LOR ~= 0
rbs = [RB * ones(1,NRB), LOR];
else
rbs = RB * ones(1,NRC);
end
if LOC ~= 0
cbs = [CB * ones(1,NCB), LOC];
else
cbs = CB * ones(1,NCB);
end
tiles = mat2cell(img, rbs, cbs, size(img,3));
See also mat2tiles in the File Exchange
And watch out for the titles that are not 28 x 28. This code does not assume that the image is an exact integer multiple of 28 in each direction, and it does not throw away any partial blocks.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related matlab Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →