C# TA GÖRÜNTÜNÜN HİSTOGRAMINI ALMA VE HİSTOGRAM ÇİZME
BİR GÖRÜNTÜNÜN HİSTOGRAMINI ÇIKARMAK DEMEK RESİMDE HER BİR PİXEL DEĞERİNİN TÜM RESİM ÜZERİNDE BULUNMA YOĞUNLUĞU ANLAMINA GELİR.ÖR: O DEĞERİNDEN RESİMDE 240 TANE VARSA O IN YOĞUNLUĞU 240 OLUYO BÖYLECE BİR PİXEL 0-255 ARASINDA DEĞER ALDIĞINA GÖRE TÜM RESİMDE 0-255 DEĞER ARALIĞININ RESİM ÜZERİNDE HER BİR DEĞERİN YOĞUNLUYLA HİSTOGRAM BULUNMUŞ OLUR…
public int[,] histogram(Bitmap resim)
{
int[,] hist = new int[3, 256];
int a = 0;
if (resim.PixelFormat == PixelFormat.Format32bppArgb)
{
a = 4;
}
else if (resim.PixelFormat == PixelFormat.Format24bppRgb)
{
a = 3;
}
progressBar1.Visible = true;
progressBar1.Maximum = resim.Width * resim.Height;
unsafe
{
BitmapData data = resim.LockBits(new Rectangle(0, 0, resim.Width, resim.Height), ImageLockMode.ReadWrite, resim.PixelFormat);
byte* z = (byte*)data.Scan0;
for (int i = 0; i < data.Width; i++)
{
for (int j = 0; j < data.Height; j++)
{
hist[0, z[0]]++;
hist[1, z[1]]++;
hist[2, z[2]]++;
z += a;
if ((i % 5) == 0)//her on satırda bir göstergeyi güncelle
{
progressBar1.Value = i * resim.Height + j;
Application.DoEvents();
}
}
}
resim.UnlockBits(data);
}
progressBar1.Visible = false;
return hist;
}
public void histogramciz(ref int[,] hist)
{
pictureBox2.Refresh();
Graphics g = pictureBox2.CreateGraphics();
Pen pp = new Pen(Color.Red,1);
for (int i = 0; i < 256; i++)
{
g.DrawLine(pp, new Point(i, pictureBox2.Height), new Point(i, pictureBox2.Height – hist[2, i] / 10));
}
g.Dispose();
}
MEHMET SALİH DEVECİ
YAZILIM MÜHENDİSİ
IT Tutorial IT Tutorial | Oracle DBA | SQL Server, Goldengate, Exadata, Big Data, Data ScienceTutorial
merhaba,
PixelFormat.Format24bppRgb bu satırdaki PixcelFormat hangi kütüphane fonksiyonu acaba tanımıyorda. birde ProgressBar değişkeni ne için acaba bunun nedenini de sorabilir miyim?
Merhaba Hocam;
Programı atar mısınız ve histogram kısmını nasıl çağıracaz. Çalıştıramadım kodları 😕
Thank you a lot for sharing this with all people you actually recognise what you’re speaking about! Bookmarked. Kindly additionally consult with my website =). We could have a link alternate arrangement between us!