Advertisement
WachidSusilo

Image Counter

Apr 12th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.19 KB | None | 0 0
  1. close all;
  2. clear all;
  3.  
  4. rgb = imread('gambar1.jpeg');
  5. [imageRows, imageColumns, colorChannels] = size(rgb);
  6. subplot(1,2,1);
  7. imshow(rgb,[]);
  8. axis on;
  9. title('Original');
  10.  
  11. crgb = imadjust(rgb, [0.3 0.7], []);
  12.  
  13. F = griddedInterpolant(double(crgb));
  14. [sx,sy,sz] = size(crgb);
  15. xq = (0:5:sx)';
  16. yq = (0:5:sy)';
  17. zq = (1:sz)';
  18. rescrgb = uint8(F({xq,yq,zq}));
  19. subplot(1,2,2);
  20. imshow(rescrgb);
  21. axis on;
  22. title('Resample');
  23.  
  24. r = rescrgb(:,:,1);
  25. g = rescrgb(:,:,2);
  26. b = rescrgb(:,:,3);
  27.  
  28. redMask = r > 250 & g < 90 & b < 90;
  29. blueMask = r < 50 & g > 170 & b > 200;
  30. greenMask = r < 180 & g > 200 & b < 220;
  31. orangeMask = r > 100 & g > 100 & b < 80;
  32. pinkMask = r > 220 & g < 100 & b > 200;
  33. violetMask = r > 220 & (g < 220 & g > 205) & b > 200;
  34.  
  35. figure();
  36. subplot(2, 3, 1);
  37. imshow(redMask);
  38. title('redMask');
  39.  
  40. subplot(2,3,3);
  41. imshow(blueMask);
  42. title('blueMask');
  43.  
  44. subplot(2,3,2);
  45. imshow(greenMask);
  46. title('greenMask');
  47.  
  48. subplot(2,3,4);
  49. imshow(orangeMask);
  50. title('orangeMask');
  51.  
  52. subplot(2,3,5);
  53. imshow(pinkMask);
  54. title('pinkMask');
  55.  
  56. subplot(2,3,6);
  57. imshow(violetMask);
  58. title('violetMask');
  59.  
  60. redBlob = conv2(double(redMask), ones(30, 30));
  61. greenBlob = conv2(double(greenMask), ones(30, 30));
  62. blueBlob = conv2(double(blueMask), ones(30, 30));
  63. orangeBlob = conv2(double(orangeMask), ones(30, 30));
  64. pinkBlob = conv2(double(pinkMask), ones(30, 30));
  65. violetBlob = conv2(double(violetMask), ones(30, 30));
  66.  
  67. figure();
  68. subplot(2, 3, 1);
  69. imshow(redBlob);
  70. title('redBlob');
  71.  
  72. subplot(2, 3, 2);
  73. imshow(greenBlob);
  74. title('greenBlob');
  75.  
  76. subplot(2, 3, 3);
  77. imshow(blueBlob);
  78. title('blueBlob');
  79.  
  80. subplot(2, 3, 4);
  81. imshow(orangeBlob);
  82. title('orangeBlob');
  83.  
  84. subplot(2, 3, 5);
  85. imshow(pinkBlob);
  86. title('pinkBlob');
  87.  
  88. subplot(2, 3, 6);
  89. imshow(violetBlob);
  90. title('violetBlob');
  91.  
  92. [R, redCount] = bwlabel(redBlob, 8);
  93. [G, greenCount] = bwlabel(greenBlob, 8);
  94. [B, blueCount] = bwlabel(blueBlob, 8);
  95. [O, orangeCount] = bwlabel(orangeBlob, 8);
  96. [P, pinkCount] = bwlabel(pinkBlob, 8);
  97. [V, violetCount] = bwlabel(violetBlob, 8);
  98.  
  99. Red = redCount
  100. Green = greenCount
  101. Blue = blueCount
  102. Orange = orangeCount
  103. Pink = pinkCount
  104. Violet = violetCount
  105. Total = Red + Green + Blue + Orange + Pink + Violet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement