All files / core/src/RenderingEngine/renderPasses sharpeningRenderPass.ts

0% Statements 0/9
0% Branches 0/2
0% Functions 0/1
0% Lines 0/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                         
import vtkConvolution2DPass from '@kitware/vtk.js/Rendering/OpenGL/Convolution2DPass';
import vtkForwardPass from '@kitware/vtk.js/Rendering/OpenGL/ForwardPass';
 
/**
 * Creates a GPU-based edge enhancement convolution pass for image sharpening.
 *
 * The edge enhancement works by detecting edges using a Laplacian kernel
 * and then subtracting a weighted version of these edges from the original image,
 * effectively enhancing the edges in the image.
 *
 * @param intensity - Sharpening intensity (0 = no sharpening, higher values = more sharpening)
 * @returns vtkConvolution2DPass configured for edge enhancement
 */
function createSharpeningRenderPass(intensity: number) {
  let renderPass = vtkForwardPass.newInstance();
 
  if (intensity > 0) {
    const convolutionPass = vtkConvolution2DPass.newInstance();
    convolutionPass.setDelegates([renderPass]);
    const k = Math.max(0, intensity);
 
    // Edge enhancement kernel type 2 (all 8 neighbors)
    // This kernel detects edges in all directions and enhances them
    // The center value (1 + 8*k) ensures the image brightness is maintained
    // while edges are enhanced proportionally to the intensity parameter
 
    convolutionPass.setKernelDimension(3);
    convolutionPass.setKernel([-k, -k, -k, -k, 1 + 8 * k, -k, -k, -k, -k]);
 
    renderPass = convolutionPass;
  }
 
  return renderPass;
}
 
export { createSharpeningRenderPass };