[제안] input image 이진화 방법 #44
JJayy
started this conversation in
Show and tell
Replies: 1 comment
-
|
retval, image = cv2.threshold(opencv_image, 180, 255, cv2.THRESH_TRUNC) 실험 결과 TOZERO 대신 TRUNC를 쓰는게 일률적으로 더 잘 이진화 된 것 같습니다. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
cv2.threshold(img, threshold_value, value, flag)
cv2를 통해 input image를 이진화 해주고 있습니다.
dataset.py 파일에서 LoadDataset 내의 getitem에 적용했습니다.
def getitem(self, i):
item = self.data[i]
image = Image.open(item["path"])
if self.rgb == 3:
image = image.convert("RGB")
elif self.rgb == 1:
image = image.convert("RGB")#L
else:
raise NotImplementedError
------추가-----------------
numpy_image = np.array(image)
opencv_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGB2GRAY)
retval, image = cv2.threshold(opencv_image, 130, 255, cv2.THRESH_TOZERO)#TRUNC
image = Image.fromarray(image)
---------------------------------
여기서 cv2.threshold 내의 flag 값 변경으로 threshold를 어떻게 적용할 지 정할 수 있습니다.
cv2.threshold(img, threshold_value, value, flag)
img : grayscale 이미지
threshold_value : 픽셀 threshold
value : 적용되는 최대값
flag :
cv2.THRESH_BINARY: 픽셀 값이 threshold_value 보다 크면 value, 작으면 0으로 할당
cv2.THRESH_BINARY_INV: threshold_value보다 크면 0, 작으면 value
cv2.THRESH_TRUNC: 픽셀 값이 threshold_value보다 크면 threshold_value, 작으면 픽셀 값 그대로 할당
cv2.THRESH_TOZERO: 픽셀 값이 threshold_value보다 크면 픽셀 값 그대로, 작으면 0으로 할당
cv2.THRESH_TOZERO_INV: 픽셀 값이 threshold_value보다 크면 0, 작으면 픽셀 값 그대로 할당
저는 TOZERO를 써서 학습을 진행하고 있습니다.
Beta Was this translation helpful? Give feedback.
All reactions