Error using mcxlab and vol.bin files

217 views
Skip to first unread message

Kris Dreher

unread,
May 21, 2019, 9:24:11 AM5/21/19
to mcx-users
Dear Dr. Fang,

I got an error in mcxlab using the json2mcx.m script to convert a json-file and the corresponding vol.bin file to a cfg. The json-file and the vol.bin-file were created by the mcx2json.m script.

The error says:

Error using reshape
To RESHAPE the number of elements must not change.

Error in loadmc2 (line 36)
data=reshape(data,dim);

Error in json2mcx (line 80)
            cfg.vol=loadmc2(json.Domain.VolumeFile,json.Domain.Dim,'uchar=>int32');

I think this was because of the 'uchar=>int32' in json2mcx (line 80).

So I changed the format to 'float32' and I got a cfg that made sense, but the cfg.vol was a 4D double instead of a 4D single.
Can you help me with that?

Also, could you make a command line example where the VolumeFile in the json-file is a .nii file instead of a vol.bin-file?
I'm aiming towards using mcx with .nii volume files with the command line and right now I'm just using the mcxlab scripts trying to understand how I can get there.

Best,
Kris Dreher

Kris Dreher

unread,
May 22, 2019, 10:07:57 AM5/22/19
to mcx-users
By manually changing the cfg.vol from a 4D double to a 4D single, mcxlab.m runs without a problem.
However, if I run mcx via command line with the same .json file as input and the same corresponding vol.bin file, mcx returns the error:
MCX ERROR(-6):medium index exceeds the specified medium types in unit mcx_utils.c:1473
I think, that this could be related to the error in my previous question. 
Could it be, that the vol.bin files aren't read correctly in both mcxlab and mcx via command line?
I'm sorry, bothering you with that, but if they are read correctly, I don't know what I'm doing wrong. 

Qianqian Fang

unread,
May 22, 2019, 11:19:46 AM5/22/19
to mcx-...@googlegroups.com, Kris Dreher

hi Kris

did you use mcxlab or mcx?

mcxlab has the capability to receive char/short/int/float/double/float2/float4/short2/char4 arrays as volume input, and will detect/convert automatically.

https://github.com/fangq/mcx/blob/72afd6a0bebcca6a83735aa215d07125f1c5bee1/mcxlab/README.txt#L97-L111

mcx, however, by default only reads char (byte) based volume masks. if you have a different input format, you must tell mcx the format of the volume file using the -K parameter (this feature only available in v2019.4)

https://github.com/fangq/mcx/blob/master/README.txt#L249-L257

double is not supported by mcx binary.

Also, in both cases, float based volume inputs have different meanings than the integer-based volumes - the integers inputs define volume label, but the float volume defines the mua (and mus) value per voxel.

Qianqian


--
You received this message because you are subscribed to the Google Groups "mcx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mcx-users+...@googlegroups.com.
To post to this group, send email to mcx-...@googlegroups.com.
Visit this group at https://groups.google.com/group/mcx-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/mcx-users/9fd9d8c6-3f16-4099-a731-51fb16528fb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Message has been deleted

Kris Dreher

unread,
May 22, 2019, 11:49:45 AM5/22/19
to mcx-users
I use both mcxlab and mcx.

Using mcxlab, I used the mcx2json.m script to convert the cfg that is defined in demo_continuous_mua_mus.m (Approach #2) to a json file with its corresponding volume binary.
However, the json2mcx.m script couldn't convert it back to a cfg that didn't raise an error. That is why I changed the format to 'float32'.
Doing this, mcxlab worked properly and mua as well as mus were displayed correctly.

Using mcx (v2019.4), I wanted to use the json file (converted from demo_continuous_mua_mus.m (Approach #2) by mcx2json.m) to run the simulation via command line. Although I tried all possible values for the -K parameter, I always got the error: MCX ERROR(-6):medium index exceeds the specified medium types in unit mcx_utils.c:1473

Best,
Kris

Qianqian Fang

unread,
May 22, 2019, 2:23:35 PM5/22/19
to mcx-...@googlegroups.com, Kris Dreher
On 5/22/19 11:49 AM, Kris Dreher wrote:
I use both mcxlab and mcx.

Using mcxlab, I used the mcx2json.m script to convert the cfg that is defined in demo_continuous_mua_mus.m (Approach #2) to a json file with its corresponding volume binary.
However, the json2mcx.m script couldn't convert it back to a cfg that didn't raise an error. That is why I changed the format to 'float32'.
Doing this, mcxlab worked properly and mua as well as mus were displayed correctly.

hi Kris

I am sorry for the confusions. The support for continuous media, as well as json2mcx, was added recently, and I haven't go through all codes to make sure such data structure is compatible with other existing features.

Using mcx (v2019.4), I wanted to use the json file (converted from demo_continuous_mua_mus.m (Approach #2) by mcx2json.m) to run the simulation via command line. Although I tried all possible values for the -K parameter, I always got the error: MCX ERROR(-6):medium index exceeds the specified medium types in unit mcx_utils.c:1473


I will look into this. it might be the best approach for now to modify from existing working examples, and do not convert from one to another. but thanks for reporting these issues, and hopefully I will fix those in the next release.

if you can write a simple script for me to reproduce the issue, please file a bug at

https://github.com/fangq/mcx/issues

thanks

Qianqian



Best,
Kris
--
You received this message because you are subscribed to the Google Groups "mcx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mcx-users+...@googlegroups.com.
To post to this group, send email to mcx-...@googlegroups.com.
Visit this group at https://groups.google.com/group/mcx-users.

Kris Dreher

unread,
May 23, 2019, 8:45:40 AM5/23/19
to mcx-users
Hi Qianqian,

I attached some scripts to reproduce the errors and one matlab script with a suggested solution.
In the Github issue, that I opened, I described how these scripts should be used.
json2mcx_modified.m
test.sh
test_script.m

Qianqian Fang

unread,
May 23, 2019, 1:16:43 PM5/23/19
to mcx-...@googlegroups.com, Kris Dreher

hi Kris

thanks for the test scripts, very helpful.

I managed to fix this issue with this commit made a moment ago

https://github.com/fangq/mcx/commit/e1b50b6bbe199026468d45e81a73fb0340045dc1

it modified 3 files:

  • in mcx2json.m to save the mcxlab vol and encode its format in Domain.MediaFormat (which is already supported by mcx binary)
  • in json2mcx.m to read the Domain.MediaFormat key and set cfg.vol format for mcxlab, and
  • in mcx_utils.c to allow mcx binary to correctly read a 2*Nx*Ny*Nz float32 volume as muamus_float (100); this is the only media format that was not previously supported in the mcx binary

I tested both mcxlab and mcx binary using the two converted inputs, and both gave me correct results (~30.4% absorption fraction).

I also recompiled mcx/mcxlab nightly build with this new addition. Please go ahead and try it. If there is any further issue, please reopen this issue

https://github.com/fangq/mcx/issues/67

Qianqian


--
You received this message because you are subscribed to the Google Groups "mcx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mcx-users+...@googlegroups.com.
To post to this group, send email to mcx-...@googlegroups.com.
Visit this group at https://groups.google.com/group/mcx-users.

Kris Dreher

unread,
May 24, 2019, 7:46:01 AM5/24/19
to mcx-users
Hi Qianqian,

thank you very much! Everything works fine now :)

Best,
Kris

Kris Dreher

unread,
May 24, 2019, 8:44:36 AM5/24/19
to mcx-users
Is there a possibility planned in future releases for 4*Nx*Ny*Nz float32 mua/mus/g/n array format?

Qianqian Fang

unread,
May 24, 2019, 10:50:19 AM5/24/19
to mcx-...@googlegroups.com, Kris Dreher
On 5/24/19 8:44 AM, Kris Dreher wrote:
Is there a possibility planned in future releases for 4*Nx*Ny*Nz float32 mua/mus/g/n array format?


it can be done, but will involve more code changes, and likely reduced GPU efficiency.

currently, all the volume data are stored in an int32 3D array - char/short label inputs are casted to int, and float2 (mua/mus) are converted to half-precision (fp16) and stored in a single integer (32bit).

if one wants to store mua/mus/g/n per voxel, packing to fp16 or not, it will require a larger sized array. that means more global memory reading and processing.

an alternative is to use the currently supported -K asgn_byte (or -K 103) for encoding all 4 optical parameters. It uses a gray-scale level (0-255 for mua/mus/g and 0-127 for n) to interpolate between cfg.prop(2,:) and cfg.prop(3,:).

For example, if one have cfg.prop=[0,0,1,1; 0.05, 1, 0.9, 1.1; 0.01, 10, 0.8, 1.5] and a 4xNx*Ny*Nz uint8 array as cfg.vol, with the first voxel containing [0, 128, 255, 64], mcx will compute the optical properties via interpolation:

mua[1,1,1]=0.05
mus[1,1,1]=(1+10)/2=5.5
g[1,1,1]=0.8
n[1,1,1]=(1.1+1.5)/2=1.3

for forward purposes, I think such method should provide sufficient accuracy (relative to the stochastic errors of MC), but I have never tested this.

Qianqian


--
You received this message because you are subscribed to the Google Groups "mcx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mcx-users+...@googlegroups.com.
To post to this group, send email to mcx-...@googlegroups.com.
Visit this group at https://groups.google.com/group/mcx-users.

Kris Dreher

unread,
May 29, 2019, 10:34:18 AM5/29/19
to mcx-users
Hi Qianqian,

I wrote some tests for the simulation, which basically just test the Beer-Lambert law. And I think if mcx uses a binary volume file, there are still some errors:

First, I think the scattering defined in the volume file is not used.
Secondly, I think that the spacing, i.e. the length of one voxel in unit mm, is not accounted for, as well.

I wrote a Python script, which should reproduce and illustrate the errors. 

I'll also open an issue on  github.
Thank you very much :)

Best,
Kris 
mua_and_mus_test.py

Qianqian Fang

unread,
May 29, 2019, 1:49:51 PM5/29/19
to mcx-...@googlegroups.com, Kris Dreher

thanks, see my reply on github

https://github.com/fangq/mcx/issues/71


Thank you very much :)

Best,
Kris 
--
You received this message because you are subscribed to the Google Groups "mcx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mcx-users+...@googlegroups.com.
To post to this group, send email to mcx-...@googlegroups.com.
Visit this group at https://groups.google.com/group/mcx-users.
Reply all
Reply to author
Forward
0 new messages