Use low-level functions (not imread.m) to read an grayscale image

조회 수: 1 (최근 30일)
Yuzhen Lu
Yuzhen Lu 2017년 5월 12일
편집: dpb 2017년 5월 13일
I try to use low-level functions (fopen.m and fread.m) to read a grayscale image of uint16 in tiff format as follows:
fid = fopen(filepath,'r');
img = fread(fid,[ncolms, nrows], 'uint16=>uint16')';
The obtained image matrix is different from that obtained by simply using imread.m:
img = imread(filepath)
The resulting images by the two approaches are shown below (the left is by fread.m and the right is by imread.m):
You can see that, in addition to the obvious intensity difference, fread.m gives some artifacts in the top edge of image. I think this must be due to their different mechanisms of reading images.
I want to know how to use such low-level functions as fopen.m and fread.m to read images (grayscale not binary), equivalently to using imread.m, if they can?

답변 (1개)

dpb
dpb 2017년 5월 12일
편집: dpb 2017년 5월 13일
See <TIFF-v6> for structure...
ERRATUM: Corrected link -- dpb
ADDENDUM
"I think this [displayed image differences] must be due to their different mechanisms of reading images."
Well, not really. As the spec shows, there's a whole lot more in an image file than just the data...you were just lucky in that the image you chose was only a single image in the file and wasn't compressed (albeit for gray-scale that's often futile so they generally aren't) so that what you got by ignoring all that structure in the file looked anything whatsoever like an image.
Sure, it's possible, but you've got to decode the file header to retrieve the data from the proper locations within the file where it's stored and put it together properly.
Why would you want to reinvent the wheel, here???
  댓글 수: 2
dpb
dpb 2017년 5월 13일
편집: dpb 2017년 5월 13일
Ah, what'd be the fun in that??!!! :)
(PS. Fixed the above link so it does actually work now...)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by