Count of black pixels that were traced in image on the web

15

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

I have no idea which tool to use and where to start ... Does anyone have a path?

It's for web environment ...

    
asked by anonymous 08.06.2016 / 21:10

2 answers

1

Explanation

You can use php itself to do this, you do not have to use javascript if you do not want to, I did an example manipulating and creating a two-color image that I used for testing (black and white) and modeling it in html itself 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 was the image I used as an example to "biometria.png"

AndthiswastheresultoftheHTMLgeneratedbyPHP:

"Actual tests" in a biometric image:

Sample image:

InthistestIusedif($value<9000000){tocheckifit"is black or not"  with the intention of covering more shades of black and not only rgb(0,0,0)

Results:

Observations

ThevalueIusedof($value<9000000)wasjustfortesting,Idonotknowifthiswouldbea"plausible" value for identifying black tones.

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

    
21.12.2017 / 20:07
0

Taking the ImageColorPicker project as an example ( link ).

link line80

... .bind("mousemove", function(e){
   ...
      /*Aqui coloque sua lógica - (toda vez que q o pixel for da cor */
      /* que vc determinar incrementa um contador). */
   ...
});...
    
03.11.2016 / 23:11