Writing TIFFs with 9 components is not supported with IMWRITE. Use Tiff instead. Type "help Tiff" for more information.

clear;clc;close all
% Load the Image Dataset of Normal and Malignant WBC
imdsTrain = imageDatastore('D:\Project\DB1\train','IncludeSubfolders',true,'LabelSource','foldernames');
imdsTest = imageDatastore('D:\Project\DB1\test','IncludeSubfolders',true,'LabelSource','foldernames');
%Perform Cross-Validation using Hold-out method with a percentage split of 70% training and 30% testing
%[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
%%
%%
newext = '.tif';
while hasdata(imdsTrain)
[img, info] = read(imdsTrain);
[filedir, basename, ext] = fileparts(info.Filename);
newfilename = fullfile(filedir, [basename, newext]);
img3 = repmat( imresize(im2uint8(img), [299 299]), [1 1 3] );
imwrite(img3, newfilename);
end
while hasdata(imdsTest)
[img, info] = read(imdsTest);
[filedir, basename, ext] = fileparts(info.Filename);
newfilename1 = fullfile(filedir, [basename, newext]);
img3 = repmat( imresize(im2uint8(img), [299 299]), [1 1 3] );
imwrite(img3, newfilename1);
end
load('HW');
%%
%Select the Test images and save in Y_test
Y_test = newfilename1.UnderlyingDatastore.Labels;
%%
% optimzation techniques selection and hyperparamter selection
options = trainingOptions('adam', ...
'MiniBatchSize',16, ...
'MaxEpochs',20, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',newfilename1, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
%%
%CNN model training
netTransfer = trainNetwork(newfilename,HW,options);
%%
% for i=1:numel(imdsValidation.Files)
% a=[imdsValidation.Files(i)];
% a = imread(char(a));
% % featuresTest22 = activations(net,a,layer,'OutputAs','rows');
% YPred(i) = classify(netTransfer,a);
% imshow(a),title(char(YPred));
% i
% end
%%
% CNN Model validation
YPred = classify(netTransfer,newfilename1);
%Performance evaluation of Deep Learning Trained Model
plotconfusion(Y_test,YPred)
Error using writetif (line 40)
Writing TIFFs with 9 components is not supported with IMWRITE. Use Tiff instead. Type "help Tiff" for
more information.
Error in imwrite (line 546)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in CNN1 (line 19)
imwrite(img3, newfilename);

1 Comment

https://www.mathworks.com/matlabcentral/answers/1627970-1-bit-tiff-images-having-more-than-1-channel-are-not-supported#comment_1944450

Sign in to comment.

 Accepted Answer

clear;clc;close all
% Load the Image Dataset of Normal and Malignant WBC
imdsTrain = imageDatastore('D:\Project\DB1\train','IncludeSubfolders',true,'LabelSource','foldernames');
imdsTest = imageDatastore('D:\Project\DB1\test','IncludeSubfolders',true,'LabelSource','foldernames');
%Perform Cross-Validation using Hold-out method with a percentage split of 70% training and 30% testing
%[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
%%
%%
newext = '.tif';
while hasdata(imdsTrain)
[img, info] = read(imdsTrain);
[filedir, basename, ext] = fileparts(info.Filename);
newfilename = fullfile(filedir, [basename, newext]);
if ndims(img) == 2
img3 = repmat( imresize(im2uint8(img), [299 299]), [1 1 3] );
else
img3 = imresize(im2uint8(img), [299 299]);
end
imwrite(img3, newfilename);
end
while hasdata(imdsTest)
[img, info] = read(imdsTest);
[filedir, basename, ext] = fileparts(info.Filename);
newfilename1 = fullfile(filedir, [basename, newext]);
if ndims(img) == 2
img3 = repmat( imresize(im2uint8(img), [299 299]), [1 1 3] );
else
img3 = imresize(im2uint8(img), [299 299]);
end
imwrite(img3, newfilename1);
end
load('HW');
%%
%Select the Test images and save in Y_test
Y_test = newfilename1.UnderlyingDatastore.Labels;
%%
% optimzation techniques selection and hyperparamter selection
options = trainingOptions('adam', ...
'MiniBatchSize',16, ...
'MaxEpochs',20, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',newfilename1, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
%%
%CNN model training
netTransfer = trainNetwork(newfilename,HW,options);
%%
% for i=1:numel(imdsValidation.Files)
% a=[imdsValidation.Files(i)];
% a = imread(char(a));
% % featuresTest22 = activations(net,a,layer,'OutputAs','rows');
% YPred(i) = classify(netTransfer,a);
% imshow(a),title(char(YPred));
% i
% end
%%
% CNN Model validation
YPred = classify(netTransfer,newfilename1);
%Performance evaluation of Deep Learning Trained Model
plotconfusion(Y_test,YPred)

3 Comments

Dot indexing is not supported for variables of this type.
Error in CNN1 (line 40)
Y_test = newfilename1.UnderlyingDatastore.Labels;
yes,sir,newfilename1 now is just string,use for filename
so,if use it as datastore,may be use imageDatastore again to get image object
if possible,may be upload your image file zip to do some analysis

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Release

R2019a

Asked:

on 19 Jan 2022

Commented:

on 29 Jan 2022

Community Treasure Hunt

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

Start Hunting!