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

5 ビュー (過去 30 日間)
sun rise
sun rise 2022 年 1 月 19 日
コメント済み: sun rise 2022 年 1 月 29 日
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 件のコメント
Walter Roberson
Walter Roberson 2022 年 1 月 19 日
https://www.mathworks.com/matlabcentral/answers/1627970-1-bit-tiff-images-having-more-than-1-channel-are-not-supported#comment_1944450

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

採用された回答

yanqi liu
yanqi liu 2022 年 1 月 20 日
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 件のコメント
sun rise
sun rise 2022 年 1 月 29 日
My DB.. Thank you in advance

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by