rii-mango / Daikon

A JavaScript DICOM reader.
Other
222 stars 55 forks source link

`Image.getInterpolatedData()` returns blank image data #14

Closed DLiblik closed 6 years ago

DLiblik commented 6 years ago

When processing images where the getDataType() method returns values other than daikon.Image.BYTE_TYPE_INTEGER and daikon.Image.BYTE_TYPE_INTEGER_UNSIGNED, the getInterpolatedData() method returns all-zero data, due to this block of code in the pixel-processing loop:

    for (ctr = 0; ctr < numElements; ctr += 1) {
// Value only assigned if datatype has one of two values, but it often has others
        if (datatype === daikon.Image.BYTE_TYPE_INTEGER) {
            if (numBytes === 1) {
                rawValue = dataView.getInt8(ctr * numBytes);
            } else if (numBytes === 2) {
                rawValue = dataView.getInt16(ctr * numBytes, littleEndian);
            }
        } else if (datatype === daikon.Image.BYTE_TYPE_INTEGER_UNSIGNED) {
            if (numBytes === 1) {
                rawValue = dataView.getUint8(ctr * numBytes);
            } else if (numBytes === 2) {
                rawValue = dataView.getUint16(ctr * numBytes, littleEndian);
            }
        }

// ** At this point, value can be unassigned (==0) if neither of above forks taken
        value = ((rawValue & mask) * slope) + intercept;
        data[ctr] = value;

// ... rest of loop

Solution is to limit datatype to only the standard values - I created PR #13 to address this.

rii-mango commented 6 years ago

Merged the PR. Thanks!