import cv2
import numpy as np

if __name__=="__main__":
    img = cv2.imread("item/sample.JPG")
    height, width = img.shape[:2]
    img_copy = img

    #それぞれの色のしきい値
    red_min = 0
    green_min = 80
    blue_min = 0
    red_max = 255
    green_max = 180
    blue_max = 140

    gray_default = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    for i in range(height):
        for j in range(width):
            img[i, j, 2] = 0 #赤の要素を0
            if img[i, j, 0] < blue_min:
                img[i, j, 0] = 255 #緑の要素を0
            if img[i, j, 0] > blue_max:
                img[i, j, 0] = 255 #緑の要素を0
            if img[i, j, 1] < green_min:
                img[i, j, 1] = 255 #緑の要素を0
            if img[i, j, 1] > green_max:
                img[i, j, 1] = 255 #緑の要素を0
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    cv2.imshow("src", img_copy)
    cv2.imshow("gray_default", gray_default)
    cv2.imshow("gray", gray)
    cv2.waitKey(0)

@@ -324,24 +324,960 @@
 _RGB2GRAY)%0A%0A
+    # 4%E8%BF%91%E5%82%8D%E3%81%AE%E5%AE%9A%E7%BE%A9%0A    neiborhood4 = np.array(%5B%5B0, 1, 0%5D,%0A                            %5B1, 1, 1%5D,%0A                            %5B0, 1, 0%5D%5D,%0A                            np.uint8)%0A%0A    # 8%E8%BF%91%E5%82%8D%E3%81%AE%E5%AE%9A%E7%BE%A9%0A    neiborhood8 = np.array(%5B%5B1, 1, 1%5D,%0A                            %5B1, 1, 1%5D,%0A                            %5B1, 1, 1%5D%5D,%0A                            np.uint8)%0A%0A    # 8%E8%BF%91%E5%82%8D%E3%81%A7%E8%86%A8%E5%BC%B5%E5%87%A6%E7%90%86%0A    img_dilation = cv2.dilate(img,%0A                              neiborhood8,%0A                              iterations=1)%0A    for i in range(3):%0A        img_dilation = cv2.dilate(img_dilation,%0A                              neiborhood8,%0A                              iterations=1)%0A%0A    # 8%E8%BF%91%E5%82%8D%E3%81%A7%E7%B8%AE%E5%B0%8F%E5%87%A6%E7%90%86%0A    img_erosion = cv2.erode(img_dilation,%0A                              neiborhood8,%0A                              iterations=1)%0A    for i in range(3):%0A        img_erosion = cv2.erode(img_erosion,%0A                              neiborhood8,%0A                              iterations=1)%0A%0A
     for i in
@@ -1334,24 +1334,32 @@
          img
+_erosion
 %5Bi, j, 2%5D = 
@@ -1378,32 +1378,40 @@
           if img
+_erosion
 %5Bi, j, 0%5D %3C blue
@@ -1431,32 +1431,37 @@
          img
+_erosion
 %5Bi, j
-, 0
 %5D = 255 #%E7%B7%91%E3%81%AE%E8%A6%81
@@ -1478,24 +1478,32 @@
       if img
+_erosion
 %5Bi, j, 0%5D %3E 
@@ -1531,24 +1531,29 @@
      img
+_erosion
 %5Bi, j
-, 0
 %5D = 255 
@@ -1570,32 +1570,40 @@
           if img
+_erosion
 %5Bi, j, 1%5D %3C gree
@@ -1624,32 +1624,37 @@
          img
+_erosion
 %5Bi, j
-, 1
 %5D = 255 #%E7%B7%91%E3%81%AE%E8%A6%81
@@ -1671,24 +1671,32 @@
       if img
+_erosion
 %5Bi, j, 1%5D %3E 
@@ -1725,24 +1725,29 @@
      img
+_erosion
 %5Bi, j
-, 1
 %5D = 255 
@@ -1750,24 +1750,25 @@
 255 #%E7%B7%91%E3%81%AE%E8%A6%81%E7%B4%A0%E3%82%920%0A
+%0A
     gray = c
@@ -1774,32 +1774,40 @@
 cv2.cvtColor(img
+_erosion
 , cv2.COLOR_RGB2
@@ -1869,31 +1869,15 @@
 gray
-_default%22, gray_default
+%22, gray
 )%0A  
@@ -1880,34 +1880,39 @@
 )%0A    cv2.im
-show
+write
 (%22gray
+.png
 %22, gray)%0A   
@@ -1900,32 +1900,69 @@
 ray.png%22, gray)%0A
+    #cv2.imshow(%22test%22, img_erosion)%0A
     cv2.waitKey(

add erosion and dilation