Augmenter le contraste et la luminosité d'une image
2 réponses
tony
Bonjour =E0 tous,
Je recherche un algorithme de traitement d'image me=20
permettant d'augmenter (ou r=E9duire) le contraste d'une=20
image et pareil pour la luminosit=E9.
Je crois que ce n'est pas le bon NG ;-). On n'a pas la sciences infuse ;-) malheureusement
-- Paul Bacelar
"tony" wrote in message news:0d8b01c4cd4c$0e974620$ Bonjour à tous,
Je recherche un algorithme de traitement d'image me permettant d'augmenter (ou réduire) le contraste d'une image et pareil pour la luminosité.
Merci d'avance.
Frederic Melantois
Bonjour,
Pour la luminosité :
<code>
public static void Luminosite(Bitmap bitmap, int lumiere) { int width = bitmap.Width; int height = bitmap.Height; if (lumiere<-255) lumiere = -255; else if (lumiere>255) lumiere = 255; //Table de pré-calcul byte [] tab = new byte[256]; for (byte i=0; i<%5 ; i++) { int val = i+lumiere; tab[i] = (byte)((val>255)?255:(val<0)? 0 : val); } unsafe { BitmapData bmpData=bitmap.LockBits(new Rectangle(0,0,width,height),ImageLockMode.ReadWrite,PixelFormat.Format24bppR gb); byte * newPixel = (byte*)(void *)bmpData.Scan0; int stride = bmpData.Stride; int offset = width % 4; width = width*3;//parcours sur les bytes for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { newPixel[0]= tab[newPixel[0]]; newPixel++; } newPixel+=offset; } bitmap.UnlockBits(bmpData); } }
</code>
Pour le contraste, je ne l'utilise pas (tu trouveras facilement sur le net). Je te propose un algo simple que j'appelle correcteur d'exposition (et que mon infographiste sous photoshop me jalouse ;-)
<code> public static void CorrectionExposition(Bitmap bitmap,int correction) { int width = bitmap.Width; int height = bitmap.Height; //Table de pré-calcul byte [] tab = new byte[256]; for (int i=0; i<%5 ; i++) { double d = Math.Exp(-(i/255f * correction/100.0f)); tab[i] = (byte)((1.0 - d)*255); } unsafe { BitmapData bmpData=bitmap.LockBits(new Rectangle(0,0,width,height),ImageLockMode.ReadWrite,PixelFormat.Format24bppR gb); byte * newPixel = (byte*)(void *)bmpData.Scan0; int stride = bmpData.Stride; int offset = width % 4; width = width*3;//le parcours se fait sur chaque byte for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { newPixel[0]= tab[newPixel[0]]; newPixel++; } newPixel+=offset; } bitmap.UnlockBits(bmpData); } } </code>
Pour les explications, il faudra attendre quelques semaines/mois ;-) , je compte publier un article sur le traitement d'images sur le site Dotnet-tech.
http://www.dotnet-tech.com/tutoriels/
Frédéric Mélantois
"tony" a écrit dans le message de news:0d8b01c4cd4c$0e974620$ Bonjour à tous,
Je recherche un algorithme de traitement d'image me permettant d'augmenter (ou réduire) le contraste d'une image et pareil pour la luminosité.
Merci d'avance.
Bonjour,
Pour la luminosité :
<code>
public static void Luminosite(Bitmap bitmap, int lumiere)
{
int width = bitmap.Width;
int height = bitmap.Height;
if (lumiere<-255)
lumiere = -255;
else if (lumiere>255)
lumiere = 255;
//Table de pré-calcul
byte [] tab = new byte[256];
for (byte i=0; i<%5 ; i++)
{
int val = i+lumiere;
tab[i] = (byte)((val>255)?255:(val<0)? 0 : val);
}
unsafe
{
BitmapData bmpData=bitmap.LockBits(new
Rectangle(0,0,width,height),ImageLockMode.ReadWrite,PixelFormat.Format24bppR
gb);
byte * newPixel = (byte*)(void *)bmpData.Scan0;
int stride = bmpData.Stride;
int offset = width % 4;
width = width*3;//parcours sur les bytes
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
newPixel[0]= tab[newPixel[0]];
newPixel++;
}
newPixel+=offset;
}
bitmap.UnlockBits(bmpData);
}
}
</code>
Pour le contraste, je ne l'utilise pas (tu trouveras facilement sur le net).
Je te propose un algo simple que j'appelle correcteur d'exposition (et que
mon infographiste sous photoshop me jalouse ;-)
<code>
public static void CorrectionExposition(Bitmap bitmap,int correction)
{
int width = bitmap.Width;
int height = bitmap.Height;
//Table de pré-calcul
byte [] tab = new byte[256];
for (int i=0; i<%5 ; i++)
{
double d = Math.Exp(-(i/255f * correction/100.0f));
tab[i] = (byte)((1.0 - d)*255);
}
unsafe
{
BitmapData bmpData=bitmap.LockBits(new
Rectangle(0,0,width,height),ImageLockMode.ReadWrite,PixelFormat.Format24bppR
gb);
byte * newPixel = (byte*)(void *)bmpData.Scan0;
int stride = bmpData.Stride;
int offset = width % 4;
width = width*3;//le parcours se fait sur chaque byte
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
newPixel[0]= tab[newPixel[0]];
newPixel++;
}
newPixel+=offset;
}
bitmap.UnlockBits(bmpData);
}
}
</code>
Pour les explications, il faudra attendre quelques semaines/mois ;-) , je
compte publier un article sur le traitement d'images sur le site
Dotnet-tech.
http://www.dotnet-tech.com/tutoriels/
Frédéric Mélantois
"tony" <toto@discussions.microsoft.com> a écrit dans le message de
news:0d8b01c4cd4c$0e974620$3501280a@phx.gbl...
Bonjour à tous,
Je recherche un algorithme de traitement d'image me
permettant d'augmenter (ou réduire) le contraste d'une
image et pareil pour la luminosité.
public static void Luminosite(Bitmap bitmap, int lumiere) { int width = bitmap.Width; int height = bitmap.Height; if (lumiere<-255) lumiere = -255; else if (lumiere>255) lumiere = 255; //Table de pré-calcul byte [] tab = new byte[256]; for (byte i=0; i<%5 ; i++) { int val = i+lumiere; tab[i] = (byte)((val>255)?255:(val<0)? 0 : val); } unsafe { BitmapData bmpData=bitmap.LockBits(new Rectangle(0,0,width,height),ImageLockMode.ReadWrite,PixelFormat.Format24bppR gb); byte * newPixel = (byte*)(void *)bmpData.Scan0; int stride = bmpData.Stride; int offset = width % 4; width = width*3;//parcours sur les bytes for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { newPixel[0]= tab[newPixel[0]]; newPixel++; } newPixel+=offset; } bitmap.UnlockBits(bmpData); } }
</code>
Pour le contraste, je ne l'utilise pas (tu trouveras facilement sur le net). Je te propose un algo simple que j'appelle correcteur d'exposition (et que mon infographiste sous photoshop me jalouse ;-)
<code> public static void CorrectionExposition(Bitmap bitmap,int correction) { int width = bitmap.Width; int height = bitmap.Height; //Table de pré-calcul byte [] tab = new byte[256]; for (int i=0; i<%5 ; i++) { double d = Math.Exp(-(i/255f * correction/100.0f)); tab[i] = (byte)((1.0 - d)*255); } unsafe { BitmapData bmpData=bitmap.LockBits(new Rectangle(0,0,width,height),ImageLockMode.ReadWrite,PixelFormat.Format24bppR gb); byte * newPixel = (byte*)(void *)bmpData.Scan0; int stride = bmpData.Stride; int offset = width % 4; width = width*3;//le parcours se fait sur chaque byte for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { newPixel[0]= tab[newPixel[0]]; newPixel++; } newPixel+=offset; } bitmap.UnlockBits(bmpData); } } </code>
Pour les explications, il faudra attendre quelques semaines/mois ;-) , je compte publier un article sur le traitement d'images sur le site Dotnet-tech.
http://www.dotnet-tech.com/tutoriels/
Frédéric Mélantois
"tony" a écrit dans le message de news:0d8b01c4cd4c$0e974620$ Bonjour à tous,
Je recherche un algorithme de traitement d'image me permettant d'augmenter (ou réduire) le contraste d'une image et pareil pour la luminosité.