I need help on cell array and Imaging processing

5 ビュー (過去 30 日間)
Abdussalam Elhanashi
Abdussalam Elhanashi 2020 年 10 月 26 日
コメント済み: Walter Roberson 2020 年 10 月 27 日
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

採用された回答

drummer
drummer 2020 年 10 月 26 日
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 件のコメント
Abdussalam Elhanashi
Abdussalam Elhanashi 2020 年 10 月 27 日
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 2020 年 10 月 27 日
reconstructed = xReconstructed{i};
reconstructed(imbinarize(reconstructed)) = 1;
imshow(reconstructed)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by