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

18 visualizaciones (últimos 30 días)
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 comentario
Walter Roberson
Walter Roberson el 19 de En. de 2022
https://www.mathworks.com/matlabcentral/answers/1627970-1-bit-tiff-images-having-more-than-1-channel-are-not-supported#comment_1944450

Iniciar sesión para comentar.

Respuesta aceptada

yanqi liu
yanqi liu el 20 de En. de 2022
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 comentarios
yanqi liu
yanqi liu el 20 de En. de 2022
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by