Problems with saving unsigned 16 bit image data
Show older comments
i am currently trying to use a ROS based software that uses 16 bit unsigned depth images.
I create my "own" dataset. I am saving my files as unsigned 16 bit image as imwrite(Z,fname,'fmt','png','BitDepth',16,'map','gray');
initially, I also tried the simple versions as well like imwrite(Z,fname,'fmt','png',) etc.. but they all don't work in the ROS software.
Is there a particular way i should be saving the depth data? to check if there wasnt some issue with the software i also performed the following step:
I used the depth files provided with the software and successfully obtained the results from it. Then, I read those depth files in matlab and saved them back again using the above call and it immediately fails to work. So i am pretty sure the problem is the way i am saving the data.
edit: I have included the input file: d_test.png and output file: dtect_out.png. I am simply performing 2 steps:
ZZ = imread('D:\Datasets\d_test.png');
imwrite(ZZ,'dtest_out.png','fmt','png','BitDepth',16,'map','gray','Mode','lossless');
The input file is 122kb while output file is 85kb so MATLAb is probably doing something internally that changes the file. infinfo is exactly the same except for date/filesize and othertext.
2 Comments
Image Analyst
on 21 Dec 2015
Is Z a double, or is it already a uint16? What does this say in the command window?
whos Z
And what is ROS software? Many/most people probably don't know that acronym. acnronymfinder.com lists 69 possible answers but I didn't review them all.
Ramanpreet
on 21 Dec 2015
Accepted Answer
More Answers (1)
Walter Roberson
on 21 Dec 2015
0 votes
The content of the files are identical except for a minor difference in the header. The error must be elsewhere.
For example if you rename the saved file to the first name, does it start working?
6 Comments
Ramanpreet
on 21 Dec 2015
Image Analyst
on 21 Dec 2015
Perhaps MATLAB's imwrite() used a different flavor of compression than whatever software you used to create d_test.png in the first place. I don't know enough about what compression scheme PNG uses to know if there are choices you can specify about how the compression is done.
PNG uses zlib compression, always. The only choice that you have is on the amount of compression done, but any program worth its salt should be able to decompress a file regardless of the compression level. Otherwise, it can't be claimed to be png compliant.
Edit: Saying that, the only difference of significance is in the compression level. matlab uses the default compression level of 2, the original image uses compression level of 0 (fastest compression at the expense of size).
Walter Roberson
on 21 Dec 2015
Guillaume, which tool were you able to use to find the compression level? The tools I used do not seem to report that?
Image Analyst
on 21 Dec 2015
Good answer by Guillaume (I voted for it). It looks like he used a hex editor, so apparently there is not any nifty user-friendly utility to read and report on the PNG information encoded with it (or at least he didn't use it, or wasn't able to find such a utility).
There's probably a tool to analyse pngs (I think I may even have written one in the past) but having written my own png encoder/decoder in the past, I'm familiar enough with the format that actually looking at the hex content of the file is easier.
The format is very well designed, everything is stored in chunks with easily readable names (IHDR, IDAT, tEXT, IEND, etc.), so you just have to locate these to find what is in the file.
@walter, the compression level used by the zlib stream is in the second byte after in the first IDAT. bit 6 and 7 of that byte is the compression level.
The original file reads: IDAT 78 01 (last two values in hex), the 78 means zlib deflate (only option, with a 32k window), the 01 means compression mode 0, which gives a checksum of 1.
The matlab file reads IDAT 78 9C, same 78, 9C means compression mode of 2 which results in a checksum value of C.
Categories
Find more on Image Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!