tensorflow에서 openCV 없이 clahe 적용하는 방법
- 서문 -
Clahe란?
Adaptive Histogram Equalization (AHE) : 이미지 전처리 기법으로 이미지의 contrast 를 늘리는 방법이다.
AHE의 변형이 Contrast limited adaptive histogram equalization (CLAHE) 방법. CLAHE는 AHE 의 중대한 문제점인 noise amplification 을 해결하기 위해 contrast limit 을 활용한다. (자세한 설명은 구글이)
이미지를 tensor형식으로 읽어와서 열심히 코딩했는데 나중에 clahe를 적용하려 보니
openCV에선 numpy형식만 받는다고 한다. 변환하긴 귀찮으니 openCV 안 쓰고 적용하는 법을 알아보려 한다.
방법 1. image data generator사용할 때 clahe 적용하는 방법 - 애초에 IDG로 작업할때 추가해주면 됨
def AHE(img):
img_adapteq = exposure.equalize_adapthist(img, clip_limit=0.03)
return img_adapteq
datagen = ImageDataGenerator(rotation_range=30, horizontal_flip=0.5, preprocessing_function=AHE)
(https://stackoverflow.com/questions/69223239/whats-the-easiest-way-to-add-clahe-to-data-augmentation)
What's the easiest way to add CLAHE to Data Augmentation?
I am new to deep learning and currently attempting to train a classifier with CT-Scans. I am using the Keras ImageDataGenerator to perform on-the-fly augmentation on my images and enable a more rob...
stackoverflow.com
방법2. ★ 텐서플로우 라이브러리 사용방법 ( 이쪽이 당연히 편한 부분 )
(https://pypi.org/project/tf-clahe/)
!pip install tf_clahe
Use
import tensorflow as tf
import tf_clahe
img = tf.io.decode_image(tf.io.read_file('./path/to/your/img'))
img_clahe = tf_clahe.clahe(img)