Use low-level functions (not imread.m) to read an grayscale image
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
dpb
2017-5-12
编辑:dpb
2017-5-13
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!