Is it possible to write a YCbCr422 uncompressed TIFF file?

19 views (last 30 days)
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)
Has anyone had success in exporting YCbCr uncompressed TIFF files?
  2 Comments
Walter Roberson
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.
MechtEngineer
MechtEngineer on 29 Sep 2017
Many thanks for a great suggestion Walter. I have edited the question, and tried using the "read" function with a Tiff object. My small experiment seems to indicate that the MATLAB reads in exactly what it is trying to export. My guess is that possibly I am missing some setting in getting the LibTIFF library to write the image correctly.

Sign in to comment.

Accepted Answer

MechtEngineer
MechtEngineer on 29 Sep 2017
Edited: MechtEngineer on 3 Oct 2017
After hours of troubleshooting, it turns out the file is saving correctly, but it seems like Uncompressed YCbCr TIFFs must not be a common TIFF format since the exported images cannot be opened with the most common Windows image software.
Software that opens the TIFF correctly:
  • ImageMagick Display v6.9.3
  • GIMP v2.8.18
  • Nikon ViewNX-i v1.2.9 (opens YCbCr422 TIFFs correctly, but incorrectly displays TCbCr444)
Software that does not open the TIFF correctly (blank, black or error messages unless noted otherwise):
  • Windows Photo Viewer
  • Microsoft Office 2010 Photo Viewer
  • Faststone Image Viewer
  • Microsoft Paint
  • Canon Photo Professional v4 (an image may be seen, but with incorrect colours)
  1 Comment
Walter Roberson
Walter Roberson on 29 Sep 2017
Good information, thanks.
I would be interested in whether irfanview handles the files...

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!