首页 > 其他分享 >dct

dct

时间:2022-10-02 17:57:04浏览次数:40  
标签:lena plt img idct np dct

import numpy as np
import cv2
import matplotlib.pyplot as plt

dct变换以及逆变换实现

#dct
def dct(img,N):
    G = np.zeros((N,N),dtype=np.float64)
    for i in range(N):
        for j in range(N):
            if(i == 0):
                G[i][j] = np.sqrt(0.5)
            else:
                G[i][j] = np.cos((i+0.5)*j*np.pi/N)
    G = G*(np.sqrt(2/N))
    return G@[email protected]() 

#dct逆变换
def idct(img,N):
    G = np.zeros((N,N),dtype=np.float64)
    for i in range(N):
        for j in range(N):
            if(i == 0):
                G[i][j] = np.sqrt(0.5)
            else:
                G[i][j] = np.cos((i+0.5)*j*np.pi/N)
    G = G*(np.sqrt(2/N))
    return G.transpose()@img@G

先将lena图像做dct变换,然后取dct系数左上角四分之一,对其进行逆变换得到图像

img_lena = cv2.imread("images/lena.jpg",0)
N,N = img_lena.shape
img_lena = np.float64(img_lena)
lena_dct = dct(img_lena,N)
lena_dct1 = lena_dct[0:int(N/4),0:int(N/4)] #取左上角四分之一
lena_idct = idct(lena_dct1,lena_dct1.shape[0]) #dct逆变换
lena_dct = np.log(np.abs(lena_dct)+1)
plt.subplot(131)
plt.title("lena")
plt.imshow(img_lena,cmap='gray')
plt.subplot(132)
plt.title("lena_dct")
plt.imshow(lena_dct,cmap='gray')
plt.subplot(133)
plt.title("lena_idct")
plt.imshow(lena_idct,cmap='gray')
plt.show()

标签:lena,plt,img,idct,np,dct
From: https://www.cnblogs.com/ryuta/p/16749110.html

相关文章

  • DDCTF2019-HOMEBREW-EVENT-LOOP-md
    title:DDCTF2019HOMEBREWEVENTLOOP.mddate:2022-09-2711:42:22tags:[DDCTF2019]homebreweventloop代码审计fromflaskimportFlask,session,request,Re......
  • BJDCTF2020Cookie-is-so-stable-md
    title:BJDCTF2020Cookieissostable.mddate:2022-07-0718:45:14tags:进去之后发现这个好像ssti我们输入{{1+2}}返回这个应该时ssti了然后我们输入{{"".__c......
  • BUUCTF [BJDCTF2020]Easy MD5 详解
    1.题目搞了好久,这道题,就一个简简单单的输入框。2、利用md5($password,true)实现SQL注入打开题目,看上去像sql注入,也有可能是命令执行,或者SSRF,但是注入半天也没什么反应......
  • dct
    https://blog.csdn.net/cv_rsrc/article/details/124697564 https://blog.csdn.net/weixin_48946798/article/details/125451230......
  • BJDCTF2020 Babyrop2
    最近这段时间应该会陆陆续续补上以前做的pwn题的wp,再来复习一下InvolvedKnowledgeFormatStringStackoverflowret2libcChecksecArch:amd64-64-little......
  • [BJDCTF2020]Mark loves cat-1|源代码泄露|变量覆盖
    主要考察了:源代码泄露、变量覆盖共展示了三种获取flag的方式1、打开题目查看未发现有效信息,查看源代码信息,发现返回的dog信息,结果如下:2、使用dirmap进行目录扫描,发现......
  • nerdctl+buildkitd构建容器镜像
    搭建nerdctl+buildkitd环境: 安装nerdctl:wgethttps://github.com/containerd/nerdctl/releases/download/v0.22.0/nerdctl-0.22.0-linux-amd64.tar.gztar-zxvfne......