reflectance interpretation

22 views
Skip to first unread message

N Namazova

unread,
Nov 25, 2025, 7:53:04 AM (7 days ago) Nov 25
to mcx-users
hi, I have a very simple code to find the reflectance/transmittance from a water droplet in air. I have followed your instructions from old conversations and could map diffuse reflectance around the particle. My question is actually very basic :  in the map, we see the negative values of diffuse reflectance. how can i get reflectance as percentage ?
thanks in advance.


cfg.nphoton = 1e5;
dim = 50;
cfg.issrcfrom0 = 0; % first voxel is [111] (matlab)
cfg.vol = uint8(zeros(dim, dim, dim));
cfg.shapes = ['{"Shapes":[{"Sphere": {"Tag":1,' ...
' "O": [25,25,25], "R": 10}}]}'];
cfg.srctype = 'planar';
cfg.srcpos = [1, 1, 1];
cfg.srcparam1 = [dim-1, 1, 1, 0];
cfg.srcparam2 = [1, dim-1, 1, 0];
cfg.srcdir = [0 0 1];
cfg.prop = [0 0 1 1.0;
0.0000001 0.00001 0.9 1.5];
% cfg.detpos = [dim/2 dim/2 dim-1 dim/2
% dim/2 dim/2 2 dim/2];
cfg.gscatter = 1;
cfg.tstart = 0;
cfg.tend = 5e-9;
cfg.tstep = 5e-9;
cfg.outputtype = 'energy';
cfg.gpuid = 1;
cfg.autopilot = 1;
cfg.debuglevel = 'P';
cfg.issaveexit = 1;
cfg.issaveref = 1;
cfg.bc = 'mmmmmm';
[flux,detph] = mcxlab(cfg, 'smoothing', 1);
cwdref=sum(flux.dref,4);
figure(Position=[100 100 500 400])
imagesc(squeeze(log(cwdref(:,:,15))));title('diffuse reflectance, z=top of sphere');
colorbar

Qianqian Fang

unread,
Nov 25, 2025, 3:00:00 PM (7 days ago) Nov 25
to mcx-...@googlegroups.com, N Namazova

it is negative because you took a natural log, it does not mean the number is negative.

if you want to get percentage over total energy, you should set cfg.outputtype='energy' and sum the output flux.dref. this will be the fraction of the energy (out of 1 total launched energy) that exit from your domain.

but, since your medium has no absorption, with the all-mirror ('mmmmmm') boundary condition, nothing will be absorbed by your droplet, and your sum(flux.dref(:)) is 100%

--
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 view this discussion visit https://groups.google.com/d/msgid/mcx-users/2fd82ae6-4a78-4c73-9533-fc22ec100e34n%40googlegroups.com.

N Namazova

unread,
Nov 26, 2025, 4:17:23 AM (7 days ago) Nov 26
to mcx-users
thanks, i fixed the log thing and made some adjustments in the code. Now, it gives a proper reflectance value, however, i would like to make sure it is a correct approach to get the reflectance of the system.  My objective here is to compare the result to a result i obtain from ray tracing and eventually move on to an absorbing sponge system.

clear; clc; close all;
dimx = 50; dimy = dimx; dimz = dimx+2;
sphere_radius = 10;
cfg.vol = uint8(zeros(dimx, dimy, dimz)); % air background
sphere_center = [round(dimx/2), round(dimy/2), round(dimz/2)];
cfg.shapes = ['{"Shapes":[' ...
'{"Sphere":{"Tag":1,' ...
'"O":[' num2str(sphere_center(1)) ',' num2str(sphere_center(2)) ',' num2str(sphere_center(3)) '],' ...
'"R":' num2str(sphere_radius) '}}' ...
']}' ...
];
cfg.prop = [ ...
0 0 1.0 1.0; % medium 0: air background
0 1e-6 0.9 1.5]; % medium 1: sphere
cfg.issrcfrom0 = 0;
cfg.srctype = 'planar';
cfg.srcpos = [0 0 0];
cfg.srcparam1 = [dimx, 0, 0, 0];
cfg.srcparam2 = [0, dimy, 0, 0];
cfg.srcdir = [0 0 1];
cfg.nphoton = 1e6;
cfg.tstart = 0;
cfg.tstep = 5e-10;
cfg.tend = 5e-8;
cfg.outputtype = 'energy';
cfg.issaveref = 1;
cfg.bc = 'mmmmmm';
cfg.gpuid = 1;
cfg.autopilot = 1;
flux = mcxlab(cfg);
cwdref = sum(flux.dref, 4);
R = sum(cwdref(:,:,dimz/2+sphere_radius), 'all'); % sphere center + radius
fprintf('\nR_total = %.6f\n', R);

Qianqian Fang

unread,
Nov 28, 2025, 11:44:15 AM (4 days ago) Nov 28
to mcx-...@googlegroups.com, N Namazova

using a label-based medium in mcx is not really the right approach for simulating transparent/non-scattering domains.

this is because label-based medium uses voxels to represent object shapes. this voxelated boundary is ok when the medium is highly scattering, but it produces incorrect solutions when the medium is transparent - a voxelated boundary is a corner-reflector (https://en.wikipedia.org/wiki/Corner_reflector) which behaves entirely differently from a curved surface.


please read the Introduction section of our split-voxel MC (SVMC) paper

https://opg.optica.org/boe/fulltext.cfm?uri=boe-11-11-6262

as well as Fig. 3 of this paper

https://www.spiedigitallibrary.org/journals/journal-of-biomedical-optics/volume-25/issue-02/025001/Modeling-voxel-based-Monte-Carlo-light-transport-with-curved-and/10.1117/1.JBO.25.2.025001.full


if you want to use mcx, you should use the SVMC method, which requires you call mcxsvmc.m to preprocess the domain before you pass it to mcxlab. see example

https://github.com/fangq/mcx/blob/master/mcxlab/examples/demo_svmc_cubesph.m
https://github.com/fangq/mcx/blob/master/mcxlab/examples/demo_svmc_sphshells.m
https://github.com/fangq/mcx/blob/master/mcxlab/examples/demo_svmc_brain19_5.m

alternatively, you can also address this issue using mmc/mmclab.


On 11/26/25 04:17, N Namazova wrote:

You don't often get email from namazo...@gmail.com. Learn why this is important

Reply all
Reply to author
Forward
0 new messages