Problem
image에서 egde를 추출할 일이 있었는데, edge는 gray scale이라 1channel만 가지고 있었다. 원본 image에 edge를 추가할 목적이라 1channel의 edge를 3channel로 맞춰주는 작업이 필요했다.
Solution
# original image read
img = cv2.imread('/path/to/image.jpg')
img.shape
# (680,720,3)
# Canny Edge Detection
edges = cv2.Canny(image=img, threshold1=50, threshold2=200)
edges.shape
# (680,720)
# 1channel image to 3channel image
img2 = cv2.merge((edges,edges,edges))
img2.shape
# (680,720,3)
cv2.merge를 이용해서 간단하게 스택을 쌓을 수 있다.
'인공지능 > Python' 카테고리의 다른 글
RuntimeError: stack expects each tensor to be equal size 에러 해결 (0) | 2022.05.16 |
---|---|
change edge thickness (using opencv Morphological Transformations ) (0) | 2022.05.16 |
AttributeError: 'YourDataModule' object has no attribute '_has_prepared_data' 해결방법 (0) | 2022.05.13 |
LightningDataModule을 for loop에서 이용하는 방법 (0) | 2022.05.13 |
Warning: find_unused_parameters=True 해결방법 (DDP programming) (0) | 2022.05.13 |