Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace DN2_Haar.src.Statitiscs
  9. {
  10.     class Blokovnost
  11.     {
  12.         public static double Calc(string imageName)
  13.         {
  14.  
  15.             // Read images
  16.             Bitmap bmp = new Bitmap(imageName);
  17.             LockBitmap lockBitmap = new LockBitmap(bmp);
  18.             lockBitmap.LockBits();
  19.  
  20.             int M = lockBitmap.Width;
  21.             int N = lockBitmap.Height;
  22.  
  23.             double result = 0.0;
  24.  
  25.             int maxM = (int)Math.Floor(M / 8.0);
  26.             for (int i = 0; i < maxM; i++)
  27.             {
  28.                 for (int j = 0; j < N; j++)
  29.                 {
  30.                     Color c1 = lockBitmap.GetPixel(i * 8, j);
  31.                     Color c2 = lockBitmap.GetPixel(i * 8 + 1, j);
  32.  
  33.                     result += Math.Abs(c1.R - c2.R);
  34.                 }
  35.             }
  36.  
  37.             int maxN = (int)Math.Floor(N / 8.0);
  38.             for (int j = 0; j < maxN; j++)
  39.             {
  40.                 for (int i = 0; i < M; i++)
  41.                 {
  42.                     Color c1 = lockBitmap.GetPixel(i, j * 8);
  43.                     Color c2 = lockBitmap.GetPixel(i, j * 8 + 1);
  44.  
  45.                     result += Math.Abs(c1.R - c2.R);
  46.                 }
  47.             }
  48.  
  49.             return result;
  50.         }
  51.  
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement