Is it possible to write a YCbCr422 uncompressed TIFF file?
19 views (last 30 days)
Show older comments
MechtEngineer
on 29 Sep 2017
Edited: MechtEngineer
on 3 Oct 2017
I have some data in a YCbCr422 sequence file, and I would like to export it in the form of YCbCr uncompressed TIFF files.
Evidence that this may be possible:
The http://www.simplesystems.org/libtiff/support.html website suggests that it is possible to have no compression with YCbCr Photometric Interpretation.
Class Y for YCbCr images
SamplesPerPixel = 3
BitsPerSample = <8,8,8>
PlanarConfiguration = 1, 2
Compression = 1 (none), 5 (LZW), 7 (JPEG)
PhotometricInterpretation = 6 (YCbCr)
YCbCrCoefficients, YCbCrSubsampling, YCbCrPositioning
Evidence that this may not be possible:
Advice from https://www.awaresystems.be/imaging/tiff/faq.html. It doesn't explicitly rule out the possibility of uncompressed YCbCr though.
The YCbCr color space and JPEG compression scheme are de facto
related. Other than using JPEG as compression scheme, there is
in our humble opinion no good reason for using YCbCr.
My effort so far
The following code successfully saves a TIF image, but when I view it in a photo viewer, nothing is seen.
% Set the tags of the output file
tagstruct.ImageLength = headerInfo.ImageHeight; % Rows
tagstruct.ImageWidth = headerInfo.ImageWidth; % Cols
tagstruct.SampleFormat = 1; % uint
tagstruct.Photometric = 6; % MinIsBlack(1), RGB(2), YCbCr(6)
tagstruct.BitsPerSample = 8; % Limited set: 1, 8, 16, 32, or 64.
tagstruct.SamplesPerPixel = 3; % 3 expected for Photometric YCbCr
tagstruct.YCbCrSubSampling = [2,1];
tagstruct.Compression = 1; % none(1)
tagstruct.DateTime = headerInfo.timestamp{frameNo};
tagstruct.Orientation = 1; % TopLeft(1)
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.Software = 'MATLAB';
% Write the tags to the TIFF object
tiffObject.setTag(tagstruct);
Y = uint8(YUV(:,:,1));
U = uint8(UYVYimg(:,1:4:end));
V = uint8(UYVYimg(:,3:4:end));
% Write the image data and metadata to the writeaddress
tiffObject.write(Y,U,V);
I tried importing the exported file with imread. This was not a good idea since imread function automatically converts TIFF YCbCr values to RGB.
As suggested by Walter Robertson, I then used the read function on a TIFF object to read the files, and this produced the results below. I thought that I should remove the complexity of 422 subsampling from the troubleshooting process, so I tried the whole process with non-subsampled 444. Note that I use the terms "YCbCr" interchangeably with "YUV" since I am dealing with video.
Note: right-click and select "Open in new tab" to view this image full-size. Please note that I do not have original 444 data, so I replicated every second column of the "4:2:2" data to create "4:4:4" data (this is how 4:2:2 data is displayed anyway - see Wikipedia's Chroma Subsampling article)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167667/image.png)
Has anyone had success in exporting YCbCr uncompressed TIFF files?
2 Comments
Walter Roberson
on 29 Sep 2017
If you use a tiff object to read the matrix, do you get exactly what you wrote? That would help isolate whether the problem is with what was written or with imread()'s conversion of the matrix.
Accepted Answer
MechtEngineer
on 29 Sep 2017
Edited: MechtEngineer
on 3 Oct 2017
1 Comment
Walter Roberson
on 29 Sep 2017
Good information, thanks.
I would be interested in whether irfanview handles the files...
More Answers (0)
See Also
Categories
Find more on Image Data 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!