Reading 10bit raw image in Matlab
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have a 10bit raw image (input.yuv) and would like to read it in Matlab. To do so, I am using the following commands:
fid = fopen('input.yuv','r');
a = fread(fid,'uint16');
fclose(fid);
When I get the max(a(:)), it is 730. However, I have white pixels in the image. My question is that:
- To get the image data between 0 and 1, should I divid them by (2^16-1) or (2^10-1). The original content is 10bit.
- Why I don't get (2^10-1 or 2^16-1) for the white pixels?
채택된 답변
Walter Roberson
2020년 3월 17일
편집: Walter Roberson
2020년 3월 17일
0 개 추천
You have not decoded the yuv to its 4:4:2 components.
YUV with 8 bits per channel does not use the full range of values for any component. Also, white is not encoded as the largest possible value: white is U component and V component 0 (they are signed) which gets stored as YCrCb with Cr and Cb = 128 each https://en.m.wikipedia.org/wiki/YUV
댓글 수: 13
WhiteFlower
2020년 3월 17일
편집: WhiteFlower
2020년 3월 17일
The image is a frame of a clip encoded as yuv420p10le (extracted using ffmpeg).
WhiteFlower
2020년 3월 17일
I would like to preserve 10 bits, not reducing to 8bits. Is frame = fread(fid,'uint16') a right way to read this data before converting to RGB?
There is a possibility that you might need
frame = fread(fid,'*uint16', 0, 'ieee-be');
WhiteFlower
2020년 3월 17일
Thank you this works!
WhiteFlower
2020년 3월 17일
And one more question. Is this now 10 bits just stored in 16bits? How can I verify that? Is there anyway to handle 10bits in Matlab?
Walter Roberson
2020년 3월 17일
There are two possibilities for storing 10 bits in 16. One of the ways is to put the 10 bits into the most significant bits, leaving the bottom 6 bits 0. The other is to put the 10 bits into the least significant bits, leaving the top 6 bits 0. Both are valid methods. It is typically easy to tell which scheme is being used: if any value is 2^10 or more then you are stuffing into the top bits for sure. (There is a marginal case that is not decideable, in the situation where both the top 6 and bottom 6 bits are clear.)
Putting the information into the top (most significant) bits is common for work with sensors like analog to digital work: if you put it into the top then you can substitute sensors with higher resolution without affecting the code.
WhiteFlower
2020년 3월 17일
I appreciate your detailed response. Is this something that I can do with the following command?
frame = fread(fid,'*uint10', 0, 'ieee-be');
Is this correct?
No, there is no uint10 precision for fread()
You could do
frame = fread(fid,'ubit10->uint16', 0, 'ieee-be');
but what that would mean is that it would read groups of 10 bits at a time, regardless of word boundaries. The first group of 10 bits would go into the first value, the second group of 10 bits would go into the second value, and so on. some encodings do that, but .yuv files do not tend to do so: they tend to use the full 16 bits of file for each entry.
If you have 10 bits of data in the most significant bits, you can (if you need to) extract the bits using bitget() . Or you could divide by 2^6 to move the bits to the bottom.
WhiteFlower
2020년 3월 17일
Thanks a lot again! Here is a summary of my outputs:
frame = fread(fid,'ubit10=>uint16', 0, 'ieee-be') did not work, i.e. the outcome displayed image (after converting yuv to RGB) is scrambled.
The output of frame = fread(fid,'*uint16', 0, 'ieee-be') is 16 bits as I wished, and the max(frame(:)) = 65281 that is very close to my expectation for the white but the displayed image is mostly purple. I probably did not a right conversion or maybe did not correctly imshow 16bit data.
The output of frame = fread(fid,'uint16') is double (however I would like to work with 10bits) and max(frame(:)) = 730 (that does not make sense to me). But the displayed image after conversion to RGB is correct (color wise). However, I am not sure if this is the right way of reading 10bit raw data.
frame = fread(fid,'*uint16');
Would be plausible.
Walter Roberson
2020년 3월 18일
For my own reference at some later time:
WhiteFlower
2020년 3월 18일
The last command works pretty well. Thank you so much for all your help.
Walter Roberson
2020년 3월 18일
Routines I find in the file exchange such as https://www.mathworks.com/matlabcentral/fileexchange/6318-convert-yuv-cif-4-2-0-video-file-to-image-files and https://www.mathworks.com/matlabcentral/fileexchange/11318-transform-yuv-file read Y then U then V, but the Microsoft link says that the format is Y then U+V interleaved.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
