1-bit TIFF images having more than 1 channel are not supported.

9 次查看(过去 30 天)
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(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(img, [299 299]), [1 1 3] );
imwrite(img3, newfilename1);
end
load('HW');
%%
%Select the Test images and save in Y_test
Y_test = imdsReSz1.UnderlyingDatastore.Labels;
%%
% optimzation techniques selection and hyperparamter selection
options = trainingOptions('adam', ...
'MiniBatchSize',16, ...
'MaxEpochs',20, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsReSz1, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
%%
%CNN model training
netTransfer = trainNetwork(imdsReSz,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,imdsReSz1);
%Performance evaluation of Deep Learning Trained Model
plotconfusion(Y_test,YPred)
Error using writetif (line 78)
1-bit TIFF images having more than 1 channel are not supported.
Error in imwrite (line 546)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in CNN1 (line 19)
imwrite(img3, newfilename);
>>

采纳的回答

DGM
DGM 2022-1-13
编辑:DGM 2022-1-13
This is happening because img is of class 'logical'. You expand img to MxNx3 (img3). When writing the TIFF, if the BitsPerSample property is 1 (logical), then the SamplesPerPixel property cannot be anything other than 1. You're trying to set SamplesPerPixel to 3.
How you handle this depends on what you want. If all your images are logical class, then I see no reason to expand them. If you don't intend to treat these images as logical images, you can convert the images to some compatible class (e.g. using im2uint8() or something).
  4 个评论
sun rise
sun rise 2022-1-20
Thanks for your advice.
My IFN/ENIT images are tif files greyscaled. How do I avoid expanding with epmat()? Is there another way to resize and make the grid accept greyscale images? how can i modify my code to apply into inception_v3 ?
DGM
DGM 2022-1-20
I don't know what inception_v3 is. I have no familiarity with DLT. I'm not sure why you're expanding the images to 3 channels, or whether that's necessary for the tools or process you're using.
If your process works only with 3-channel images, check the incoming image and then only expand it if it's not already a 3-channel image.
[img, info] = read(imdsTrain);
% ...
img = imresize(im2uint8(img), [299 299]);
if size(img,3)==1
img3 = repmat(img, [1 1 3] );
elseif size(img,3)==3
img3 = img;
else
error('expected image to have either 1 or 3 channels, instead it has %d channels',size(img,3))
end
% ...
On the other hand, if your process works with 1-channel images and you want to work with that (perhaps the reduced data volume is advantageous in terms of speed?)
[img, info] = read(imdsTrain);
% ...
img = imresize(im2uint8(img), [299 299]);
if size(img,3)==1
img3 = img;
elseif size(img,3)==3
img3 = rgb2gray(img);
else
error('expected image to have either 1 or 3 channels, instead it has %d channels',size(img,3))
end
% ...
I don't have DLT, so I can't really say what's best for your needs.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by