OpenCV 이미지 코딩 실천 실현
![](https://s1.md5.ltd/image/ff07cf8453c3a960799f7c81ac765a79.jpg)
그림 정 보 를 볼 수 있 습 니 다.그림 은 816*2100 픽 셀 의 그림 입 니 다.
![](https://s1.md5.ltd/image/bc0e1a4873a33049dbc6953b73d5dcdd.jpg)
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 계수 하나만 추출 한 후 효과:![](https://s1.md5.ltd/image/51ebbec2a5008a50fe5771e96600433f.jpg)
![](https://s1.md5.ltd/image/478cd1b28da21c093da4a28e988f2fa7.jpg)
800*1000 의 DCT 계 수 를 사용 하면:
![](https://s1.md5.ltd/image/3006a65d6c705fbd1b28fb424e9e7f4a.jpg)
그림 의 디 테 일이 좀 더 풍부 해 진 것 을 볼 수 있 습 니 다.
![](https://s1.md5.ltd/image/3be8816f92256e87895e0e8afa3c31ef.jpg)
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 계 수 를 사용 하면:![](https://s1.md5.ltd/image/9842de21df94f9d74446c474ea404c29.jpg)
이미지 가 원래 의 품질 로 회복 되 었 음 을 알 수 있다.
![](https://s1.md5.ltd/image/027fe74de9438019c65b47594fbc763c.jpg)
분석 코드:
img_dct 는 dct 변환 후의 행렬 을 저장 합 니 다.imgdct_log 는 행렬 의 요소 로 먼저 절대 치 를 취하 고 대수 의 행렬 을 구한다.
img_dct_log = np.log(abs(img_dct))
그러면 대수의 밑 은 얼마 인가요?
출력 imgdct_log 와 abs(imgdct)보 세 요:
![](https://s1.md5.ltd/image/d7a9fc987f308ae5721994888be0954e.jpg)
인쇄 결과:
![](https://s1.md5.ltd/image/ce8e0de325db40087c5b861c788845e5.jpg)
그 중에서 9.45971865 e+04=9.45971865 x 10^4=94597.1865 는 과학 계수 법 을 나타 낸다.
![](https://s1.md5.ltd/image/b427959c09e37d3f945669f3c09d32f3.jpg)
우 리 는 밑 에서 e 를 취 할 때 만 대응 하 는 대수 가 문제 출력 요구 에 부합 되 는 것 을 보 았 기 때문에 python numpy.log 함 수 는 자연 상수 e 를 땅 으로 하 는 대수 입 니 다.
여기 서 OpenCV 가 이미지 디 코딩 실천 을 실현 하 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 OpenCV 이미지 디 코딩 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 바 랍 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Visual Studio 2017에서 OpenCV 템플릿 프로젝트 만들기・Windows 7 Professional 64bit ・Visual Studio 2017 Version 15.9.14 · OpenCV 3.4.1 OpenCV의 도입 방법 등은 아래를 참조하십시오. Visual Stu...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.