Error during Greyscale tiff image conversion to RGB tiff image
4 views (last 30 days)
Show older comments
Claudio Esposito
on 22 Oct 2021
Commented: Claudio Esposito
on 23 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.
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!