Error during Greyscale tiff image conversion to RGB tiff image

조회 수: 4 (최근 30일)
Claudio Esposito
Claudio Esposito 2021년 10월 22일
댓글: Claudio Esposito 2021년 10월 23일
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.

채택된 답변

Dave B
Dave B 2021년 10월 22일
편집: Dave B 2021년 10월 22일
You have a small typo:
tagstrut.PlanarConfiguration
you missed a c, you wanted
tagstruct.PlanarConfiguration

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by