silvervana
Messages postés10Date d'inscriptionmardi 21 février 2006StatutMembreDernière intervention16 mai 2006
-
4 avril 2006 à 11:53
molloc459
Messages postés1Date d'inscriptionlundi 6 mars 2006StatutMembreDernière intervention15 mai 2008
-
15 mai 2008 à 18:56
Bonjour,
Je voudrais pouvoir passer d'un mode RGB à un mode YUV, et inversement. Le problème c'est qu'en partant d'une image RGB que je modifie en YUV, puis que je remodifie en RGB, je n'arrive pas à retrouver mon image de départ... je pense à un problème de conversion mais je ne vois pas comment faire.... Je joint le code, merci pour vos idées et commentaires !!!
Code :
//je récupère mon image et je lance ma méthode RGBtoYUV(rgbsImage, rgbsImage)
File fImg = new File (szPathImage);
Image = ImageIO.read (fImg);
//récupère les pixels de l'image
int iWidthImage = Image.getWidth ();
int iHeightImage = Image.getHeight ();
int [] rgbsImage = new int[iWidthImage * iHeightImage];
//puis je lance l'inverse et je réécris...
YUVtoRGB(rgbsImage, rgbsImage);
BufferedImage im = new BufferedImage(Image.getWidth(), Image.getHeight(),BufferedImage.TYPE_INT_RGB);
im.setRGB (0, 0,Image.getWidth(), Image.getHeight(), rgbsImage, 0, Image.getWidth());
// On sauve l'image
File fic= new File(szNom+ "." + szFormat);
ImageIO.write(im, szFormat, fic);
Voici mes méthodes :
private void RGBtoYUV(int [] rgbs, int [] yuvs)
{
for(int i=0; i<rgbs.length; i++)
{
int rgb = rgbs[i];
int A = (rgb >>24 ) & 0xff;
int R = (rgb >>16 ) & 0xFF;
int G = (rgb >> 8 ) & 0xFF;
int B = rgb & 0xFF;
/*int Y = (int)(0.299* R + 0.587 * G + 0.114 *B);
int U = (int)(-0.147*R - 0.289*G +0.436*B);
int V = (int)(0.615*R -0.515*G - 0.100*B);*/
int Y = (int)(0.299 * R + 0.587 * G + 0.114 * B);
int U = (int)(R - Y);
int V = (int)(B - Y);
private void YUVtoRGB(int [] yuvs, int [] rgbs )
{
for(int i=0; i<rgbs.length; i++)
{
int yuv = yuvs[i];
int A = (yuv >>24 ) & 0xff;
int Y = (yuv >>16 ) & 0xFF;
int U = (yuv >> 8 ) & 0xFF;
int V = yuv & 0xFF;
/*int R = (int)(Y + 1.140 * V);
int G = (int)(Y - 0.395 * U - 0.581 * V);
int B = (int)(Y + 2.032 * U);*/
int R = (int)(U + Y);
int B = (int)(V + Y);
int G = (int)((Y*1.7 - R*0.509 - B*0.194));