rii-mango / NIFTI-Reader-JS

A JavaScript NIfTI file format reader.
MIT License
136 stars 25 forks source link

Normalizing the data to 0-255 #10

Closed hockeyob closed 3 years ago

hockeyob commented 3 years ago

How do I normalize data in the typedData array? Where can I find the min and max values in the header? Math.min.apply(typedData) returns infinity and any math I try to do in the for loops takes a long time to calculate, slowing the progress. My typed data is a float32array if it matters

Thank you for any help you give! I will provide any additional info if you need

xgui3783 commented 3 years ago

haven't tried the code, but according to the code and the spec, the below should read

var data = // an ArrayBuffer
var niftiHeader = null,
    niftiImage = null,
    niftiExt = null;

if (nifti.isCompressed(data)) {
    data = nifti.decompress(data);
}

if (nifti.isNIFTI(data)) {
    niftiHeader = nifti.readHeader(data);
    console.log(niftiHeader.cal_min, niftiHeader.cal_max)
}

spec relevant code snippit for nifti 1 relevant code snippit for nifti 2

hockeyob commented 3 years ago

Hi xgui, cal_min and cal_max are both zero for all of my nii files

xgui3783 commented 3 years ago

Were they set in the nii file to begin with? If not, you might have to do a for loop to find min and max.

On Tue, 4 May 2021, 17:23 hockeyob, @.***> wrote:

Hi xgui, cal_min and cal_max are both zero for all of my nii files

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rii-mango/NIFTI-Reader-JS/issues/10#issuecomment-832027700, or unsubscribe https://github.com/notifications/unsubscribe-auth/AET34F7PXARYORXGHTRYDHLTMAGOZANCNFSM44BAODHA .