t=Tiff('Stacked.tiff','w');
tagstruct.ImageLength = y1;
tagstruct.ImageWidth = x1;
tagstruct.Photometric = Tiff.Photometric.RGB;
tagstruct.BitsPerSample = 8;
tagstruct.SamplesPerPixel = 3;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.Software = 'MATLAB';
setTag(t,tagstruct)
write(t,squeeze(im2uint8(Imagelayer1)));
writeDirectory(t);
setTag(t,tagstruct)
write(t,squeeze(im2uint8(Imagelayer2)))
close(t)
Best Answer