How do I MatLab from changing RowsPerStrip (tagID 278) upon opening Tiff?
2 次查看(过去 30 天)
显示 更早的评论
I actually have a few questions but the main one is as posed in the title.
Situation:
I use ImageJ 1.50b to manipulate multiple single-page 32-bit gray-scale Tiffs and save the results as a single multi-page binary (8-bit gray-scale with 0 and 255; not bi-level) Tiff. The saved Tiff has the following values in each IFD (as verified using 'imfinfo' and a third-party non-MatLab Tiff tag reader). The format is "TagName (Count DataType): Value".
SubFileType (1 Long): Zero
ImageWidth (1 Long): 1300
ImageLength (1 Long): 1300
BitsPerSample (1 Short): 8
Photometric (1 Short): MinIsWhite
ImageDescription (70 ASCII): ImageJ=1.50b images=203 slices=203 unit=cm sp...
StripOffsets (1 Long): 1738610
SamplesPerPixel (1 Short): 1
RowsPerStrip (1 Short): 1300
StripByteCounts (1 Long): 1690000
XResolution (1 Rational): 4545.4545450697
YResolution (1 Rational): 4545.4545450697
ResolutionUnit (1 Short): Centimeter
The first IFD has two unrecognized tags which I assume are part of ImageJ's unusual format which supports Tiffs larger than 4 GB (even though my image is only 328 MB). I am using MatLab 2015a and get the following.
>> image=Tiff('myimage.tif', 'r+');
Warning: TIFF library warning - 'TIFFReadDirectory: Unknown field with tag 50838 (0xc696)
encountered.'
Warning: TIFF library warning - 'TIFFReadDirectory: Unknown field with tag 50839 (0xc697)
encountered.'
>> info=imfinfo('myimage.tif');
>> info(1)
ans =
Filename: 'myimage.tif'
FileModDate: '23-Mar-2016 19:15:00'
FileSize: 343151334
Format: 'tif'
FormatVersion: []
Width: 1300
Height: 1300
BitDepth: 8
ColorType: 'grayscale'
FormatSignature: [77 77 0 42]
ByteOrder: 'big-endian'
NewSubFileType: 0
BitsPerSample: 8
Compression: 'Uncompressed'
PhotometricInterpretation: 'WhiteIsZero'
StripOffsets: 48610
SamplesPerPixel: 1
RowsPerStrip: 1300
StripByteCounts: 1690000
XResolution: 4.5455e+03
YResolution: 4.5455e+03
ResolutionUnit: 'Centimeter'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 255
MinSampleValue: 0
Thresholding: 1
Offset: 8
ImageDescription: 'ImageJ=1.50b
images=203
slices=203
unit=cm
spacing=2.2E-4
loop=false
'
UnknownTags: [2x1 struct]
>> image.getTag(Tiff.TagID.RowsPerStrip)
ans =
6
>> image.getTag(Tiff.TagID.StripByteCounts)
ans =
Columns 1 through 4
7800 7800 7800 7800
Columns 5 through 8
7800 7800 7800 7800
...shortened to keep this post short...
Columns 213 through 216
7800 7800 7800 7800
Column 217
5200
>>
If I modify a tag using 'setTag(image, id, value)' and then close the Tiff using 'close(image)', it will save the changes, including the change to the 'RowsPerStrip' and 'StripByteCounts' tags. I have tried to manually reset the tags and get the following.
>> setTag(image, Tiff.TagID.RowsPerStrip, 1300);
>> setTag(image, Tiff.TagID.StripByteCounts, 1690000);
Error using tifflib
Tag number (279) is unrecognized by the TIFF library.
Error in Tiff/setTag (line 1397)
tifflib('setField',obj.FileID,varargin{:});
>>
Questions:
- How do I prevent MatLab from changing the 'RowsPerStrip' and 'StripByteCounts' tags? If I cannot, how can I reset the values?
- From the MatLab documentation for 'setTag', "Note: If you are modifying a tag rather than creating it, you must use the Tiff.rewriteDirectory method after using the Tiff.setTag method." If this is the case, why are the changes saved when I close the image even though I don't use 'rewriteDirectory'?
0 个评论
回答(0 个)
另请参阅
类别
在 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!