Dear All,
I have the pointclass3.lmf file as attached. But I dont know how to open it. In manual just said like below:
"This routine saves information about the photon history in a binary list mode file. The file will have the extension *.lmf. To save disk space, each record of a history in the binary file will have nine 16-bit integer values, one 64-bit float value, and one 8-bit value in the order indicated in the table. "
Anyone can hel me?

8 Comments

DGM
DGM on 23 Nov 2024
Edited: DGM on 23 Nov 2024
I have no idea what the file is, but maybe this is a start.
% i'm assuming byte order and signedness of integer classes
% is there a header? file length is not integer-divisible by described record length
% i'm assuming that the data is not compressed, and that the there is nothing trailing the data
% that assumption leaves _at least_ 16B that can't be data.
fid = fopen('pointclass3.lmf');
stream = fread(fid,inf,'*uint8');
fclose(fid);
recordlen = 18 + 8 + 1; % 9x16b, 1x64b, 1x8b
headerlen = mod(numel(stream),recordlen); % is there a header??
header = stream(1:headerlen);
data = reshape(stream(headerlen+1:end),recordlen,[]);
% the 16b fields
fields1 = typecast(reshape(data(1:18,:),[],1),'uint16');
fields1 = reshape(fields1,9,[]).';
% the double float field
fields2 = typecast(reshape(data(19:26,:),[],1),'double');
% the 8b field (the recasting here is redundant, but i'm just being explicit)
fields3 = typecast(reshape(data(23,:),[],1),'uint8');
In the case of blindly decoding physical images, there's often some discernable structure that tells us if we're decoding things grossly wrong. With tabular data, we don't really get the same insight. The results can be completely wrong, and I would have no idea.
EDIT: My blind suggestion is probably garbage. This is probably closer, since you seem to be doing a lot of medical image stuff.
That suggests though, that each LMF file should have a text file which describes its structure -- something like a header file. This is at odds with my assumption that the LMF file itself apparently must have had a header due to its length.
Can you share the table the quoted text refers to?
mohd akmal masud
mohd akmal masud on 23 Nov 2024
Edited: Walter Roberson on 23 Nov 2024
I think there is file image produced together. You can get the file image as link here: https://drive.google.com/drive/folders/18f_e3KljFuebeQHH6KRVXHbCyRx_0Moq?usp=sharing .
pointlmf.a00 = the image file
pointlmf.h00 = the header file image
pointlmf.lmf = saves information about the photon history in a binary list mode file.
Actually the lmf file accordingly to manual is saves information about the photon history in a binary list mode file. The manual just said like below:
DGM
DGM on 23 Nov 2024
Edited: DGM on 23 Nov 2024
Yee. Well, as much as that looks helpful, I'm not able to download 1.3GB in a reasonable timeframe.
The screenshot does, however tell us that there's an extra field. With that information, the file does appear to have an integer number of records.
fid = fopen('pointclass3.lmf');
stream = fread(fid,inf,'*uint8');
fclose(fid);
recordlen = 20 + 8 + 1; % 10x16b, 1x64b, 1x8b
headerlen = mod(numel(stream),recordlen) % is there a header??
header = stream(1:headerlen);
data = reshape(stream(headerlen+1:end),recordlen,[]);
% the 16b fields
xyz0 = typecast(reshape(data(1:6,:),[],1),'uint16');
xyz0 = reshape(xyz0,3,[]).';
xyzphantom = typecast(reshape(data(7:12,:),[],1),'uint16');
xyzphantom = reshape(xyzphantom,3,[]).';
xyzcrystal = typecast(reshape(data(13:18,:),[],1),'uint16');
xyzcrystal = reshape(xyzcrystal,3,[]).';
energy = typecast(reshape(data(19:20,:),[],1),'uint16');
% the double float field
photonweight = typecast(reshape(data(21:28,:),[],1),'double');
% the 8b field
scatterorder = typecast(reshape(data(29,:),[],1),'uint8');
Dear @DGM
I was try your syntax. All is well.
But the value in workspace I dont know what is it actually?
Is it is images? is it is data? is it is graph profile?
Can you help me how to view all that valu workspace?
Dear @DGM,
headerlen = mod(numel(stream),recordlen) % is there a header??
The header files is attached.

Sign in to comment.

 Accepted Answer

Harsh
Harsh on 24 Nov 2024
Hi Akmal,
You can use “fread” function to read a binary file in MATLAB. Below is the code to read data in the format mentioned by you.
% Open the file in binary read mode
fileID = fopen('pointclass3.lmf', 'rb');
numRecords = 10; % As an example we read 10 records
% Preallocate arrays to store data
int16Data = zeros(numRecords, 9, 'int16'); % 9 int16 values per record
float64Data = zeros(numRecords, 1, 'double'); % 1 float64 value per record
int8Data = zeros(numRecords, 1, 'int8'); % 1 int8 value per record
% Loop to read each record
for i = 1:numRecords
int16Data(i, :) = fread(fileID, 9, 'int16'); % Read 9 int16 values
float64Data(i) = fread(fileID, 1, 'double'); % Read 1 float64 value
int8Data(i) = fread(fileID, 1, 'int8'); % Read 1 int8 value
end
% Close the file
fclose(fileID);
% Display the first record as an example
disp('First Record:');
disp('Int16 Data:');
disp(int16Data(1, :));
disp('Float64 Data:');
disp(float64Data(1));
disp('Int8 Data:');
disp(int8Data(1));
Here’s the output for the above code-
You may refer to the following documentation to learn more about “fread” function - https://www.mathworks.com/help/matlab/ref/fread.html

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Release

R2023b

Asked:

on 22 Nov 2024

Answered:

on 24 Nov 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!