Error during Greyscale tiff image conversion to RGB tiff image

4 vues (au cours des 30 derniers jours)
Claudio Esposito
Claudio Esposito le 22 Oct 2021
Hello everyone, I need your kind help.
I'm working on my thesis regarding deep learning techniques and during the process of conversion from greyscale image to RGB image, I got an error.
I saved these images as geotiff from Snap and now I need to put them as input to Mask R-CNN.
However, Mask accepts only RGB images.
Following, the code I wrote:
%% RGB Data Conversion
d = uigetdir(pwd,'Select the Dataset Folder');
srcDir = dir(fullfile(d,'*.tif'));
for i = 1:length(srcDir)
baseFileName = srcDir(i).name;
filename = fullfile(srcDir(i).folder, baseFileName);
s1 = 'RGB';
newfilename = strcat(s1, baseFileName);
grayIm = imread(filename);
RGB = cat(3, grayIm, grayIm, grayIm);
t = Tiff(newfilename,'w');
tagstruct.ImageLength = size(RGB, 1);
tagstruct.ImageWidth = size(RGB, 2);
tagstruct.Photometric = Tiff.Photometric.RGB;
tagstruct.BitsPerSample = 8;
tagstruct.SamplesPerPixel = 3;
tagstrut.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.Software = 'MATLAB';
setTag(t, tagstruct);
write(t, RGB);
close(t)
end
and the error I got:
Error using tifflib
Illegal value (0) for PlanarConfiguration.
Error in Tiff/writeAllStrips (line 1938)
meta = tifflib('retrieveMetadata', obj.FileID);
Error in Tiff/write (line 1486)
obj.writeAllStrips(varargin{:});
Error in MASK_R_CNN (line 26)
write(t, RGB);
Can someone help me?
Thank you for your availability.

Réponse acceptée

Dave B
Dave B le 22 Oct 2021
Modifié(e) : Dave B le 22 Oct 2021
You have a small typo:
tagstrut.PlanarConfiguration
you missed a c, you wanted
tagstruct.PlanarConfiguration
  1 commentaire
Claudio Esposito
Claudio Esposito le 23 Oct 2021
Oh my God, I'm pretty embarrassed about it. Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by