Advertisement
Guest User

gk

a guest
Nov 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.08 KB | None | 0 0
  1.  public void srednia() // srednia arytmetyczna
  2.         {
  3.             System.Drawing.Color pixel;
  4.             double tmpkont = 0, kontrast = 0;
  5.             double avg = 0, jasnosc = 0, tmpjasn = 0;
  6.             for (int j = 1; j <= L; j++)
  7.                 for (int i = 1; i <= K; i++)
  8.                 {
  9.                     pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
  10.  
  11.                     avg = (pixel.R + pixel.G + pixel.B) / 3;
  12.                     pixel = System.Drawing.Color.FromArgb((int)avg, (int)avg, (int)avg);
  13.  
  14.                     m_ekran.SetPixel(i - 1, j - 1, pixel);
  15.  
  16.                     tmpjasn += avg;
  17.                 }
  18.             jasnosc = tmpjasn / (L * K);
  19.             jasnosc = jasnosc * 100 / 255;
  20.  
  21.             label2.Text = "Jasność obrazu: " + (int)jasnosc + "%";
  22.  
  23.             for (int j = 1; j <= L; j++)
  24.                 for (int i = 1; i <= K; i++)
  25.                 {
  26.                     pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
  27.                     avg = (pixel.R + pixel.G + pixel.B) / 3;
  28.                     tmpkont = tmpkont + ((avg - jasnosc) * (avg - jasnosc));
  29.  
  30.                 }
  31.             kontrast = System.Math.Sqrt(tmpkont / (L * K));
  32.             kontrast = 100 * kontrast / 127;
  33.             label3.Text = "Kontrast obrazu: " + (int)kontrast + "%";
  34.  
  35.             SetBitMap(ref m_ekran);
  36.         }
  37.  
  38.         //------------------
  39.         //------------------
  40.  
  41.         public void rgb_hls()
  42.         {
  43.             System.Drawing.Color pixel;
  44.             double max = 0, min = 0, avg = 0, jasnosc = 0, tmpjasn = 0;
  45.             double kontrast = 0, tmpkont = 0;
  46.             for (int j = 1; j <= L; j++)
  47.                 for (int i = 1; i <= K; i++)
  48.                 {
  49.                     pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
  50.  
  51.                     max = pixel.G;
  52.                     if (pixel.R > pixel.G) max = pixel.R;
  53.                     if (pixel.B > max) max = pixel.B;
  54.  
  55.                     min = pixel.G;
  56.                     if (pixel.R < pixel.G) min = pixel.R;
  57.                     if (pixel.B < min) min = pixel.B;
  58.  
  59.                     avg = (max + min) / 2;
  60.                     pixel = System.Drawing.Color.FromArgb((int)avg, (int)avg, (int)avg);
  61.  
  62.                     m_ekran.SetPixel(i - 1, j - 1, pixel);
  63.  
  64.                     tmpjasn += avg;
  65.                 }
  66.             jasnosc = tmpjasn / (L * K);
  67.             jasnosc = (jasnosc * 100) / 255;
  68.             tmpkont += ((avg - jasnosc) * (avg - jasnosc));
  69.             label2.Text = "Jasność obrazu: " + (int)jasnosc + "%";
  70.  
  71.             // kontrast
  72.             for (int j = 1; j <= L; j++)
  73.                 for (int i = 1; i <= K; i++)
  74.                 {
  75.                     pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
  76.                     avg = (pixel.R + pixel.G + pixel.B) / 3;
  77.                     tmpkont = tmpkont + ((avg - jasnosc) * (avg - jasnosc));
  78.  
  79.                 }
  80.  
  81.             kontrast = System.Math.Sqrt(tmpkont / (L * K));
  82.             kontrast = 100 * kontrast / 127;
  83.             label3.Text = "Kontrast obrazu: " + (int)kontrast + "%";
  84.             SetBitMap(ref m_ekran);
  85.         }
  86.  
  87.         public void rgb_hsvb()
  88.         {
  89.             System.Drawing.Color pixel;
  90.             double max = 0, tmpjasn = 0, jasnosc = 0;
  91.             double tmpkont = 0, kontrast = 0;
  92.             for (int j = 1; j <= L; j++)
  93.                 for (int i = 1; i <= K; i++)
  94.                 {
  95.                     pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
  96.  
  97.                     if (pixel.R > pixel.G) max = pixel.R;
  98.                     else max = pixel.G;
  99.                     if (max < pixel.B) max = pixel.B;
  100.  
  101.                     pixel = System.Drawing.Color.FromArgb((int)max, (int)max, (int)max);
  102.  
  103.                     tmpjasn += max;
  104.  
  105.  
  106.                     m_ekran.SetPixel(i - 1, j - 1, pixel);
  107.                 }
  108.             jasnosc = tmpjasn / (L * K);
  109.             jasnosc = (jasnosc * 100) / 255;
  110.             tmpkont += ((max - jasnosc) * (max - jasnosc));
  111.             label2.Text = "Jasność obrazu: " + (int)jasnosc + "%";
  112.  
  113.             // kontrast
  114.             for (int j = 1; j <= L; j++)
  115.                 for (int i = 1; i <= K; i++)
  116.                 {
  117.                     pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
  118.                     int avg = (pixel.R + pixel.G + pixel.B) / 3;
  119.                     tmpkont = tmpkont + ((avg - jasnosc) * (avg - jasnosc));
  120.  
  121.                 }
  122.             label2.Text = "Jasność obrazu: " + (int)jasnosc + "%";
  123.  
  124.             kontrast = System.Math.Sqrt(tmpkont / (L * K));
  125.             kontrast = (100 * kontrast / 127);
  126.             label3.Text = "Kontrast obrazu: " + (int)kontrast + "%";
  127.             SetBitMap(ref m_ekran);
  128.         }
  129.  
  130.         public void scroll_jasnosc()
  131.         {
  132.             int offset = hScrollBar1.Value;
  133.             int Red = 0;
  134.             int Green = 0;
  135.             int Blue = 0;
  136.             double avg, sum = 0, jasnosc, tmpjasn = 0, kontrast, tmpkont = 0;
  137.  
  138.             System.Drawing.Color pixel;
  139.  
  140.             for (int j = 1; j <= L; j++)
  141.                 for (int i = 1; i <= K; i++)
  142.                 {
  143.                     pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
  144.  
  145.                     Red = pixel.R + offset;
  146.  
  147.                     if (Red > 255) Red = 255;
  148.                     else if (Red < 0) Red = 0;
  149.  
  150.                     Green = pixel.G + offset;
  151.  
  152.                     if (Green > 255) Green = 255;
  153.                     else if (Green < 0) Green = 0;
  154.  
  155.                     Blue = pixel.B + offset;
  156.  
  157.                     if (Blue > 255) Blue = 255;
  158.                     else if (Blue < 0) Blue = 0;
  159.  
  160.                     pixel = System.Drawing.Color.FromArgb(Red, Green, Blue);
  161.  
  162.                    
  163.                     m_ekran.SetPixel(i - 1, j - 1, pixel);
  164.                     avg = (Red + Green + Blue) / 3;
  165.                     sum += avg;
  166.  
  167.                 }
  168.             //jasnosc obrazu
  169.             jasnosc = sum / (L * K);
  170.             tmpjasn = (jasnosc * 100) / 255 + 0.996;
  171.             label2.Text = "Jasność obrazu " + (int)tmpjasn + "%";
  172.  
  173.             // kontrast obrazu
  174.             for (int j = 1; j <= L; j++)
  175.                 for (int i = 1; i <= K; i++)
  176.                 {
  177.                     pixel = m_obraz_w_pamieci.GetPixel(i - 1, j - 1);
  178.                     Red = pixel.R + offset;
  179.  
  180.                     if (Red > 255) Red = 255;
  181.                     else if (Red < 0) Red = 0;
  182.  
  183.                     Green = pixel.G + offset;
  184.  
  185.                     if (Green > 255) Green = 255;
  186.                     else if (Green < 0) Green = 0;
  187.  
  188.                     Blue = pixel.B + offset;
  189.  
  190.                     if (Blue > 255) Blue = 255;
  191.                     else if (Blue < 0) Blue = 0;
  192.  
  193.                     avg = (Red + Green + Blue) / 3;
  194.                     tmpkont = tmpkont + ((avg - jasnosc) * (avg - jasnosc));
  195.  
  196.                 }
  197.  
  198.             kontrast = System.Math.Sqrt(tmpkont / (L * K));
  199.             kontrast = (kontrast * 100 / 127);
  200.  
  201.             label3.Text = "Kontrast obrazu " + (int)kontrast + "%";
  202.  
  203.             SetBitMap(ref m_ekran);
  204.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement