calculate sbr in vascular image stacks through binarization in javascript

To calculate the Signal-to-Background Ratio (SBR) in vascular image stacks through binarization, the following steps can be taken:

  1. Load the image stack in JavaScript using any suitable library such as cornerstone.js or papaya.

  2. Convert the image stack to grayscale to simplify calculations.

index.tsx
// Assume `stack` is the image stack
for(let i=0; i<stack.length; i++) {
  let grayscaleStack = stack[i].clone().greyscale();
}
128 chars
5 lines
  1. Threshold the grayscale image stack using any suitable binarization algorithm such as Otsu's method or triangle thresholding.
index.tsx
// Assume `threshold` is the threshold computed using any binarization algorithm
for(let i=0; i<grayscaleStack.length; i++) {
  let binaryStack = grayscaleStack[i].clone().threshold(threshold);
}
196 chars
5 lines
  1. Calculate the mean intensity value of the regions of interest (ROIs) defined by the binary image stack.
index.tsx
let roiSum = 0, roiCount = 0;
for(let i=0; i<binaryStack.length; i++) {
  let binaryImage = binaryStack[i];
  let roi = binaryImage.getRoi();
  roiCount += roi.count();
  roi.forEach((x, y) => {
    roiSum += grayscaleStack[i].getPixel(x, y);
  });
}
let roiMean = roiSum / roiCount;
284 chars
11 lines
  1. Calculate the mean intensity value of the background defined by the binary image stack.
index.tsx
let bgSum = 0, bgCount = 0;
for(let i=0; i<binaryStack.length; i++) {
  let binaryImage = binaryStack[i];
  let bg = binaryImage.getBg();
  bgCount += bg.count();
  bg.forEach((x, y) => {
    bgSum += grayscaleStack[i].getPixel(x, y);
  });
}
let bgMean = bgSum / bgCount;
273 chars
11 lines
  1. Calculate the SBR as the ratio of the mean intensity value of the ROIs to the mean intensity value of the background.
index.tsx
let sbr = roiMean / bgMean;
28 chars
2 lines

gistlibby LogSnag