Error during Greyscale tiff image conversion to RGB tiff image

4 views (last 30 days)
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.

Accepted Answer

Dave B
Dave B on 22 Oct 2021
Edited: Dave B on 22 Oct 2021
You have a small typo:
tagstrut.PlanarConfiguration
you missed a c, you wanted
tagstruct.PlanarConfiguration

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!