Concatenating YCbCr channels gives distorted colors
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to do something simple. I am separating an image into Y, Cb, Cr channels, saving them into different directories using imwrite, and then scaling them (by a factor of 2) using different interpolation methods. After scaling them, I read the channels from their respective directories using imread, and put them togther using cat(3, Y, Cb, Cr), then I convert them to rgb using ycbcr2rgb, and save the results using imwrite. The saved image shows distorted colors. Here I am showing the original image vs the resulting one after processing and concatenation. I made sure that the order of the channels is correct. I am not sure what else could be causing this.
Edit: this error still occurs even without scaling the channels individually. Just by saving the channels in different directories, reading them again, and then concatenating, the colors appear as seen in the picture. I tried saving as jpg and png, both lead to the same result.
I tested to see if the values of Y, Cb, Cr are the same before and after saving (without doing any processing in between). Turns out that Y is the same, but Cb and Cr differ as soon as I save (all the channels are of type uint8).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230739/image.png)
0 Kommentare
Antworten (1)
Walter Roberson
am 22 Jul. 2019
This is expected. Your conversion to Y Cr Cb is producing data that is not integer data class. When you imwrite floating point then matlab assumes data range 0 to 1, multiplies by 255, does uint8(), and writes that.
If the results of YCrCb happens to be integral then uint8() it.
My recollection is that the YCrCb conversion leaves you with values that are not strictly in the range 0 to 1.
If you need to write floating point to image then you should use Tiff class; there is a file exchange contribution to do the work to write floating point tiff.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!