img = cv.imread(‘019595_1.jpg’)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
ret, thresh = cv.threshold(gray,0,255,cv.THRESH_BINARY_INV + cv.THRESH_OTSU)
cv.imshow(“result”, thresh)
cv.waitKey(0)
→ edge 기반으로 segmentation된걸 찾아보아야겠다.
→ 배경과 분리하는걸찾아보자. 그후 masking.? → 실패
함수 threshold를 다시봐야겠다 싶어서 해보았다.
img = cv2.imread(‘019595_1.jpg’, 0)
blur = cv2.GaussianBlur(img,(5,5),0)
ret3,th3 = cv2.threshold(blur,252,255,cv2.THRESH_BINARY_INV)
cv2.imshow(‘mask’,th3)
cv2.waitKey(0)
깔끔하지는않다. smooth 처리해보자.
import numpy as np
from PIL import Image
pil_image=Image.fromarray(th3)
image = pil_image.filter(ImageFilter.ModeFilter(size=13))
여러 문제가 있긴햇는데. 이 코드를 쓴다.
img = cv2.imread(‘cloth.jpg’, 0)
blur = cv2.GaussianBlur(img,(5,5),0)
#배경가장자리에서 색깔구하기.
df = pd.DataFrame(blur)
row_border_min = min(df.iloc[0].values)
column_border_min = min(df[0].values)
blur = cv2.GaussianBlur(img,(5,5),0)
if min(row_border_min, column_border_min) == 255:
ret3,th3 = cv2.threshold(blur,250,255,cv2.THRESH_BINARY_INV)
else:
ret3,th3 = cv2.threshold(blur,min(row_border_min, column_border_min),255,cv2.THRESH_BINARY_INV)
pil_image=Image.fromarray(th3)
image = pil_image.filter(ImageFilter.ModeFilter(size=13))
낫배드하다
Good
import sys
import numpy as np
import skimage.color
import skimage.filters
import skimage.io
import skimage.viewer
#$1 $2
print(sys.argv[1])
print(sys.argv[2])
# get filename, sigma, and threshold value from command line
filename = sys.argv[1]
sigma = float(2)
t = float(0.8)
# read and display the original image
image = skimage.io.imread(fname=filename)
#viewer = skimage.viewer.ImageViewer(image)
#viewer.show()
# blur and grayscale before thresholding
blur = skimage.color.rgb2gray(image)
blur = skimage.filters.gaussian(blur, sigma=sigma)
# perform inverse binary thresholding
mask = blur < t
#save
skimage.io.imsave(sys.argv[2],mask)