Print

Print


Hi Mahmoud,

I don't think it's available in the command line tools but if you have PALM
installed, the function palm_inormal.m should do the trick inside
Matlab/Octave. Something like this:

*% Min and max values desired for the output image (you can change these):*
*mi = 0; *
*ma = 4096;*

*% Number of the bins of the histogram (you can change this):*
*nbins = 128;*

*% Load the image to be equalised and a mask of the same size:*
*img = palm_miscread('image.nii',true);*
*msk = palm_miscread('mask.nii',true);*

*% Convert the mask to the type "logical" so that it can be used to index
elements.*
*% This will also replace the loaded struct for just the mask data:*
*msk = logical(msk.data);*

*% Select the masked voxels and make a vector:*
*imgvec = img.data(msk);*

*% Do a simple image quantisation:*
*imgquant = floor((imgvec - min(imgvec))/max(imgvec) * nbins);*

*% Do an inverse-normal transformation:*
*z = palm_inormal(imgquant);*

*% Convert to normal quantiles (i.e., these will be in the range [0 1]).*
*% This is already the image equalised, but still in the wrong range.*
*q = erfc(-z/sqrt(2))/2;*

*% Put the quantiles to the desired range:*
*imgeq = q*(ma-mi) + mi;*

*% Save the result:*
*img.filename = 'image_equalised.nii';*
*img.data(mask) = imgeq;*

*palm_miscwrite(img);*


It's possible to get rid of the dependence on nbins by skipping the
quantisation step. Regardless of which route is taken, the only reason why
one would want to do this is to improve contrast for visualisation. This
process will introduce undesired statistical dependencies among distant
voxels, will introduce non-linearities in effect sizes, and will cause loss
of information through the quantisation step.

I haven't tested the code above -- use at your own risk. Nonetheless, hope
this helps.

All the best,

Anderson


On 12 October 2016 at 19:54, Mahmoud <[log in to unmask]> wrote:

> Hi all,
>
> Is there any function in FSL that performs the histogram equalization?
>
> Thank you!
> Mahmoud
>