daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Operação morfológica dilatação
  2. int vc_binary_dilate(IVC *src, IVC *dst, int kernel) {
  3.  
  4.     unsigned char *datasrc = (unsigned char *)src->data;
  5.     int bytesperline_src = src->width * src->channels;
  6.     int channels_src = src->channels;
  7.     unsigned char *datadst = (unsigned char *)dst->data;
  8.     int bytesperline_dst = dst->width * dst->channels;
  9.     int channels_dst = dst->channels;
  10.  
  11.     int width = src->width;
  12.     int height = src->height;
  13.     int x, y, kx, ky, threshold, vMin = 0, vMax = 0;
  14.     long int pos, posk = 0;
  15.     int existe = 0;
  16.  
  17.     //verificação de erros
  18.  
  19.     if ((src->width <= 0) || (src->height <= 0) || (src->data == NULL)) return 0;
  20.     if ((src->width != dst->width) || (src->height != dst->height)) return 0;
  21.     if ((src->channels != 1) || (dst->channels != 1)) return 0;
  22.        
  23.    
  24.  
  25.     for (y = 0; y < height; y++) {
  26.  
  27.         for (x = 0; x < width; x++) {
  28.  
  29.             pos = y * bytesperline_src + x * channels_src;
  30.             existe = 0;
  31.  
  32.             for (ky = -kernel/2; ky <= kernel/2; ky++) {
  33.  
  34.                 for (kx = -kernel/2; kx <= kernel/2; kx++) {
  35.  
  36.                     if ((y + ky >= 0) && (y + ky < height) && (x + kx >= 0) && (x + kx < width)) {
  37.  
  38.                         posk = (y + ky) * bytesperline_src + (x + kx) * channels_src;
  39.  
  40.                         if (datasrc[posk] == 255)
  41.                             existe = 1;                
  42.  
  43.                     }
  44.                 }
  45.             }
  46.  
  47.             if (existe == 1) {
  48.                 datadst[pos] = 255;
  49.             }
  50.             else {
  51.                 datadst[pos] = 0;
  52.             }
  53.         }          
  54.     }
  55.  
  56.     return 1;
  57.  
  58. }
  59.  
  60. //Operação morfológica erosão
  61. int vc_binary_erode(IVC *src, IVC *dst, int kernel) {
  62.  
  63.     unsigned char *datasrc = (unsigned char *)src->data;
  64.     int bytesperline_src = src->width * src->channels;
  65.     int channels_src = src->channels;
  66.     unsigned char *datadst = (unsigned char *)dst->data;
  67.     int bytesperline_dst = dst->width * dst->channels;
  68.     int channels_dst = dst->channels;
  69.  
  70.     int width = src->width;
  71.     int height = src->height;
  72.     int x, y, kx, ky, threshold, vMin = 0, vMax = 0;
  73.     long int pos, posk = 0;
  74.     int existe = 0;
  75.  
  76.     //verificação de erros
  77.  
  78.     if ((src->width <= 0) || (src->height <= 0) || (src->data == NULL)) return 0;
  79.     if ((src->width != dst->width) || (src->height != dst->height)) return 0;
  80.     if ((src->channels != 1) || (dst->channels != 1)) return 0;
  81.    
  82.  
  83.     for (y = 0; y < height; y++) {
  84.  
  85.         for (x = 0; x < width; x++) {
  86.  
  87.             pos = y * bytesperline_src + x * channels_src;
  88.             existe = 0;
  89.  
  90.             for (ky = -kernel/2; ky <= kernel/2; ky++) {
  91.  
  92.                 for (kx = -kernel/2; kx <= kernel/2; kx++) {
  93.  
  94.                     if ((y + ky >= 0) && (y + ky < height) && (x + kx >= 0) && (x + kx < width)) {
  95.  
  96.                         posk = (y + ky) * bytesperline_src + (x + kx) * channels_src;
  97.  
  98.                         if (datasrc[posk] == 0)
  99.                             existe = 1;
  100.  
  101.                     }
  102.                 }
  103.             }
  104.  
  105.             if (existe == 1) {
  106.                 datadst[pos] = 0;
  107.             }
  108.             else {
  109.                 datadst[pos] = 255;
  110.             }
  111.         }
  112.     }
  113.  
  114.     return 1;
  115.  
  116. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top