OpenCV 이미지 코딩 실천 실현

원본 그림:

그림 정 보 를 볼 수 있 습 니 다.그림 은 816*2100 픽 셀 의 그림 입 니 다.

python 코드:

import cv2
import numpy as np
import matplotlib.pyplot as plt
 
img = cv2.imread('11.jpg', 0)
img1 = img.astype('float')
img_dct = cv2.dct(img1)
img_dct_log = np.log(abs(img_dct))
img_recor = cv2.idct(img_dct)
recor_temp = img_dct[0:100,0:100]
recor_temp2 = np.zeros(img.shape)
recor_temp2[0:100,0:100] = recor_temp
print recor_temp.shape
print recor_temp2.shape
img_recor1 = cv2.idct(recor_temp2)
plt.subplot(221)
plt.imshow(img)
plt.title('original')
plt.subplot(222)
plt.imshow(img_dct_log)
plt.title('dct transformed')
plt.subplot(223)
plt.imshow(img_recor)
plt.title('idct transformed')
plt.subplot(224)
plt.imshow(img_recor1)
plt.title('idct transformed2')
 
plt.show()
100*100 DCT 계수 하나만 추출 한 후 효과:


800*1000 의 DCT 계 수 를 사용 하면:

그림 의 디 테 일이 좀 더 풍부 해 진 것 을 볼 수 있 습 니 다.

import cv2
import numpy as np
import matplotlib.pyplot as plt
 
img = cv2.imread('11.jpg', 0)
img1 = img.astype('float')
img_dct = cv2.dct(img1)
img_dct_log = np.log(abs(img_dct))
img_recor = cv2.idct(img_dct)
recor_temp = img_dct[0:800,0:1000]
recor_temp2 = np.zeros(img.shape)
recor_temp2[0:800,0:1000] = recor_temp
print recor_temp.shape
print recor_temp2.shape
img_recor1 = cv2.idct(recor_temp2)
plt.subplot(221)
plt.imshow(img)
plt.title('original')
plt.subplot(222)
plt.imshow(img_dct_log)
plt.title('dct transformed')
plt.subplot(223)
plt.imshow(img_recor)
plt.title('idct transformed')
plt.subplot(224)
plt.imshow(img_recor1)
plt.title('idct transformed2')
 
plt.show()
816*1200 의 DCT 계 수 를 사용 하면:

이미지 가 원래 의 품질 로 회복 되 었 음 을 알 수 있다.

분석 코드:
img_dct 는 dct 변환 후의 행렬 을 저장 합 니 다.imgdct_log 는 행렬 의 요소 로 먼저 절대 치 를 취하 고 대수 의 행렬 을 구한다.
img_dct_log = np.log(abs(img_dct))
그러면 대수의 밑 은 얼마 인가요?
출력 imgdct_log 와 abs(imgdct)보 세 요:

인쇄 결과:

그 중에서 9.45971865 e+04=9.45971865 x 10^4=94597.1865 는 과학 계수 법 을 나타 낸다.

우 리 는 밑 에서 e 를 취 할 때 만 대응 하 는 대수 가 문제 출력 요구 에 부합 되 는 것 을 보 았 기 때문에 python numpy.log 함 수 는 자연 상수 e 를 땅 으로 하 는 대수 입 니 다.
여기 서 OpenCV 가 이미지 디 코딩 실천 을 실현 하 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 OpenCV 이미지 디 코딩 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 바 랍 니 다!

좋은 웹페이지 즐겨찾기