Advertisement
Guest User

373 week 9

a guest
May 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. ###Binary Erosion
  2. height = getHeight();
  3. width = getWidth();
  4.  
  5. v = newArray(width*height);
  6.  
  7. for(y = 1; y < height-1; y++){
  8. for(x = 1; x < width-1; x++){
  9. if(getPixel(x,y) != 0 && getPixel(x-1,y) != 0 && getPixel(x+1,y) != 0 && getPixel(x,y-1) != 0 && getPixel(x,y+1) != 0){
  10. v[x+y*width] = 255;
  11. }else{
  12. v[x+y*width] = 0;
  13. }
  14. }
  15. }
  16.  
  17. for(y = 1; y < height-1; y++){
  18. for(x = 1; x < width-1; x++){
  19. setPixel(x, y, v[x+y*width]);
  20. }
  21. }
  22.  
  23.  
  24. ###Binary close
  25. height = getHeight();
  26. width = getWidth();
  27.  
  28. v = newArray(width*height);
  29.  
  30. for(y = 1; y < height-1; y++){
  31. for(x = 1; x < width-1; x++){
  32. if(getPixel(x,y) == 0 && getPixel(x,y-1) == 0 && getPixel(x,y+1) == 0 && getPixel(x-1,y-1) == 0 && getPixel(x+1,y+1) == 0){
  33. v[x+y*width] = 0;
  34. }else{
  35. v[x+y*width] = 255;
  36. }
  37. }
  38. }
  39.  
  40. u = newArray(width*height);
  41.  
  42. for(y = 1; y < height-1; y++){
  43. for(x = 1; x < width-1; x++){
  44. p = x+y*width;
  45. if(v[p] != 0 && v[p-width] != 0 && v[p+width] != 0 && v[p-width-1] != 0 && v[p+width+1] != 0){
  46. u[x+y*width] = 255;
  47. }else{
  48. u[x+y*width] = 0;
  49. }
  50. }
  51. }
  52.  
  53. for(y = 1; y < height-1; y++){
  54. for(x = 1; x < width-1; x++){
  55. setPixel(x, y, u[x+y*width]);
  56. }
  57. }
  58.  
  59.  
  60. ###External Gradient
  61. height = getHeight();
  62. width = getWidth();
  63.  
  64. v = newArray(width*height);
  65.  
  66. for(y = 1; y < height-1; y++){
  67. for(x = 1; x < width-1; x++){
  68. if(getPixel(x,y) == 0 && getPixel(x-1,y-1) == 0 && getPixel(x+1,y+1) == 0 && getPixel(x-1,y+1) == 0 && getPixel(x+1,y-1) == 0){
  69. v[x+y*width] = 0;
  70. }else{
  71. v[x+y*width] = 255;
  72. }
  73. }
  74. }
  75.  
  76. u = newArray(width*height);
  77.  
  78. for(y = 1; y < height-1; y++){
  79. for(x = 1; x < width-1; x++){
  80. p = x+y*width;
  81. if(v[p] == 0 || getPixel(x,y) == 255){
  82. u[p]=0;
  83. }else{
  84. u[p]=255;
  85. }
  86. }
  87. }
  88.  
  89. for(y = 1; y < height-1; y++){
  90. for(x = 1; x < width-1; x++){
  91. setPixel(x, y, u[x+y*width]);
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement