Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void srednia() // srednia arytmetyczna
- {
- System.Drawing.Color pixel;
- double tmpkont = 0, kontrast = 0;
- double avg = 0, jasnosc = 0, tmpjasn = 0;
- for (int j = 1; j <= L; j++)
- for (int i = 1; i <= K; i++)
- {
- pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
- avg = (pixel.R + pixel.G + pixel.B) / 3;
- pixel = System.Drawing.Color.FromArgb((int)avg, (int)avg, (int)avg);
- m_ekran.SetPixel(i - 1, j - 1, pixel);
- tmpjasn += avg;
- }
- jasnosc = tmpjasn / (L * K);
- jasnosc = jasnosc * 100 / 255;
- label2.Text = "Jasność obrazu: " + (int)jasnosc + "%";
- for (int j = 1; j <= L; j++)
- for (int i = 1; i <= K; i++)
- {
- pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
- avg = (pixel.R + pixel.G + pixel.B) / 3;
- tmpkont = tmpkont + ((avg - jasnosc) * (avg - jasnosc));
- }
- kontrast = System.Math.Sqrt(tmpkont / (L * K));
- kontrast = 100 * kontrast / 127;
- label3.Text = "Kontrast obrazu: " + (int)kontrast + "%";
- SetBitMap(ref m_ekran);
- }
- //------------------
- //------------------
- public void rgb_hls()
- {
- System.Drawing.Color pixel;
- double max = 0, min = 0, avg = 0, jasnosc = 0, tmpjasn = 0;
- double kontrast = 0, tmpkont = 0;
- for (int j = 1; j <= L; j++)
- for (int i = 1; i <= K; i++)
- {
- pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
- max = pixel.G;
- if (pixel.R > pixel.G) max = pixel.R;
- if (pixel.B > max) max = pixel.B;
- min = pixel.G;
- if (pixel.R < pixel.G) min = pixel.R;
- if (pixel.B < min) min = pixel.B;
- avg = (max + min) / 2;
- pixel = System.Drawing.Color.FromArgb((int)avg, (int)avg, (int)avg);
- m_ekran.SetPixel(i - 1, j - 1, pixel);
- tmpjasn += avg;
- }
- jasnosc = tmpjasn / (L * K);
- jasnosc = (jasnosc * 100) / 255;
- tmpkont += ((avg - jasnosc) * (avg - jasnosc));
- label2.Text = "Jasność obrazu: " + (int)jasnosc + "%";
- // kontrast
- for (int j = 1; j <= L; j++)
- for (int i = 1; i <= K; i++)
- {
- pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
- avg = (pixel.R + pixel.G + pixel.B) / 3;
- tmpkont = tmpkont + ((avg - jasnosc) * (avg - jasnosc));
- }
- kontrast = System.Math.Sqrt(tmpkont / (L * K));
- kontrast = 100 * kontrast / 127;
- label3.Text = "Kontrast obrazu: " + (int)kontrast + "%";
- SetBitMap(ref m_ekran);
- }
- public void rgb_hsvb()
- {
- System.Drawing.Color pixel;
- double max = 0, tmpjasn = 0, jasnosc = 0;
- double tmpkont = 0, kontrast = 0;
- for (int j = 1; j <= L; j++)
- for (int i = 1; i <= K; i++)
- {
- pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
- if (pixel.R > pixel.G) max = pixel.R;
- else max = pixel.G;
- if (max < pixel.B) max = pixel.B;
- pixel = System.Drawing.Color.FromArgb((int)max, (int)max, (int)max);
- tmpjasn += max;
- m_ekran.SetPixel(i - 1, j - 1, pixel);
- }
- jasnosc = tmpjasn / (L * K);
- jasnosc = (jasnosc * 100) / 255;
- tmpkont += ((max - jasnosc) * (max - jasnosc));
- label2.Text = "Jasność obrazu: " + (int)jasnosc + "%";
- // kontrast
- for (int j = 1; j <= L; j++)
- for (int i = 1; i <= K; i++)
- {
- pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
- int avg = (pixel.R + pixel.G + pixel.B) / 3;
- tmpkont = tmpkont + ((avg - jasnosc) * (avg - jasnosc));
- }
- label2.Text = "Jasność obrazu: " + (int)jasnosc + "%";
- kontrast = System.Math.Sqrt(tmpkont / (L * K));
- kontrast = (100 * kontrast / 127);
- label3.Text = "Kontrast obrazu: " + (int)kontrast + "%";
- SetBitMap(ref m_ekran);
- }
- public void scroll_jasnosc()
- {
- int offset = hScrollBar1.Value;
- int Red = 0;
- int Green = 0;
- int Blue = 0;
- double avg, sum = 0, jasnosc, tmpjasn = 0, kontrast, tmpkont = 0;
- System.Drawing.Color pixel;
- for (int j = 1; j <= L; j++)
- for (int i = 1; i <= K; i++)
- {
- pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
- Red = pixel.R + offset;
- if (Red > 255) Red = 255;
- else if (Red < 0) Red = 0;
- Green = pixel.G + offset;
- if (Green > 255) Green = 255;
- else if (Green < 0) Green = 0;
- Blue = pixel.B + offset;
- if (Blue > 255) Blue = 255;
- else if (Blue < 0) Blue = 0;
- pixel = System.Drawing.Color.FromArgb(Red, Green, Blue);
- m_ekran.SetPixel(i - 1, j - 1, pixel);
- avg = (Red + Green + Blue) / 3;
- sum += avg;
- }
- //jasnosc obrazu
- jasnosc = sum / (L * K);
- tmpjasn = (jasnosc * 100) / 255 + 0.996;
- label2.Text = "Jasność obrazu " + (int)tmpjasn + "%";
- // kontrast obrazu
- for (int j = 1; j <= L; j++)
- for (int i = 1; i <= K; i++)
- {
- pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
- Red = pixel.R + offset;
- if (Red > 255) Red = 255;
- else if (Red < 0) Red = 0;
- Green = pixel.G + offset;
- if (Green > 255) Green = 255;
- else if (Green < 0) Green = 0;
- Blue = pixel.B + offset;
- if (Blue > 255) Blue = 255;
- else if (Blue < 0) Blue = 0;
- avg = (Red + Green + Blue) / 3;
- tmpkont = tmpkont + ((avg - jasnosc) * (avg - jasnosc));
- }
- kontrast = System.Math.Sqrt(tmpkont / (L * K));
- kontrast = (kontrast * 100 / 127);
- label3.Text = "Kontrast obrazu " + (int)kontrast + "%";
- SetBitMap(ref m_ekran);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement