I need help on cell array and Imaging processing

4 views (last 30 days)
Hi
I am using the following code
close all;
clc;
%% Initalize the data
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);
numImages = numel(TrainData.Files);
for i = 1:numImages
img = readimage(TrainData, i);
% img2= imshow(img, 'InitialMagnification', 800);
img3= imresize(img, [100 100]);
img4= imshow(img3, 'InitialMagnification', 800);
drawnow;
Train{i} = (img3); %#ok<SAGROW>
end
hiddenSize = 25;
autoenc = trainAutoencoder(Train,hiddenSize,'MaxEpochs',1000,...
'DecoderTransferFunction','purelin','EncoderTransferFunction','satlin','L2WeightRegularization',0.0004,'SparsityRegularization',4,'SparsityProportion',0.15);
numImages = numel(TestData.Files);
for i = 1:numImages
img5 = readimage(TestData, i);
img6= imresize(img, [100 100]);
img7= imshow(img3, 'InitialMagnification', 800);
drawnow;
Test{i} = (img6); %#ok<SAGROW>
end
xReconstructed = predict(autoenc,Test);
%% Test Images
figure();
for i = 1:10
subplot(4,5,i);
imshow(TestData.Files{i});
end
%% Reconstructed images from TestData
figure();
for i = 1:10
subplot(4,5,i);
imshow(xReconstructed(i))
end
But I got the following error
Error using imageDisplayValidateParams
Expected input number 1, I, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical
Instead its type was cell.
Error in images.internal.imageDisplayValidateParams (line 11)
validateattributes(common_args.CData, {'numeric','logical'},...
Error in images.internal.imageDisplayParseInputs (line 79)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 253)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in data_process1 (line 51)
imshow(xReconstructed(i))
When I compare to the example,
https://www.mathworks.com/help/deeplearning/ref/trainautoencoder.html
the issue is with Train{i}and Test {i}, The model is not trained probably with given data. When I compared with example in MATLAB for digitTrainCellArrayData and digitTTestCellArrayData I am having problems and my cell array which are not the same as in example
My cell arrays for Train{i}and Test {i} are like this like for example Train{i}
But in the example in MATLAB for digits, digitTrainCellArrayData and digitTestCellArrayData are like this
digitTrainCellArrayData
In addition to that. Range in example is from 0 – 1 while my data is from 0 – 255
Kindly looking for your support

Accepted Answer

drummer
drummer on 26 Oct 2020
figure();
for i = 1:10
subplot(4,5,i);
imshow(TestData.Files{i});
end
Hi.
It's probably your argument for imshow that is cell type, while it only accepts the type mentioned in your error message.
Try this workaround
figure();
for i = 1:10
subplot(4,5,i);
image = cell2mat(TestData.Files{i});
imshow(image);
end
I haven't tested, so before performing within the loop, try outside, with a single image.
Cheers
  15 Comments
Abdussalam Elhanashi
Abdussalam Elhanashi on 27 Oct 2020
Hi walter I tried this but i got error
reconstructed(imbinarize(xReconstructed)) = 1;
Error using imbinarize
Expected I to be one of these types:
uint8, uint16, uint32, int8, int16, int32, single, double
Instead its type was cell.
Error in imbinarize>validateImage (line 262)
validateattributes(I,supportedClasses,supportedAttribs,mfilename,'I');
Error in imbinarize>parseInputs (line 198)
validateImage(I);
Error in imbinarize (line 134)
[I,isNumericThreshold,options] = parseInputs(I,varargin{:});
Walter Roberson
Walter Roberson on 27 Oct 2020
reconstructed = xReconstructed{i};
reconstructed(imbinarize(reconstructed)) = 1;
imshow(reconstructed)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!