Display .bin depth image in Matlab

278 views Asked by At

Here is the .bin image which I saved in c#. Please anyone help to view this in MATLAB. the dimension of image 424 x 512.

I have tried this code, but its not working correctly

file = fopen('test0.bin', 'r');
A = fread(file, 424*512, 'uint16=>uint16');
A1 = reshape(A, 424, 512);
imagesc(A1)

Before doing downmark please tell me the reason so j can update this

1

There are 1 answers

2
Daniel On BEST ANSWER

There are row major and column major programming languages. To simplify, which is the second element in memory? First column second row or second column first row? There is no "right" answer, thus there are programming languages using the one or the other. This is the major problem in your case. If you make an error here, the image looks like the one you got.

To fix the problem with row and column major, you have to use:

A1 = reshape(A, 512, 424).';

This swaps rows and columns to get a row-major behaviour, then transposes to turn the image right.