How auto W/L is implemented in 3DSlicer?

Operating system: Windows
Slicer version: 4.8.1
Expected behavior:NO
Actual behavior:NO
How auto W/L is implemented in 3DSlicer?
I’m fanscinated with the auto W/L module in 3DSlicer,which satisfies my requirement for visualizing MR volume.But I want to use this functionality for batch processing,so I want to know the exact algorithm.
I want know whether this functionality can be implemented using ITK apis.
Programmatic advice is welcome.
Thank you :grinning::grinning:

We define window/level based on the image histogram (using vtkImageHistogramStatistics):

I’m really curious what do you mean by this :slight_smile: Because W/L is a strictly visualization feature that has no persistent effect on the data, but batch processing typically changes the data. Can you please shed some light on it for us?

Oh,Sorry about my unclear statement,I want to convert the MRI volumes to PNG images,while maximally maintaining the MRI image’s detatils.Luckily, auto W/L module in 3DSlicer just satisfies my very requirement.But I know this W/L visualization feature has no persistent effect on the data,so I try to write a program to process these MRI data based on the auto W/L algorithm.
Thank you for your kind reply, @Iassoan has solved my problem.
Thank you both very much~~

Thank you for your kind reply,
I will try this algorithm.
Thank you~~

I would be very cautious about scaling medical imaging data to PNG. While PNG can support 16-bit grayscale, most implementations only support 8-bit (e.g. 256 shades of gray). While that may be sufficient with many machine learning algorithms (e.g. facial recognition of photographs) I would be very wary of using 8-bits to represent medical imaging data. Since you mention MR scans, in fMRI scans a 1% signal change is huge. Most of the brightness comes from constant properties (e.g. amount of water in the voxel), and we are seeking a very small but reliable change in signal. You really want to be careful to preserve the precision of your data. As a minimum, you might want to consider first doing your desired low/high pass filter, then subtracting each image from the mean, and looking at scaling these residual values from 0…255.

Thank you for your advice,I’m reconsidering my problems.