Matlab: Raw image DNG BitsPerSample 10 not support - matlab

As Steve Eddin posted in http://blogs.mathworks.com/steve/2011/03/08/tips-for-reading-a-camera-raw-file-into-matlab/, I followed and copied the following code, running in MATLAB 2014b. As a result, I got the following error."Reading images with a BitsPerSample of 10 is not supported". I checked info and info.SubIFDs{1}, I got the following results in INFOS. I have searched on google for the problem, but there is no enough information. Therefore, I posted this problem here and hope someone gives me solutions.
CODE::
warning off MATLAB:tifflib:TIFFReadDirectory:libraryWarning
t = Tiff('Non-Invasive DNGs/WP_20150311_15_03_14_Raw__highres.dng','r');
offsets = getTag(t,'SubIFD');
setSubDirectory(t,offsets(1));
cfa = read(t);
close(t);
ERROR::
Error using Tiff.constructBlankOutputImage (line 2448)
Reading images with a BitsPerSample of 10 is not supported.
Error in Tiff/readAllStrips (line 2046)
imageData = obj.constructBlankOutputImage(imageSize,bps,sampleFormat);
Error in Tiff/read (line 1507)
[varargout{:}] = obj.readAllStrips();
Error in readDNG (line 11)
cfa = read(t);
INFOS_1::
FileSize: 43676288
Format: 'tif'
FormatVersion: []
Width: 960
Height: 544
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 1
BitsPerSample: [8 8 8]
Compression: 'Uncompressed'
PhotometricInterpretation: 'RGB'
StripOffsets: 69248
SamplesPerPixel: 3
RowsPerStrip: 544
StripByteCounts: 1566720
XResolution: []
YResolution: []
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: [255 255 255]
MinSampleValue: [0 0 0]
Thresholding: 1
Offset: 8
Make: 'Nokia'
Model: 'Lumia 1020'
Software: 'Nokia RAW-to-DNG converter v01.00.06'
DateTime: '2015:03:11 15:03:11'
SubIFDs: {[1x1 struct]}
DigitalCamera: [1x1 struct]
DNGVersion: [1 3 0 0]
DNGBackwardVersion: [1 3 0 0]
UniqueCameraModel: 'Nokia Lumia 1020'
ColorMatrix1: [1.6183 -0.7414 0.1000 -0.2665 1.1286 0.3664 0.1114 0.0951 0.8522]
ColorMatrix2: [0.9390 -0.1511 -0.0964 -0.3983 1.2153 0.1384 -0.0880 0.4120 0.5662]
CameraCalibration1: [1.0361 0 0 0 1 0 0 0 0.9688]
CameraCalibration2: [0.9851 0 0 0 0.9926 0 0 0 0.9763]
AnalogBalance: [1 1 1]
AsShotNeutral: [0.8476 1 0.6481]
BaselineExposure: -1
BaselineNoise: 1
BaselineSharpness: 1
LinearResponseUnit: 0.9999
ShadowScale: 1
DNGPrivateData: [1x1246 double]
MakerNoteSafety: 1
CalibrationIlluminant1: 17
CalibrationIlluminant2: 21
AliasLayerMetadata: [58 48 51 58 49 49 32 49 53 58 48 51 58 49 49 0]
UnknownTags: [7x1 struct]
INFOS_2::SubIFDs{1}
FileSize: 43676288
Format: 'tif'
FormatVersion: []
Width: 7728
Height: 4352
BitDepth: 10
ColorType: 'CFA'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: 10
Compression: 'Uncompressed'
PhotometricInterpretation: 'CFA'
StripOffsets: 1635968
SamplesPerPixel: 1
RowsPerStrip: 4352
StripByteCounts: 42040320
XResolution: []
YResolution: []
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 1023
MinSampleValue: 0
Thresholding: 1
Offset: 56578
CFAPlaneColor: [0 1 2]
CFALayout: 1
BlackLevelRepeatDim: [2 2]
BlackLevel: [0 0 0 0]
WhiteLevel: 1023
DefaultScale: [1 1]
DefaultCropOrigin: [0 0]
DefaultCropSize: [7728 4352]
BayerGreenSplit: 1
AntiAliasStrength: 1
BestQualityScale: 1
UnknownTags: [4x1 struct]

Related

Trace and Watch (wt) on breakpoint in WinDbg

I'd like to get a trace of function calls inside comctl32.dll beginning when the left mouse button is pressed on a tree control item and while the mouse button is held down.
I can set a breakpoint on comctl32!TV_ButtonDown and then use wt when the breakpoint is hit but this requires me to release the mouse button and interact with WinDbg. When I try to use a command string for my breakpoint like this: bp comctl32!TV_ButtonDown "wt -m comctl32", the tracing stops immediately after starting upon hitting the breakpoint:
Tracing COMCTL32!TV_ButtonDown to return address 00007ffd`57a48f1d
0 instructions were executed in 0 events (0 from other threads)
Function Name Invocations MinInst MaxInst AvgInst
0 system calls were executed
COMCTL32!TV_ButtonDown+0x5:
00007ffd`57b03bd9 48896c2418 mov qword ptr [rsp+18h],rbp ss:000000b7`746f8b00=0000000000000201
Is what I am attempting possible? Are there any alternatives?
not 64 bit but 32 bit
supply the end address
( top of stack or return address is what i give #$ra and don't release the mouse
it is not mandatory that you give #$ra but you should be sure that you will reach the end address
eventually without releasing the mouse lsft button)
0:000> bl
0 e Disable Clear 6e57a2ee 0001 (0001) 0:**** COMCTL32!TV_ButtonDown "wt -m comctl32 #$ra"
0:000> g
17 0 [ 0] COMCTL32!TV_ButtonDown
10 0 [ 1] COMCTL32!GetMessagePosClient
3 0 [ 2] USER32!GetMessagePos
18 3 [ 1] COMCTL32!GetMessagePosClient
17 0 [ 2] USER32!ScreenToClient
25 20 [ 1] COMCTL32!GetMessagePosClient
20 45 [ 0] COMCTL32!TV_ButtonDown
22 0 [ 1] COMCTL32!TV_DismissEdit
14 0 [ 2] USER32!IsWindowVisible
26 14 [ 1] COMCTL32!TV_DismissEdit
10 0 [ 2] USER32!GetDlgCtrlID
33 24 [ 1] COMCTL32!TV_DismissEdit
10 0 [ 2] USER32!SetWindowLongW
48 34 [ 1] COMCTL32!TV_DismissEdit
16 0 [ 2] COMCTL32!TV_InvalidateItem
40 0 [ 3] COMCTL32!TV_GetItemRect
24 40 [ 2] COMCTL32!TV_InvalidateItem
4 0 [ 3] USER32!NtUserRedrawWindow
27 44 [ 2] COMCTL32!TV_InvalidateItem
52 105 [ 1] COMCTL32!TV_DismissEdit
4 0 [ 2] USER32!NtUserShowWindow
58 109 [ 1] COMCTL32!TV_DismissEdit
34 0 [ 2] COMCTL32!CCSendNotify
25 0 [ 3] USER32!GetParent
40 25 [ 2] COMCTL32!CCSendNotify
18 0 [ 3] USER32!GetWindow
44 43 [ 2] COMCTL32!CCSendNotify
10 0 [ 3] USER32!GetDlgCtrlID
57 53 [ 2] COMCTL32!CCSendNotify
24 0 [ 3] USER32!GetWindowThreadProcessId
60 77 [ 2] COMCTL32!CCSendNotify
1 0 [ 3] kernel32!GetCurrentProcessIdStub
1 0 [ 3] kernel32!GetCurrentProcessId
3 0 [ 3] KERNELBASE!GetCurrentProcessId
87 82 [ 2] COMCTL32!CCSendNotify
24 0 [ 3] USER32!SendMessageW
109 106 [ 2] COMCTL32!CCSendNotify
16 0 [ 3] COMCTL32!InOutAtoW
118 122 [ 2] COMCTL32!CCSendNotify
3 0 [ 3] COMCTL32!__security_check_cookie
120 125 [ 2] COMCTL32!CCSendNotify
67 354 [ 1] COMCTL32!TV_DismissEdit
4 0 [ 2] USER32!NtUserDestroyWindow
75 358 [ 1] COMCTL32!TV_DismissEdit
3 0 [ 2] COMCTL32!__security_check_cookie
77 361 [ 1] COMCTL32!TV_DismissEdit
27 483 [ 0] COMCTL32!TV_ButtonDown
3 0 [ 1] COMCTL32!__security_check_cookie
29 486 [ 0] COMCTL32!TV_ButtonDown
515 instructions were executed in 514 events (0 from other threads)
Function Name Invocations MinInst MaxInst AvgInst
COMCTL32!CCSendNotify 1 120 120 120
COMCTL32!GetMessagePosClient 1 25 25 25
COMCTL32!InOutAtoW 1 16 16 16
COMCTL32!TV_ButtonDown 1 29 29 29
COMCTL32!TV_DismissEdit 1 77 77 77
COMCTL32!TV_GetItemRect 1 40 40 40
COMCTL32!TV_InvalidateItem 1 27 27 27
COMCTL32!__security_check_cookie 3 3 3 3
KERNELBASE!GetCurrentProcessId 1 3 3 3
USER32!GetDlgCtrlID 2 10 10 10
USER32!GetMessagePos 1 3 3 3
USER32!GetParent 1 25 25 25
USER32!GetWindow 1 18 18 18
USER32!GetWindowThreadProcessId 1 24 24 24
USER32!IsWindowVisible 1 14 14 14
USER32!NtUserDestroyWindow 1 4 4 4
USER32!NtUserRedrawWindow 1 4 4 4
USER32!NtUserShowWindow 1 4 4 4
USER32!ScreenToClient 1 17 17 17
USER32!SendMessageW 1 24 24 24
USER32!SetWindowLongW 1 10 10 10
kernel32!GetCurrentProcessId 1 1 1 1
kernel32!GetCurrentProcessIdStub 1 1 1 1
0 system calls were executed
eax=00000000 ebx=00000201 ecx=422f0fd7 edx=77a370f4 esi=002d9590 edi=00000200
eip=6e542888 esp=0012fcc4 ebp=0012fd00 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
COMCTL32!TV_WndProc+0x577:
6e542888 e90a060000 jmp COMCTL32!TV_WndProc+0x5de (6e542e97)

Writing TIFF Appears Black But imagesc does not MATLAB

I want to write a tiff again after having read it into MATLAB. The tiff files were generated by some other software:
[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();
This line which is supposed to rescale the intensity range:
J2(:,:) = uint16((J2(:,:)./max(max(J2(:,:),[],1)))*65536);
was borrowed from here: https://stackoverflow.com/a/19949536/3319527. But my images still come out as black. This should not be the case because with imagesc though the signals are quite noisy but the data output to the screen makes sense but the tiffs I write to file are quite useless.
Image Parameters:
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: '
From 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
Thanks!

matlab imshow not working with certain tiff files

I get the following errors when trying to run imshow with some tiff files:
??? Error using ==> imageDisplayValidateParams>validateCData at 114
Unsupported dimension
Error in ==> imageDisplayValidateParams at 31
common_args.CData = validateCData(common_args.CData,image_type);
Error in ==> imageDisplayParseInputs at 79
common_args = imageDisplayValidateParams(common_args);
Error in ==> imshow at 199
[common_args,specific_args] = ...
Error in ==> CellArea at 6
imshow('A1 x20.tiff')
I initially stored the image data in a matlab variable using imread and when that didn't work with imshow I used it to just get the image directly with the filename; the error messages are the same.
The problem images I'm trying to analyze are 1032x778 tiff files. I made a sample tif image using Paint and the function has no problems with it. Does anybody know what is causing these errors and how to get the image to display? Thanks
Here is the infinfo output for one of the images, as requested
Filename: 'A1 x20.tiff'
FileModDate: '14-Oct-2013 15:49:26'
FileSize: 3211714
Format: 'tif'
FormatVersion: []
Width: 1032
Height: 778
BitDepth: 32
ColorType: 'truecolor'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: [8 8 8 8]
Compression: 'Uncompressed'
PhotometricInterpretation: 'RGB'
StripOffsets: 8
SamplesPerPixel: 4
RowsPerStrip: 4.2950e+009
StripByteCounts: 3211584
XResolution: []
YResolution: []
ResolutionUnit: 'None'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: [255 255 255 255]
MinSampleValue: 0
Thresholding: 1
Offset: 3211592
doing x = imread('A1 x20.tiff') and then whos x gives
Name x
Size 778x1032x4
Bytes 3211584
Class uint8
Attributes
For some reason your tiff file has four channels (nothing to do with multiple frames): size(x,3)==4. I guess the fourth is an alpha-channel.
imshow can display either gray scale images, indexed images (with size(x,3)==1) or true-color images (with size(x,3)==3). Your image had 4 channels and thus imshow failed.
Asking inshow to work only on the first three channels made the trick:
>> imshow( x(:,:,1:3) );

cannot open tiff files compressed in this fashion (2) - imageJ/FIJI

I have two sets of images generated from MATLAB - one set is when I save manually from the figure window into a tif file and the other set has images saved in tif format by using imwrite function in MATLAB.
When I try to use the first set of images to perform some operations in Fiji (Image J) it works but when I try doing the same on the second set, I get an error saying 'cannot open tiff files compressed in this fashion (2)'. Is there a plugin that I need to install?
imfinfo for first set - created by saveas tif from figure window:
Filename: [1x68 char]
FileModDate: [1x20 char]
FileSize: 51376
Format: 'tif'
FormatVersion: []
Width: 719
Height: 477
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: [1x4 double]
ByteOrder: [1x13 char]
NewSubFileType: 0
BitsPerSample: [8 8 8]
Compression: 'PackBits'
PhotometricInterpretation: 'RGB'
StripOffsets: [69x1 double]
SamplesPerPixel: 3
RowsPerStrip: 7
StripByteCounts: [69x1 double]
XResolution: 96
YResolution: 96
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: [1x3 double]
MinSampleValue: [0 0 0]
Thresholding: 1
Offset: 50592
ImageDescription: [1x22 char]
imfinfo for second set - created by imwrite. imwrite(bw,fullfile(filename),'tiff');
Filename: [1x75 char]
FileModDate: [1x20 char]
FileSize: 25586
Format: 'tif'
FormatVersion: []
Width: 832
Height: 587
BitDepth: 1
ColorType: [1x9 char]
FormatSignature: [1x4 double]
ByteOrder: [1x13 char]
NewSubFileType: 0
BitsPerSample: 1
Compression: [1x8 char]
PhotometricInterpretation: [1x11 char]
StripOffsets: [66x1 double]
SamplesPerPixel: 1
RowsPerStrip: 9
StripByteCounts: [66x1 double]
XResolution: 72
YResolution: 72
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 1
MinSampleValue: 0
Thresholding: 1
Offset: 24868
I am not sure, if you got the answer yet. I had a similar problem. Try saving your file via:
imwrite(bw,fullfile(filename),'tiff', 'Compression','none');
or try compression using 'packbits'
imwrite(bw,fullfile(filename),'tiff', 'Compression','packbits');
Try this plugin for ImageJ - IJ Plugins: Image I/O.
EDIT
It look like your image is binary (BitDepth=1). IMWRITE by default saves binary image in TIFF format with ccitt compression. Such images are not supported by IMageJ. (See, for example, this thread for a possible reason).
If you need to save your images with imwrite try to set BitDepth to 24 and Compression to packbits. Compare other fields in imfinfo outputs and use different ones in imwrite if necessary.

about tiff image

imfinfo of my image gives the following:
Filename: 'drosophila.tif'
FileModDate: '10-Nov-2009 18:52:42'
FileSize: 264768
Format: 'tif'
FormatVersion: []
Width: 512
Height: 512
BitDepth: 8
ColorType: 'grayscale'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: 8
Compression: 'PackBits'
PhotometricInterpretation: 'BlackIsZero'
StripOffsets: [32x1 double]
SamplesPerPixel: 1
RowsPerStrip: 16
StripByteCounts: [32x1 double]
XResolution: 72
YResolution: 72
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 255
MinSampleValue: 0
Thresholding: 1
Offset: 264322
how many strips are there?
generic logic:
ceil(Height/RowsPerStrip)
The TIFF specifications states that the last strip need not be full (hence the CEIL call).
Or, the length of the StripOffsets from the info structure. As the name implies, this is a vector of byte offsets to each strip in the file (so there has to be one offset per strip).
32.
Height: 512
RowsPerStrip: 16
512 = 2^9; 16=2^4. Divide to get 2^5 which is 32.