Issue to get CT value of a CT image

Describe Your Question

I downloaded the latest cornerstone3D lib from Github and revised the “local” example by adding codes to get the CT value of a pixel where the mouse points to. For some CT images, the CT values returned are always NaN. For others, values are correct.

What steps can we follow to reproduce the bug?

  1. I added the below codes to get the CT value of a pixel with “local” example by referring to how “multiVolumeCanvasToWorld” example gets the CT value;
  2. I selected a few CT images of the same series - for some images, the script only returns NaN for wherever position of the mouse over the image; for others, the script shows the correct CT value;
  3. I traced to “const index = imageData.worldToIndex(worldPos);” and find index[2] returned is -1.776356839400251e-15, and then it fails at indexWithinDimensions(): index[2]<0. So I changed the below line to make index[2]=0, and it works well to return the correct CT value: index[2] = Math.floor(index[2]); => change to index[2] = Math.round(index[2])

My help needed is - did I write the codes incorrectly here, or is there an issue with the imageData.worldToIndex()? I traced into worldToIndex() and guess it may be related to the value of model.worldToIndex Array.
I also trie to use getScalarValueFromWorld() instead of the below getValue(), but it performs the same way as getValue(). I traced into getScalarValueFromWorld() and it also calls imageData.worldToIndex().

// I added below codes in the index.ts at /packages/tools/examples/local by referring to index.ts of /packages/core/examples/multiVolumeCanvasToWorld:

const ctValue = document.createElement('p');
const content = document.getElementById('content');

function getValue(worldPos) {
  let dimensions = viewport.getImageData().dimensions;
  let scalarData = viewport.getImageData().scalarData;
  let imageData = viewport.getImageData().imageData;
  const index = imageData.worldToIndex(worldPos);
  index[0] = Math.floor(index[0]);
  index[1] = Math.floor(index[1]);
  index[2] = Math.floor(index[2]);  // change to Math.round(index[2])
  if (!csUtils.indexWithinDimensions(index, dimensions)) {
  const yMultiple = dimensions[0];
  const value = scalarData[index[1] * yMultiple + index[0]];
  return value;

element.addEventListener('mousemove', (evt) => {
  const rect = element.getBoundingClientRect();
  const canvasPos: Types.Point2 = [
    Math.floor(evt.clientX - rect.left),
    Math.floor(evt.clientY -,
  const worldPos = viewport.canvasToWorld(canvasPos);
  ctValue.innerText = `CT value: ${getValue(worldPos)}`;