Binarisation d'une image avec php
Bonsoir ici,moi c'est Kevin
Je viens de me lancer dans la binarisation d'image. Et d'ailleirs je dois binariser une image mais le j'ai beau ecrire le code l'image n'est pas binariser. Voici mon code, s'il vous plait verifier le et dite moi ou ca bloque
Code:
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 38 39 40 41 42
|
<?php
$image = imagecreatefromjpeg('empreinte.jpg');
$width = imagesx($image);
$heigth = imagesy($image);
$imgFinal = imagecreatetruecolor($width, $heigth);
for ($y=0; $y <$heigth ; $y++) {
for ($x=0; $x <$width ; $x++) {
$pixel = imagecolorat($imgFinal, $x, $y);
$red = ($pixel>>16)&0xFF;
$green = ($pixel>>8)&0xFF;
$bleu = $pixel&0xFF;
$NG = (($red*0.299)+($green*0.587)+($bleu*0.114));
$black = imagecolorallocate($imgFinal, 255, 255, 255); // Couleur noir
$white = imagecolorallocate($imgFinal, 0, 0, 0); // couleur blanche
if ($NG >= 170 ) { // si le seuil depasse
imagesetpixel($imgFinal, $x, $y, $black); // on change la couleur du pixel en noir
}
else
{
imagesetpixel($imgFinal, $x, $y, $white); // on change la couelur du pixel en balnc
}
}
}
?> |
Merci d'avance pour vos differentes reaction
Probleme resolu avec succes
Bonjour je viens de par ce message vous dire que j'ai triuver solution a mon probleme, j'ai rectifier ce qu'il fallait faire et le probleme etait sur le chemin de sorti de l'image resultante que j'ai parfaitement resctifier et tout va pour le mieux. Voic le code resultant
Code:
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 38 39 40 41 42 43 44 45
|
<?php
$image = imagecreatefromjpeg('tata.jpeg');
$width = imagesx($image);
$heigth = imagesy($image);
$imgFinal = imagecreatetruecolor($width, $heigth);
for ($y=0; $y <$heigth ; $y++) {
for ($x=0; $x <$width ; $x++) {
$pixel = imagecolorat($image, $x, $y);
$red = ($pixel>>16)&0xFF;
$green = ($pixel>>8)&0xFF;
$bleu = $pixel&0xFF;
$NG = ($red*0.299 + $green*0.587 + $bleu*0.114);
$black = imagecolorallocate($imgFinal, 0, 0, 0); // Couleur noir
$white = imagecolorallocate($imgFinal, 255, 255, 255); // couleur blanche
if ($NG >= 170 ) { // si le seuil depasse
imagesetpixel($imgFinal, $x, $y, $white); // on change la couleur du pixel en noir
}
else
{
imagesetpixel($imgFinal, $x, $y, $black); // on change la couelur du pixel en balnc
}
}
}
imagejpeg($imgFinal,'Image1/resultat2.jpeg');
imagedestroy($imgFinal);
?> |
Merci pour vos reaction:D:D