我想在读完MATLAB后再写一个tiff。 tiff文件由其他一些软件生成:
[flnm,locn]=uigetfile({'*.tif','Image files'}, 'Select an image');
fp=fullfile(locn,flnm);
I = double(imread(fp));
info = imfinfo(fp);
.
.
.
J2 = im2int16(J2);
J2(:,:) = uint16((J2(:,:)./max(max(J2(:,:),[],1)))*65536);
T = Tiff((fullfile(strcat(locn,v_f), (sprintf('%d.tif',i)))), 'w');
tagstruct.ImageLength = size(J2, 1);
tagstruct.ImageWidth = size(J2, 2);
tagstruct.Compression = Tiff.Compression.None;
tagstruct.SampleFormat = Tiff.SampleFormat.Int;
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = info.BitsPerSample; % 32;
tagstruct.SamplesPerPixel = info.SamplesPerPixel; % 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
T.setTag(tagstruct);
T.write(J2);
T.close();
这条线应该重新调整强度范围:
J2(:,:) = uint16((J2(:,:)./max(max(J2(:,:),[],1)))*65536);
是从这里借来的:https://stackoverflow.com/a/19949536/3319527。但我的照片仍然是黑色的。这不应该是这种情况,因为虽然信号很嘈杂但是输出到屏幕的数据是有意义的但是我写入文件的tiff很没用。
图像参数:
Filename: [1x172 char]
FileModDate: '24-Jan-2014 14:39:09'
FileSize: 32003
Format: 'tif'
FormatVersion: []
Width: 125
Height: 125
BitDepth: 16
ColorType: 'grayscale'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: 16
Compression: 'Uncompressed'
PhotometricInterpretation: 'BlackIsZero'
StripOffsets: [8 2008 4008 6008 8008 10008 12008 14008 16008 18008 20008 22008 24008 26008 28008 30008]
SamplesPerPixel: 1
RowsPerStrip: 8
StripByteCounts: [2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 1250]
XResolution: 72
YResolution: 72
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 65535
MinSampleValue: 0
Thresholding: 1
Offset: 31768
ImageDescription: '
来自tiff info:
TIFF File: '000001.tif'
Mode: 'r'
Current Image Directory: 1
Number Of Strips: 16
SubFileType: Tiff.SubFileType.Default
Photometric: Tiff.Photometric.MinIsBlack
ImageLength: 125
ImageWidth: 125
RowsPerStrip: 8
BitsPerSample: 16
Compression: Tiff.Compression.None
SampleFormat: Tiff.SampleFormat.UInt
SamplesPerPixel: 1
PlanarConfiguration: Tiff.PlanarConfiguration.Chunky
ImageDescription:
This is frame #0000
Orientation: Tiff.Orientation.TopLeft
谢谢!