Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. void GUIMyFrame1::m_b_prewitt_click( wxCommandEvent& event )
  2. {
  3.     wxSize m_size = Img_Org.GetSize();
  4.     const int width = m_size.GetWidth();
  5.     const int height = m_size.GetHeight();
  6.     unsigned char* org_data = Img_Org.GetData();
  7.     unsigned char* cpy_data = (unsigned char*)malloc(width * height * 3 * sizeof(unsigned char));
  8.     int ver, hor;
  9.  
  10.     for (int y = 1; y < height - 1; ++y)
  11.     {
  12.         for (int x = 1; x < width - 1; ++x)
  13.         {
  14.             for (int off = 0; off < 3; ++off)
  15.             {
  16.                 ver = org_data[3 * ((y - 1) * width + (x - 1)) + off];
  17.                 ver += org_data[3 * (y * width + (x - 1)) + off];
  18.                 ver += org_data[3 * ((y + 1) * width + (x - 1)) + off];
  19.                 ver -= org_data[3 * ((y - 1) * width + (x + 1)) + off];
  20.                 ver -= org_data[3 * (y * width + (x + 1)) + off];
  21.                 ver -= org_data[3 * ((y + 1) * width + (x + 1)) + off];
  22.  
  23.                 if (ver > 255) ver = 255;
  24.                 else if (ver < 0) ver = 0;
  25.  
  26.                 hor = org_data[3 * ((y - 1) * width + (x - 1)) + off];
  27.                 hor += org_data[3 * ((y - 1) * width + x) + off];
  28.                 hor += org_data[3 * ((y - 1) * width + (x + 1)) + off];
  29.                 hor -= org_data[3 * ((y + 1) * width + (x + 1)) + off];
  30.                 hor -= org_data[3 * ((y + 1) * width + x) + off];
  31.                 hor -= org_data[3 * ((y + 1) * width + (x - 1)) + off];
  32.  
  33.                 if (hor > 255) hor = 255;
  34.                 else if (hor < 0) hor = 0;
  35.  
  36.                 cpy_data[3 * (y * width + x) + off] = sqrt(ver * ver + hor * hor);
  37.             }
  38.         }
  39.     }
  40.  
  41.     Img_Cpy.Create(m_size, cpy_data);
  42.     Repaint();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement