src/falseColorMapping.js
function convertImageToFalseColorImage (image, colormap) {
  if (image.color && !image.falseColor) {
    throw new Error('Color transforms are not implemented yet');
  }

  // User can pass a colormap id or a colormap object
  colormap = ensuresColormap(colormap);

  const colormapId = colormap.getId();

  // Doesn't do anything if colormapId hasn't changed
  if (image.colormapId === colormapId) {
    // It has already being converted into a false color image
    // Using the colormapId passed as parameter
    return false;
  }

  // Restore the image attributes updated when converting to a false color image
  restoreImage(image);

  // Convert the image to a false color image
  if (colormapId) {
    const minPixelValue = image.minPixelValue || 0;
    const maxPixelValue = image.maxPixelValue || 255;

    image.restore = getRestoreImageMethod(image);

    const lookupTable = colormap.createLookupTable();

    lookupTable.setTableRange(minPixelValue, maxPixelValue);

    // Update the pixel data and render the new image
    pixelDataToFalseColorData(image, lookupTable);

    // Update min and max pixel values
    const pixelValues = getPixelValues(image.getPixelData());

    image.minPixelValue = pixelValues.minPixelValue;
    image.maxPixelValue = pixelValues.maxPixelValue;

    image.windowWidth = 255;
    image.windowCenter = 128;

    // Cache the last colormapId used for performance
    // Then it doesn't need to be re-rendered on next
    // Time if the user hasn't updated it
    image.colormapId = colormapId;
  }

  // Return `true` to tell the caller that the image has got updated
  return true;
}
function convertImageToFalseColorImage (image, colormap) {
  if (image.color && !image.falseColor) {
    throw new Error('Color transforms are not implemented yet');
  }

  // User can pass a colormap id or a colormap object
  colormap = ensuresColormap(colormap);

  const colormapId = colormap.getId();

  // Doesn't do anything if colormapId hasn't changed
  if (image.colormapId === colormapId) {
    // It has already being converted into a false color image
    // Using the colormapId passed as parameter
    return false;
  }

  // Restore the image attributes updated when converting to a false color image
  restoreImage(image);

  // Convert the image to a false color image
  if (colormapId) {
    const minPixelValue = image.minPixelValue || 0;
    const maxPixelValue = image.maxPixelValue || 255;

    image.restore = getRestoreImageMethod(image);

    const lookupTable = colormap.createLookupTable();

    lookupTable.setTableRange(minPixelValue, maxPixelValue);

    // Update the pixel data and render the new image
    pixelDataToFalseColorData(image, lookupTable);

    // Update min and max pixel values
    const pixelValues = getPixelValues(image.getPixelData());

    image.minPixelValue = pixelValues.minPixelValue;
    image.maxPixelValue = pixelValues.maxPixelValue;

    image.windowWidth = 255;
    image.windowCenter = 128;

    // Cache the last colormapId used for performance
    // Then it doesn't need to be re-rendered on next
    // Time if the user hasn't updated it
    image.colormapId = colormapId;
  }

  // Return `true` to tell the caller that the image has got updated
  return true;
}
function convertImageToFalseColorImage ( image , colormap ) { if ( image . color && ! image . falseColor ) { throw new Error ( 'Color transforms are not implemented yet' ) ; } // User can pass a colormap id or a colormap object colormap = ensuresColormap ( colormap ) ; const colormapId = colormap . getId ( ) ; // Doesn't do anything if colormapId hasn't changed if ( image . colormapId === colormapId ) { // It has already being converted into a false color image // Using the colormapId passed as parameter return false ; } // Restore the image attributes updated when converting to a false color image restoreImage ( image ) ; // Convert the image to a false color image if ( colormapId ) { const minPixelValue = image . minPixelValue || 0 ; const maxPixelValue = image . maxPixelValue || 255 ; image . restore = getRestoreImageMethod ( image ) ; const lookupTable = colormap . createLookupTable ( ) ; lookupTable . setTableRange ( minPixelValue , maxPixelValue ) ; // Update the pixel data and render the new image pixelDataToFalseColorData ( image , lookupTable ) ; // Update min and max pixel values const pixelValues = getPixelValues ( image . getPixelData ( ) ) ; image . minPixelValue = pixelValues . minPixelValue ; image . maxPixelValue = pixelValues . maxPixelValue ; image . windowWidth = 255 ; image . windowCenter = 128 ; // Cache the last colormapId used for performance // Then it doesn't need to be re-rendered on next // Time if the user hasn't updated it image . colormapId = colormapId ; } // Return `true` to tell the caller that the image has got updated return true ; }
Convert an image to a false color image

@param {Image} image A Cornerstone Image Object
@param {String|Object} colormap - it can be a colormap object or a colormap id (string)

@returns {Boolean} - Whether or not the image has been converted to a false color image
Convert an image to a false color image