Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 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.         // Works with gray images
  13.         public static double Calc(string imageName)
  14.         {
  15.  
  16.             // Read images
  17.             Bitmap bmp = new Bitmap(imageName);
  18.             LockBitmap lockBitmap = new LockBitmap(bmp);
  19.             lockBitmap.LockBits();
  20.  
  21.             int M = lockBitmap.Width;
  22.             int N = lockBitmap.Height;
  23.  
  24.             double result = 0.0;
  25.  
  26.             int maxM = (int)Math.Floor(M / 8.0);
  27.             for (int i = 0; i < maxM; i++)
  28.             {
  29.                 for (int j = 0; j < N; j++)
  30.                 {
  31.                     Color c1 = lockBitmap.GetPixel(i * 8, j);
  32.                     Color c2 = lockBitmap.GetPixel(i * 8 + 1, j);
  33.  
  34.                     result += Math.Abs(c1.R - c2.R);
  35.                 }
  36.             }
  37.  
  38.             int maxN = (int)Math.Floor(N / 8.0);
  39.             for (int j = 0; j < maxN; j++)
  40.             {
  41.                 for (int i = 0; i < M; i++)
  42.                 {
  43.                     Color c1 = lockBitmap.GetPixel(i, j * 8);
  44.                     Color c2 = lockBitmap.GetPixel(i, j * 8 + 1);
  45.  
  46.                     result += Math.Abs(c1.R - c2.R);
  47.                 }
  48.             }
  49.  
  50.             return result;
  51.         }
  52.  
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement