javascriptnode.jsimage-processingsharpconnected-components

How to detect the number of disconnected regions in a PNG using Javascript?


How to detect that there are (for example) 3 disconnected regions within the PNG below? Is there a technique or library someone could kindly refer me to? Not sure how to even start with this one. I'm thinking maybe there exists a function in an image processing library that will decompose a PNG into an array of buffers for each image region detected.

Thanks!

PNG with disconnected regions


Solution

  • This tutorial seems to do what you need, but in Python:

    https://www.geeksforgeeks.org/how-to-detect-shapes-in-images-in-python-using-opencv/

    You can try to copy the code and parts of the logic from that Python code and use this question (and answer) as a foundation:

    How to access data from findContours() in opencv js

    Here is another SO question that can be helpful in how to work with contours:

    mask after finding shape's contour

    However, this approach assumes you are running Node JS, not a browser JS.

    Please let me know if this helps.

    UPDATE:

    I had some spare time and thought trying the approach I suggested in my answer would be nice.

    Here we go - a non-optimized implementation of the algorithm that searches for shapes by filling them with different colors.

    Comment out the line await delay(1); to see it running at full-speed without animation.

    <html>
    
    <head>
      <style>
    
      </style>
    </head>
    
    <body>
      <canvas width="800" height="600"></canvas>
      <script>
        const canvas = document.querySelector('canvas');
        const ctx = canvas.getContext('2d');
    
        const delay = (msec) => {
          return new Promise((resolve) => {
            setTimeout(resolve, msec);
          });
        };
    
        const getPixel = (x, y) => {
          const pixel = ctx.getImageData(x, y, 1, 1);
          return [pixel.data[0], pixel.data[1], pixel.data[2], pixel.data[3]];
        }
    
        const setPixel = (x, y, rgba) => {
          const pixel = ctx.getImageData(x, y, 1, 1);
          pixel.data[0] = rgba[0];
          pixel.data[1] = rgba[1];
          pixel.data[2] = rgba[2];
          ctx.putImageData(pixel, x, y);
        }
    
        const fillShape = async(shape) => {
          while (pos = shape.queue.pop()) {
            let pixel = getPixel(pos.x, pos.y);
            if (!isBackground(pixel) && !isScanned(pixel)) {
              setPixel(pos.x, pos.y, [255, 0, 0]);
    
              if (pos.x < shape.bounds.x1) {
                shape.bounds.x1 = pos.x;
              }
              if (pos.x > shape.bounds.x2) {
                shape.bounds.x2 = pos.x;
              }
              if (pos.y < shape.bounds.y1) {
                shape.bounds.y1 = pos.y;
              }
              if (pos.y > shape.bounds.y2) {
                shape.bounds.y2 = pos.y;
              }
    
              if (pos.x - 1 >= 0) {
                shape.queue.push({
                  x: pos.x - 1,
                  y: pos.y
                });
              }
              if (pos.x + 1 < img.width) {
                shape.queue.push({
                  x: pos.x + 1,
                  y: pos.y
                });
              }
              if (pos.y - 1 >= 0) {
                shape.queue.push({
                  x: pos.x,
                  y: pos.y - 1
                });
              }
              if (pos.y + 1 < img.height) {
                shape.queue.push({
                  x: pos.x,
                  y: pos.y + 1
                });
              }
    
              await delay(1);
            }
          }
        };
    
        const isBackground = (pixel) => {
          return pixel[0] === 255 && pixel[1] === 255 && pixel[1] === 255;
        }
    
        const isScanned = (pixel) => {
          return pixel[0] === 255 && pixel[1] === 0 && pixel[2] === 0;
        }
    
        const detectShapes = async() => {
          const shapes = [];
          for (let y = 0; y < img.height; y++) {
            for (let x = 0; x < img.width; x++) {
              const pixel = getPixel(x, y);
              if (!isBackground(pixel) && !isScanned(pixel)) {
                const shape = {
                  bounds: {
                    x1: 999999,
                    y1: 999999,
                    x2: -1,
                    y2: -1,
                  },
                  queue: [],
                };
                shape.queue.push({
                  x,
                  y
                });
                await fillShape(shape);
                shapes.push(shape);
              }
            }
          }
          return shapes;
        };
    
        const img = new Image();
        img.crossOrigin = "Anonymous";
        //img.src = "shapes.png";
        img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAADuCAYAAAAHrN1QAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAPHRFWHRDb21tZW50AHhyOmQ6REFHQlU0Nk95aG86MTIsajo2NTUzMTYxNjQ5NDg0NDI5MDYzLHQ6MjQwNDA4MDR2VTdVAAAFBmlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSdhZG9iZTpuczptZXRhLyc+CiAgICAgICAgPHJkZjpSREYgeG1sbnM6cmRmPSdodHRwOi8vd3d3LnczLm9yZy8xOTk5L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HWzvzsZS0NBUKAEVpLvdvZcp3lbmkoEAKM0Ppa20BRdn7z/bu5WxqWiwAjlIq9duaHtTQUAgFGKJVi7cwPa2lYLgKM0Cnl2pkf1tKwHAQYoVPKtTM/rKVhOQgwQsXE2pkf1tKwVAQYoWFq7cwPa2lYKgKM0DC5duaHtTQsBQFGKJheO/PDWhqWggAjFIKwdubn8Z4RHRqaMD0GQoQAI/CCtHbm59Yj3aylIW8EGIEXpLUzP6ylYTEIMAItiGtnfvaeOKvJbLBPlyAYCDACayqb053He02PsWispSFfBBiB9bW2AbWFdLXrK8/1s5YGXwQYgRT0tTM/rKUhHwQYgfR3J4O/duaHtTT4IcAInDCtnflhLQ0LIcAInDuO9SprSbNYS8NCCDACJYxrZ35YS8N8CDACI6xrZ35YS8N8CDACI8xrZ35YS8NcCDACIexrZ35YS8NcCDACwYa1Mz+spWE2AgzjbFo78/Opo6yl4UUEGMbZtHbm5+cjrKXhRQQYRtm4duaHtTRMI8Awxta1Mz9npzL6ssUfOCJ/BBjG2Lx25uee06ylgQDDENvXzvywlgaJAMMQF9bO/LCWBgKMknNp7cwPa2luI8AoOZfWzvywluY2AoyScnHtzA9rae4iwCiZVM5zcu3MD2tp7op4HiegUBqj6awOD/Oh01zi0YiuWV1tegyUGAEGAEM4BQEAhhBgADCEAAOAIQQYAAwhwABgCAEGAEMIMAAYQoABwBACDACGEGAAMIQAA4AhBBgADCHAAGAIAQYAQwgwABhCgAHAEAIMAIYQYAAwhAADgCEEGAAMIcAAYAgBBgBDCDAAGEKAAcAQAgwAhhBgADCEAAOAIQQYAAwhwABgyP8BV6makU/LD00AAAAASUVORK5CYII=";
        img.addEventListener('load', async() => {
          console.log(img.width, img.height);
          canvas.width = img.width;
          canvas.height = img.height;
          ctx.drawImage(img, 0, 0);
    
          const shapes = await detectShapes();
          shapes.forEach((shape) => {
            ctx.beginPath();
            ctx.rect(shape.bounds.x1, shape.bounds.y1, shape.bounds.x2 - shape.bounds.x1, shape.bounds.y2 - shape.bounds.y1);
            ctx.stroke();
          });
        });
      </script>
    </body>
    
    </html>