Count of black pixels that have been plotted on the web image

Asked

Viewed 534 times

15

I want the user to trace a line in a biometric image and make an automatic count of "black parts" of the digital that this line crossed.

Exemplo

I have no idea which tool to use and where to start... Someone has some way?

It is for web environment...

  • 2

    If you do not know what technology to use, it is difficult to obey help here. From what you said, da para fazer isso usando canvas. Just sequentially scroll through all the pixels on the line and check when there is a total switch from white to black.

  • 4

    There are some approaches that may be useful, but that will depend on the image quality. My intuition says you should : 1) convert the image to grayscale (to avoid working with RGB); 2) apply a filter for edge extraction (has a simple algorithm in this my answer); 3) segment the region under the line (ignore all other image); 4) count the groupings of black pixels (like a region growth).

  • 2

    By the way, you have a [mcve] in Javascript that does the part of displaying the digital image (any, example) and allows you to trace the line in it? If you do, share it, which will make it much easier for someone to help you more directly/completely.

  • 1

    Another thing: this seems to be feasible in Javascript. Thus, you can show the result to the user without having to make requests to the server. I try this way before trying in PHP.

  • 1

    What do you want a biometric reading system? If it is, based on lines, it will never be necessary, because it can have repetition. The idea is not to draw lines but to map points at the points of the strokes and intersections of the drawing, where there is a black record. And then capture these points again.

  • Try to do something thereby. or thereby or thereby

  • Here has a book that can help you

  • More related with subject.

  • And if you convert the image to ASCII and find the pattern from there?

Show 6 more comments

2 answers

1

Explanation

You can use php itself to do this, you don’t need to use javascript if you don’t want, I made an example manipulating and creating an image of only two colors that I used for testing (black and white) and modelling it on html itself again with a scale of 10 pixels by 10 pixels.

Code

<style>
    .container {
        height: 10px;
        width: 100px;
    }
    .bloco {
        width: 10px;
        height: 10px;
        display: block;
        float: left;
    }
    .preto {
        background: black;
    }
    .branco {
        background: white;
    }
</style>
<?php
$image = imagecreatefrompng('biometria.png'); //aqui é o caminho da imagem
$IniX = 0;  //inicio largura
$FimX = 10; //dimensão de largura da imagem
$IniY = 0;  //inicio altura
$FimY = 10; //dimensão de altura da imagem
$codigoCorPreta = 0; //se for rgb(0,0,0) é zero. porém nem todo preto é realmente preto.
$pxPreto = 0; //qtd. de pixels pretos zerada inicialmente
for ($y = $IniY; $y < $FimY; $y++ ) {
    echo '<div class=container>'; //container para envolver cada linha horizontal
    for($x = $IniX; $x < $FimX; $x++ ) {
        $value = imagecolorat($image, $x, $y);
        if ($value === $codigoCorPreta){ 
        //se a cor no pixel atual for totalmente preta vai entrar aqui mas tbm poderia ser '($value < 9000000)' por exemplo para captar mais tons de preto.
            $cor = 'preto';
            $pxPreto++; //incrementa qtd de pixels pretos
        } else {
            $cor = 'branca';
        }
        echo "<div class='bloco {$cor}'></div>"; //cria uma div de 10x10 simulando 1 pixel com a cor branca ou preta.
    }
    echo '</div>';
}
echo "Total de pixels pretos: {$pxPreto}"; //aqui imprime a quantidade total de pixels pretos que foi percorrido.
?>

Results

This is the image I used as an example to "biometria.png" imagem que utilizei de exemplo

And this was the result obtained in HTML generated by PHP:

resultado do html gerado pelo php

"Real tests" on a biometric image:

Example image: fingerprint

In this test I used if ($value < 9000000){ to check if "black or not" in order to cover more shades of black and not only rgb(0,0,0)

Results:

resultado biometria

Remarks

The value I used ($value < 9000000) was only for testing, I can’t tell you if this would be a "plausible" value to identify black tones.

If the image you want to work on is jpg you must change the function imagecreatefrompng for imagecreatefromjpeg.

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.