전공 과목 이수2👨‍💻/디지털영상처리

다양한 영상처리 기법을 트랙바로 조절해보기

천숭이 2021. 11. 5. 21:46

< 히스토그램,언샤프,시그마,스케일 트랙바로 조절 >

 

 

 

lut함수 없이 -> 따라서 he트랙바 조절시 변화 없음

import cv2 as cv
import numpy as np
import time

def printImgAtt (string):
    global garo
    global saero
    print("\n" + string)
    data = eval(string) # eval(문자열) - 실행가능한 문자열을 바로 실행시켜주는 함수
    print(' type :', type(data))           # imge type =  <class 'numpy.ndarray'>
    print(' shape = ', data.shape)      # 영상 어레이의 크기 알아내기. image shape =  (세로, 가로, 3). (행, 열, 채널)
    saero = data.shape[0]
    garo = data.shape[1]
    print(' data type = ', data.dtype) # 어레이 요소의 데이터 타입 알아내기. uint8 = unsigned 8비트.
    print(' total frame = ',videoCapture.get(cv.CAP_PROP_FRAME_COUNT) )
    if len(data.shape) >= 2:
        print(' row = ', data.shape[0])  # shape는 tuple이다. 원소는 []로 지정. 리스트도 []로 지정한다.
        print(' column = ', data.shape[1])  # 열의 수.
        if len(data.shape) == 3:
            print(' channel = ', data.shape[2])  # 채널의 수. 칼라 영상이면 3. 모도 영상이면 1.


Path = "d:/dip/"
Name = 'the_return_of_the_king.avi'
Name = 'polor_express.avi'

FullName = Path+Name
videoCapture = cv.VideoCapture(FullName)
success, frame = videoCapture.read()
printImgAtt('frame')
total_frames = int(videoCapture.get(cv.CAP_PROP_FRAME_COUNT))



# 직접 HE 처리 알고리즘을 coding 하여 히스토그램 평활화를 칼라 영상에 대해 처리하는 방법의 한 사례를 보인다
#   1) np.histogram()를 이용해 히스토그램(DF: Distribution Function)을 구한다.
#   2) 연산을 통해 CDF(Cumulative DF)를 구하고,
#   3) 총 화소수로 나누어 NCDF(Normalized CDF)를 구하고,
#   4) 여기에 255를 구하여 mapping LUT 테이블를 구한다.
#   5) Python 함수, matplotlib.pyplot.hist를 이용하여 영상의 히스토그램을 그린다.
#       https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html?highlight=pyplot%20hist#matplotlib.pyplot.hist

def callBack_HeWeight(pos):
    pass

def callBack_sigma(pos):
    pass


def callBack_scale(pos):
    pass


def callBack_position(pos):
    global orgindex
    orgindex = cv.getTrackbarPos('position', win_name)



win_name = 'video processing app'
cv.namedWindow(win_name)
# 트랙바 생성
cv.createTrackbar('HE wgt', win_name, 0, 100, callBack_HeWeight)   # HeWeight
cv.createTrackbar('sigma', win_name, 0, 7, callBack_sigma)
cv.createTrackbar('scale',win_name,0, 5, callBack_scale)
cv.createTrackbar('position',win_name, 0, total_frames,callBack_position)

count=0
while success:
    bar1 = cv.getTrackbarPos('HE wgt', win_name) ###
    bar2 = cv.getTrackbarPos('sigma', win_name) ###
    bar3 = cv.getTrackbarPos('scale', win_name) ###

    success, frame = videoCapture.read()    # 다음 프레임을 읽어온다.
    b, g, r = cv.split(frame)
    #img = cv.merge([r, g, b])
    img = cv.merge([b, g, r])   # 순서 안바꿔야함
    imgC = img.copy()  # img의 복사본을 하나 저장해 둔다.
    imgG = cv.cvtColor(img, cv.COLOR_RGB2GRAY)
    hist, bins = np.histogram(imgC, 256, [0, 255])  # 히스토그램 데이터를 hist에 반환. bins는 용처가 없다.
    cdf = hist.cumsum()  # 누적분포함수, Cumulative Distribution Function
    #cdf_normalized = hist.max() * cdf / cdf.max()
    cdf_normalized = cdf / cdf.max()  # 0~1 범위의  정규화된 누적분포함수, NCDF
    #mapping = cdf * 255 / cdf[255]
    mapping = cdf_normalized * 255 / cdf_normalized[255]
    LUT = mapping.astype('uint8')  # Look Up Table - 256바이트 크기. 화소 값 변환 테이블.
    #print(LUT)
    imgCeq = LUT[imgC]  # 3채널 칼라 영상에 대한 LUT 기반 히스토그램 평활화
    # imgEG = cv.cvtColor(imgCeq, cv.COLOR_RGB2GRAY)  # 히스토그램 평활화된 영상의 그레이 버전. Equalized Gray



    k=bar2*6+1
    blur = cv.GaussianBlur(src=imgCeq, ksize=(k, k),sigmaX=bar2,borderType=cv.BORDER_REPLICATE)
    UnsharpMaskImg = imgCeq - blur  # 고주파 영상
    scale = bar3
    masked = imgCeq + scale * UnsharpMaskImg  ##??
    # um = img + scale * (img - cv.GaussianBlur(src=img, ksize=(k, k), sigmaX=sigma))



    addh = cv.hconcat([frame,masked])
    cv.putText(addh,f'org_index={str(count)}',(10,30),cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.putText(addh,f'sigma={str(bar2)}, scale={str(bar3)}, weight={str(bar1)}',(garo +10,saero-30),cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.imshow(win_name,addh)

    count+=1
    cv.setTrackbarPos('position',win_name,count)
    k = cv.waitKey(1)
    if k==0x1b:
        break
    elif k==0x73:
        cv.imwrite("test",addh)
    elif k==0x20:  # pause
        pass




videoCapture.release()

imgadjust함수 적용 따라서 he트랙바 조절시 변화 나타남

import cv2 as cv
import numpy as np
import time

def printImgAtt (string):
    global garo
    global saero
    print("\n" + string)
    data = eval(string) # eval(문자열) - 실행가능한 문자열을 바로 실행시켜주는 함수
    print(' type :', type(data))           # imge type =  <class 'numpy.ndarray'>
    print(' shape = ', data.shape)      # 영상 어레이의 크기 알아내기. image shape =  (세로, 가로, 3). (행, 열, 채널)
    saero = data.shape[0]
    garo = data.shape[1]
    print(' data type = ', data.dtype) # 어레이 요소의 데이터 타입 알아내기. uint8 = unsigned 8비트.
    print(' total frame = ',videoCapture.get(cv.CAP_PROP_FRAME_COUNT) )
    if len(data.shape) >= 2:
        print(' row = ', data.shape[0])  # shape는 tuple이다. 원소는 []로 지정. 리스트도 []로 지정한다.
        print(' column = ', data.shape[1])  # 열의 수.
        if len(data.shape) == 3:
            print(' channel = ', data.shape[2])  # 채널의 수. 칼라 영상이면 3. 모도 영상이면 1.


def make_lut_for_imadjust(input_range=None, output_range=None, gamma=1):
    src = np.arange(0, 256) / 256
    if input_range is None:
        input_range = (0, 1)
    low_in, high_in = input_range
    #print(low_in, high_in)
    if output_range is None:
        output_range = (0, 1)
    low_out, high_out = output_range
    #print(low_out, high_out)
    dst = np.empty_like(src, np.float64)
    #print(dst.shape)

    for i in range(0, len(src)):
        if src[i] < low_in:
            dst[i] = low_out
        elif src[i] > high_in:
            dst[i] = high_out
        elif gamma == 1:
            dst[i] = (high_out-low_out) / (high_in - low_in) * (src[i] - low_in) + low_out
        else:   # gamma가 1이 아닌 경우 감마 변환 => 아래 루틴은 오류가 있습니다. (0, 1)=> (0, 1) 범위만 됩니다. 주석처리 하였음
            #dst[i] = ((src[i]-low_in) * (high_out-low_out)/(high_in - low_in))**gamma + (low_out-(1-high_in) * (1-high_in + src[i]) )
            dst[i] = (high_out - low_out) * ((src[i] - low_in)/ (high_in - low_in)) ** gamma + low_out      # 올바른 처리
    return src, dst, input_range, output_range, gamma    # dst가 LUT이다.

def imadjust(img, input_range=None, output_range=None, gamma=1):
    _, LUT_float, __, ___, ____ = make_lut_for_imadjust(input_range, output_range, gamma)
    LUT = (255*LUT_float).astype(np.uint8)
    return LUT[img]

Path = "d:/dip/"
Name = 'the_return_of_the_king.avi'
Name = 'polor_express.avi'

FullName = Path+Name
videoCapture = cv.VideoCapture(FullName)
success, frame = videoCapture.read()
printImgAtt('frame')
total_frames = int(videoCapture.get(cv.CAP_PROP_FRAME_COUNT))



# 직접 HE 처리 알고리즘을 coding 하여 히스토그램 평활화를 칼라 영상에 대해 처리하는 방법의 한 사례를 보인다
#   1) np.histogram()를 이용해 히스토그램(DF: Distribution Function)을 구한다.
#   2) 연산을 통해 CDF(Cumulative DF)를 구하고,
#   3) 총 화소수로 나누어 NCDF(Normalized CDF)를 구하고,
#   4) 여기에 255를 구하여 mapping LUT 테이블를 구한다.
#   5) Python 함수, matplotlib.pyplot.hist를 이용하여 영상의 히스토그램을 그린다.
#       https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html?highlight=pyplot%20hist#matplotlib.pyplot.hist

def callBack_HeWeight(pos):
    pass

def callBack_sigma(pos):
    pass


def callBack_scale(pos):
    pass


def callBack_position(pos):
    global orgindex
    orgindex = cv.getTrackbarPos('position', win_name)



win_name = 'video processing app'
cv.namedWindow(win_name)
# 트랙바 생성
cv.createTrackbar('HE wgt', win_name, 5, 100, callBack_HeWeight)   # HeWeight
cv.createTrackbar('sigma', win_name, 0, 7, callBack_sigma)
cv.createTrackbar('scale',win_name,0, 5, callBack_scale)
cv.createTrackbar('position',win_name, 0, total_frames,callBack_position)

count=0
while success:
    bar1 = cv.getTrackbarPos('HE wgt', win_name) ###
    bar2 = cv.getTrackbarPos('sigma', win_name) ###
    bar3 = cv.getTrackbarPos('scale', win_name) ###

    imgC = frame.copy()
    success, frame = videoCapture.read()    # 다음 프레임을 읽어온다.
    dst = imadjust(frame, input_range=(0,1-bar1*0.01), output_range=(0,1), gamma=1)
    # frame[..., ::-1]



    #img = cv.merge([b, g, r])   # 순서 안바꿔야함


    k=bar2*6 + 1
    blur = cv.GaussianBlur(src=dst, ksize=(21, 21),sigmaX=bar2,borderType=cv.BORDER_REPLICATE)
    UnsharpMaskImg = dst - blur  # 고주파 영상
    scale = bar3
    masked = dst + scale * UnsharpMaskImg
    # um = img + scale * (img - cv.GaussianBlur(src=img, ksize=(k, k), sigmaX=sigma))



    addh = cv.hconcat([frame,masked])
    cv.putText(addh,f'org_index={str(count)}',(10,30),cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.putText(addh, f'this_index={str(count)}', (10+garo, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.putText(addh,f'sigma={str(bar2)}, scale={str(bar3)}, weight={str(bar1)}',(garo +10,saero-30),cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.imshow(win_name,addh)

    count+=1
    cv.setTrackbarPos('position',win_name,count)
    k = cv.waitKey(1)
    if k==0x1b:
        break
    elif k==0x73:
        cv.imwrite("test",addh)
    elif k==0x20:  # pause
        pass



videoCapture.release()

 

모든 기능 잘됨 (프레임 트랙바 빼고) , 연산이 많은지 영상이 느림

import cv2 as cv
import numpy as np
import time

def printImgAtt (string):
    global garo
    global saero
    print("\n" + string)
    data = eval(string) # eval(문자열) - 실행가능한 문자열을 바로 실행시켜주는 함수
    print(' type :', type(data))           # imge type =  <class 'numpy.ndarray'>
    print(' shape = ', data.shape)      # 영상 어레이의 크기 알아내기. image shape =  (세로, 가로, 3). (행, 열, 채널)
    saero = data.shape[0]
    garo = data.shape[1]
    print(' data type = ', data.dtype) # 어레이 요소의 데이터 타입 알아내기. uint8 = unsigned 8비트.
    print(' total frame = ',videoCapture.get(cv.CAP_PROP_FRAME_COUNT) )
    if len(data.shape) >= 2:
        print(' row = ', data.shape[0])  # shape는 tuple이다. 원소는 []로 지정. 리스트도 []로 지정한다.
        print(' column = ', data.shape[1])  # 열의 수.
        if len(data.shape) == 3:
            print(' channel = ', data.shape[2])  # 채널의 수. 칼라 영상이면 3. 모도 영상이면 1.


def make_lut_for_imadjust(input_range=None, output_range=None, gamma=1):
    src = np.arange(0, 256) / 256
    if input_range is None:
        input_range = (0, 1)
    low_in, high_in = input_range
    #print(low_in, high_in)
    if output_range is None:
        output_range = (0, 1)
    low_out, high_out = output_range
    #print(low_out, high_out)
    dst = np.empty_like(src, np.float64)
    #print(dst.shape)

    for i in range(0, len(src)):
        if src[i] < low_in:
            dst[i] = low_out
        elif src[i] > high_in:
            dst[i] = high_out
        elif gamma == 1:
            dst[i] = (high_out-low_out) / (high_in - low_in) * (src[i] - low_in) + low_out
        else:   # gamma가 1이 아닌 경우 감마 변환 => 아래 루틴은 오류가 있습니다. (0, 1)=> (0, 1) 범위만 됩니다. 주석처리 하였음
            #dst[i] = ((src[i]-low_in) * (high_out-low_out)/(high_in - low_in))**gamma + (low_out-(1-high_in) * (1-high_in + src[i]) )
            dst[i] = (high_out - low_out) * ((src[i] - low_in)/ (high_in - low_in)) ** gamma + low_out      # 올바른 처리
    return src, dst, input_range, output_range, gamma    # dst가 LUT이다.

def imadjust(img, input_range=None, output_range=None, gamma=1):
    _, LUT_float, __, ___, ____ = make_lut_for_imadjust(input_range, output_range, gamma)
    LUT = (255*LUT_float).astype(np.uint8)
    return LUT[img]

Path = "d:/dip/"
Name = 'the_return_of_the_king.avi'
#Name = 'polor_express.avi'

FullName = Path+Name
videoCapture = cv.VideoCapture(FullName)
success, frame = videoCapture.read()
printImgAtt('frame')
size = (int(videoCapture.get(cv.CAP_PROP_FRAME_WIDTH)),
    int(videoCapture.get(cv.CAP_PROP_FRAME_HEIGHT)))

total_frames = int(videoCapture.get(cv.CAP_PROP_FRAME_COUNT))

fps = videoCapture.get(cv.CAP_PROP_FPS)
fps = fps * 2
CODEC = cv.VideoWriter_fourcc('F', 'M', 'P', '4')
def decode_fourcc(cc):
    return "".join([chr((int(cc) >> 8 * i) & 0xFF) for i in range(4)])

videoWriter = cv.VideoWriter(
    "test_video", CODEC, fps, size)         # 정상 속도. 똑 같은 파일을 만든다.

# 직접 HE 처리 알고리즘을 coding 하여 히스토그램 평활화를 칼라 영상에 대해 처리하는 방법의 한 사례를 보인다
#   1) np.histogram()를 이용해 히스토그램(DF: Distribution Function)을 구한다.
#   2) 연산을 통해 CDF(Cumulative DF)를 구하고,
#   3) 총 화소수로 나누어 NCDF(Normalized CDF)를 구하고,
#   4) 여기에 255를 구하여 mapping LUT 테이블를 구한다.
#   5) Python 함수, matplotlib.pyplot.hist를 이용하여 영상의 히스토그램을 그린다.
#       https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html?highlight=pyplot%20hist#matplotlib.pyplot.hist

def callBack_HeWeight(pos):
    pass

def callBack_sigma(pos):
    pass

def callBack_scale(pos):
    pass

def callBack_position(pos):
    global orgindex
    orgindex = cv.getTrackbarPos('position', win_name)



win_name = 'video processing app'
cv.namedWindow(win_name)
# 트랙바 생성
cv.createTrackbar('HE wgt', win_name, 5, 100, callBack_HeWeight)   # HeWeight
cv.createTrackbar('sigma', win_name, 0, 7, callBack_sigma)
cv.createTrackbar('scale',win_name,0, 5, callBack_scale)
cv.createTrackbar('position',win_name, 0, total_frames,callBack_position)

count=0
while success:
    bar1 = cv.getTrackbarPos('HE wgt', win_name) ###
    bar2 = cv.getTrackbarPos('sigma', win_name) ###
    bar3 = cv.getTrackbarPos('scale', win_name) ###

    imgC = frame.copy()
    success, frame = videoCapture.read()    # 다음 프레임을 읽어온다.

    dst = imadjust(frame, input_range=(0,1-bar1*0.01), output_range=(0,1), gamma=1)
    org = imadjust(frame, input_range=(0,1), output_range=(0,1), gamma=1)  # concat 할때 데이터 형을 맞춰야하기때문에 아무 효과적용안하지만 연산은 같이 수행하는 img변수 선언
    # frame[..., ::-1]

    dst=dst/255
    org=org/255
    np.clip(dst,0,1)  ### 수정한곳
    k=bar2*6 + 1
    blur = cv.GaussianBlur(src=dst, ksize=(k, k), sigmaX=bar2, borderType=cv.BORDER_REPLICATE)
    UnsharpMaskImg = dst - blur  # 고주파 영상
    scale = bar3
    masked = dst + scale * UnsharpMaskImg


    addh = cv.hconcat([org,masked])
    cnt = int(videoCapture.get(cv.CAP_PROP_POS_FRAMES))
    cv.putText(addh,f'org_index={str(cnt)}',(10,30),cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.putText(addh, f'this_index={str(count)}', (10+garo, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.putText(addh,f'sigma={str(bar2)}, scale={str(bar3)}, weight={str(bar1)}',(garo +10,saero-30),cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.imshow(win_name,addh)

    count+=1
    cv.setTrackbarPos('position',win_name,count)
    k = cv.waitKey(1)
    if k==0x1b:   # 'esc'
        break
    elif k==0x73:  # 's'
        forsave = cv.hconcat([org * 255, masked * 255])
        cv.putText(forsave, f'org_index={str(cnt)}', (10, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
        cv.putText(forsave, f'this_index={str(count)}', (10 + garo, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
        cv.putText(forsave, f'sigma={str(bar2)}, scale={str(bar3)}, weight={str(bar1)}', (garo + 10, saero - 30),
                   cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)

        cv.imwrite("test.png",forsave)
        videoWriter

    elif k==0x20:  # pause
        cv.waitKey()


videoCapture.release()

 

결론같은 코드

import cv2 as cv
import numpy as np

def printImgAtt (string):
    global garo
    global saero
    print("\n" + string)
    data = eval(string) # eval(문자열) - 실행가능한 문자열을 바로 실행시켜주는 함수
    print(' type :', type(data))           # imge type =  <class 'numpy.ndarray'>
    print(' shape = ', data.shape)      # 영상 어레이의 크기 알아내기. image shape =  (세로, 가로, 3). (행, 열, 채널)
    saero = data.shape[0]
    garo = data.shape[1]
    print(' data type = ', data.dtype) # 어레이 요소의 데이터 타입 알아내기. uint8 = unsigned 8비트.
    print(' total frame = ',videoCapture.get(cv.CAP_PROP_FRAME_COUNT) )
    if len(data.shape) >= 2:
        print(' row = ', data.shape[0])  # shape는 tuple이다. 원소는 []로 지정. 리스트도 []로 지정한다.
        print(' column = ', data.shape[1])  # 열의 수.
        if len(data.shape) == 3:
            print(' channel = ', data.shape[2])  # 채널의 수. 칼라 영상이면 3. 모도 영상이면 1.

def make_lut_for_imadjust(input_range=None, output_range=None, gamma=1):
    src = np.arange(0, 256) / 256
    if input_range is None:
        input_range = (0, 1)
    low_in, high_in = input_range
    if output_range is None:
        output_range = (0, 1)
    low_out, high_out = output_range
    dst = np.empty_like(src, np.float64)

    for i in range(0, len(src)):
        if src[i] < low_in:
            dst[i] = low_out
        elif src[i] > high_in:
            dst[i] = high_out
        elif gamma == 1:
            dst[i] = (high_out-low_out) / (high_in - low_in) * (src[i] - low_in) + low_out
        else:
            dst[i] = (high_out - low_out) * ((src[i] - low_in)/ (high_in - low_in)) ** gamma + low_out      # 올바른 처리
    return src, dst, input_range, output_range, gamma    # dst가 LUT이다.

def imadjust(img, input_range=None, output_range=None, gamma=1):
    _, LUT_float, __, ___, ____ = make_lut_for_imadjust(input_range, output_range, gamma)
    LUT = (255*LUT_float).astype(np.uint8)
    return LUT[img]



Path = "d:/dip/"
Name = 'the_return_of_the_king.avi'
#Name = 'polor_express.avi'
FullName = Path+Name
videoCapture = cv.VideoCapture(FullName)
success, frame = videoCapture.read()

printImgAtt('frame')                                                    # 영상 정보 출력

total_frames = int(videoCapture.get(cv.CAP_PROP_FRAME_COUNT))           # 전체 프레임 구하기

fps = videoCapture.get(cv.CAP_PROP_FPS)                                 # 영상의 원래 속도로 동영상 저장
CODEC = cv.VideoWriter_fourcc('I','4','2','0')

size = (int(videoCapture.get(cv.CAP_PROP_FRAME_WIDTH)),
    int(videoCapture.get(cv.CAP_PROP_FRAME_HEIGHT)))

videoWriter = cv.VideoWriter(
    "Heq+UnMasking Video.avi", CODEC, fps, size)         # 정상 속도. 똑같은 파일을 만든다.

def callBack_HeWeight(pos):
    pass

def callBack_sigma(pos):
    pass

def callBack_scale(pos):
    pass

def callBack_position(pos):
    global orgindex
    orgindex = cv.getTrackbarPos('position', win_name)


win_name = 'video processing app'
cv.namedWindow(win_name)
# 트랙바 생성
cv.createTrackbar('HE wgt', win_name, 5, 100, callBack_HeWeight)   # HeWeight
cv.createTrackbar('sigma', win_name, 0, 7, callBack_sigma)
cv.createTrackbar('scale',win_name,0, 5, callBack_scale)
cv.createTrackbar('position',win_name, 0, total_frames,callBack_position)

count=0
flag=0
while success:
    bar1 = cv.getTrackbarPos('HE wgt', win_name) ###
    bar2 = cv.getTrackbarPos('sigma', win_name) ###
    bar3 = cv.getTrackbarPos('scale', win_name) ###

    imgC = frame.copy()
    success, frame = videoCapture.read()    # 다음 프레임을 읽어온다.

    dst = imadjust(frame, input_range=(0,1-(bar1/2)*0.01), output_range=(0,1), gamma=1)
    org = imadjust(frame, input_range=(0,1), output_range=(0,1), gamma=1)  # concat 할때 데이터 형을 맞춰야하기때문에 아무 효과적용안하지만 연산은 같이 수행하는 img변수 선언
    # frame[..., ::-1]

    dst=dst/255
    org=org/255
    np.clip(dst,0,1)
    k=bar2*6 + 1
    blur = cv.GaussianBlur(src=dst, ksize=(k, k), sigmaX=bar2, borderType=cv.BORDER_REPLICATE)
    UnsharpMaskImg = dst - blur  # 고주파 영상
    scale = bar3
    masked = dst + scale * UnsharpMaskImg

    maskedC=masked.copy()
    cnt = int(videoCapture.get(cv.CAP_PROP_POS_FRAMES))
    cv.putText(org,f'org_index={str(cnt)}',(10,30),cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.putText(masked, f'this_index={str(count)}', (10, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.putText(masked,f'sigma={str(bar2)}, scale={str(bar3)}, weight={str(bar1)}',(10,saero-20),cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    addh = cv.hconcat([org,masked])
    cv.imshow(win_name,addh)

    maskedC = (maskedC * 255)
    cv.putText(maskedC, f'this_index={str(count)}', (10, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    cv.putText(maskedC, f'sigma={str(bar2)}, scale={str(bar3)}, weight={str(bar1)}', (10, saero - 20),
               cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
    videoWriter.write((maskedC).astype(np.uint8))  # 동영상이 잘 저장이 안됨

    count+=1
    cv.setTrackbarPos('position',win_name,count)

    k = cv.waitKey(1)
    if k==0x1b:   # 'esc'
        break
    elif k==0x73:  # 's'
        forsave = cv.hconcat([org * 255, masked * 255])
        cv.putText(forsave, f'org_index={str(cnt)}', (10, 30), cv.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
        cv.putText(forsave, f'this_index={str(count)}', (10 + garo, 30), cv.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2) ## 연산된 영상의 프레임 찾아보기
        cv.putText(forsave, f'sigma={str(bar2)}, scale={str(bar3)}, weight={str(bar1)}', (garo + 10, saero - 30),
                   cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
        cv.imwrite("tmp.png",forsave)

    elif k==0x20:  # pause
        cv.waitKey()

videoCapture.release()