首页 > 代码库 > 数字信号处理Day2-小波基与规范正交化
数字信号处理Day2-小波基与规范正交化
我们有这么一张灰度图64*64
我们可以定义出4096个基,分别是某一位是0其他是1,在这种情况下,如果我们传输图片,那么就相当于传输原始数据
假设传到一半,网络坏了。
于是,我们得到
我们可以计算原图像和这图像的差距
error = I - I_approx;
distance = sqrt(sum(sum(error.*error)))
distance =
713.5559
假设我们使用Haar基
function h = haar(N) % Assume N is power of 2 h = zeros(N,N); h(1,1:N) = ones(1,N)/sqrt(N); for k = 1:N-1 p = fix(log(k)/log(2)); q = k-(2^p); k1 = 2^p; t1 = N/k1; k2 = 2^(p+1); t2 = N/k2; for i=1:t2 h(k+1,i+q*t1) = (2^(p/2))/sqrt(N); h(k+1,i+q*t1+t2) = -(2^(p/2))/sqrt(N); end end
然后,我们看一下只接受一半的图片可以恢复成什么样子,这个东西可以用到图片压缩(PCA降维)
clear all close all clc % Load image I = double(imread(‘camera.jpg‘)); % Arrange image in column vector I = I(:); % Generate Haar basis vector (rows of H) H = haar(4096); % Project image on the new basis I_haar = H*I; % Remove the second half of the coefficient I_haar(2049:4096) = 0; % Recover the image by inverting change of basis I_haar = H‘*I_haar; % Rearrange pixels of the image I_haar = reshape(I_haar, 64, 64); % Display image figure imshow(I_haar,[]);
效果还可以
error = I - I_haar;
distance = sqrt(sum(sum(error.*error)))
distance =
350.6765
Haar基是正交基
如何将普通基变成正交基呢
线性代数中的拉格慕-施密特正交化就行
function E=gs_orthonormalization(V) % V is a matrix where each column contains the vectors spanning the space of which we want to compute the orthonormal base % E is a matrix where each column contains an ortho-normal vector of the base of the space [numberLines,numberColumns]=size(V); % U is a matrix containing the orthogonal vectors (non normalized) U=zeros(numberLines,numberColumns); for indexColumn=1:numberColumns U(:,indexColumn)=V(:,indexColumn); for index=1:(indexColumn-1) R(index,indexColumn) =U(:,index)‘*V(:,indexColumn); U(:,indexColumn)=U(:,indexColumn)-R(index,indexColumn)*U(:,index); end R(indexColumn,indexColumn)=norm(U(:,indexColumn)); U(:,indexColumn)=U(:,indexColumn)./R(indexColumn,indexColumn); end E=U; return
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。