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

조회 수: 9 (최근 30일)
sun rise
sun rise 2022년 1월 12일
댓글: DGM 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]);
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