function out = encoding(m, max_bits, block_size, level)
figure;
imshow(m);
bitctr = 0;
out = 2*ones(1,max_bits);
n_max = floor(log2(abs(max(max(m)'))));
Bits_Header = 0;
Bits_LSP = 0;
Bits_LIP = 0;
Bits_LIS = 0;
out(1,[1 2 3]) = [size(m,1) n_max level]; bitctr = bitctr + 24;
index = 4;
Bits_Header = Bits_Header + 24;
%----------- Initialize LIP, LSP, LIS ----------------
temp = [];
bandsize = 2.^(log2(size(m, 1)) - level + 1);
temp1 = 1 : bandsize;
for i = 1 : bandsize
temp = [temp; temp1];
end
LIP(:, 1) = temp(:);
temp = temp';
LIP(:, 2) = temp(:);
LIS(:, 1) = LIP(:, 1);
LIS(:, 2) = LIP(:, 2);
LIS(:, 3) = zeros(length(LIP(:, 1)), 1);
pstart = 1;
pend = bandsize / 2;
for i = 1 : bandsize / 2
LIS(pstart : pend, :) = [];
pdel = pend - pstart + 1;
pstart = pstart + bandsize - pdel;
pend = pend + bandsize - pdel;
end
LSP = [];
n = n_max;
%coding
while(bitctr < max_bits)
% Sorting Pass
LIPtemp = LIP; temp = 0;
for i = 1:size(LIPtemp,1)
temp = temp+1;
if (bitctr + 1) >= max_bits
if (bitctr < max_bits)
out(length(out))=[];
end
return
end
if abs(m(LIPtemp(i,1),LIPtemp(i,2))) >= 2^n % 1: positive; 0: negative
out(index) = 1; bitctr = bitctr + 1;
index = index +1; Bits_LIP = Bits_LIP + 1;
sgn = m(LIPtemp(i,1),LIPtemp(i,2))>=0;
out(index) = sgn; bitctr = bitctr + 1;
index = index +1; Bits_LIP = Bits_LIP + 1;
LSP = [LSP; LIPtemp(i,:)];
LIP(temp,:) = []; temp = temp - 1;
else
out(index) = 0; bitctr = bitctr + 1;
index = index +1;
Bits_LIP = Bits_LIP + 1;
end
end
LIStemp = LIS; temp = 0; i = 1;
while ( i <= size(LIStemp,1))
temp = temp + 1;
if LIStemp(i,3) == 0
if bitctr >= max_bits
return
end
max_d = func_MyDescendant(LIStemp(i,1),LIStemp(i,2),LIStemp(i,3),m);
if max_d >= 2^n
out(index) = 1; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
x = LIStemp(i,1); y = LIStemp(i,2);
if (bitctr + 1) >= max_bits
if (bitctr < max_bits)
out(length(out))=[];
end
return
end
if abs(m(2*x-1,2*y-1)) >= 2^n
LSP = [LSP; 2*x-1 2*y-1];
out(index) = 1; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
sgn = m(2*x-1,2*y-1)>=0;
out(index) = sgn; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
else
out(index) = 0; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
LIP = [LIP; 2*x-1 2*y-1];
end
if (bitctr + 1) >= max_bits
if (bitctr < max_bits)
out(length(out))=[];
end
return
end
if abs(m(2*x-1,2*y)) >= 2^n
LSP = [LSP; 2*x-1 2*y];
out(index) = 1; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
sgn = m(2*x-1,2*y)>=0;
out(index) = sgn; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
else
out(index) = 0; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
LIP = [LIP; 2*x-1 2*y];
end
if (bitctr + 1) >= max_bits
if (bitctr < max_bits)
out(length(out))=[];
end
return
end
if abs(m(2*x,2*y-1)) >= 2^n
LSP = [LSP; 2*x 2*y-1];
out(index) = 1; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
sgn = m(2*x,2*y-1)>=0;
out(index) = sgn; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
else
out(index) = 0; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
LIP = [LIP; 2*x 2*y-1];
end
if (bitctr + 1) >= max_bits
if (bitctr < max_bits)
out(length(out))=[];
end
return
end
if abs(m(2*x,2*y)) >= 2^n
LSP = [LSP; 2*x 2*y];
out(index) = 1; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
sgn = m(2*x,2*y)>=0;
out(index) = sgn; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
else
out(index) = 0; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
LIP = [LIP; 2*x 2*y];
end
if ((2*(2*x)-1) < size(m) & (2*(2*y)-1) < size(m))
LIS = [LIS; LIStemp(i,1) LIStemp(i,2) 1];
LIStemp = [LIStemp; LIStemp(i,1) LIStemp(i,2) 1];
end
LIS(temp,:) = []; temp = temp-1;
else
out(index) = 0; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
end
else
if bitctr >= max_bits
return
end
max_d = func_MyDescendant(LIStemp(i,1),LIStemp(i,2),LIStemp(i,3),m);
if max_d >= 2^n
out(index) = 1; bitctr = bitctr + 1;
index = index +1;
x = LIStemp(i,1); y = LIStemp(i,2);
LIS = [LIS; 2*x-1 2*y-1 0; 2*x-1 2*y 0; 2*x 2*y-1 0; 2*x 2*y 0];
LIStemp = [LIStemp; 2*x-1 2*y-1 0; 2*x-1 2*y 0; 2*x 2*y-1 0; 2*x 2*y 0];
LIS(temp,:) = []; temp = temp - 1;
else
out(index) = 0; bitctr = bitctr + 1;
index = index +1; Bits_LIS = Bits_LIS + 1;
end
end
i = i+1;
end
% Refinement Pass
temp = 1;
value = floor(abs(2^(n_max-n+1)*m(LSP(temp,1),LSP(temp,2))));
while (value >= 2^(n_max+2) & (temp <= size(LSP,1)))
if bitctr >= max_bits
return
end
s = bitget(value,n_max+2);
out(index) = s; bitctr = bitctr + 1;
index = index +1; Bits_LSP = Bits_LSP + 1;
temp = temp + 1;
if temp <= size(LSP,1)
value = floor(abs(2^(n_max-n+1)*m(LSP(temp,1),LSP(temp,2))));
end
end
n = n - 1;
end
没有合适的资源?快使用搜索试试~ 我知道了~
基于SPIHT-DWT变换的图像压缩解压缩matlab仿真+仿真操作录像
共18个文件
m:11个
bmp:5个
avi:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 58 浏览量
2022-10-16
02:51:42
上传
评论 1
收藏 2.29MB RAR 举报
温馨提示
1.版本:matlab2021a,我录制了仿真操作录像,可以跟着操作出仿真结果 2.领域:图像压缩解压缩 3.内容:基于SPIHT-DWT变换的图像压缩解压缩 4.适合人群:本,硕等教研学习使用
资源推荐
资源详情
资源评论
收起资源包目录
基于SPIHT-DWT变换的图像压缩解压缩matlab仿真.rar (18个子文件)
基于SPIHT-DWT变换的图像压缩解压缩matlab仿真
操作录像0031.avi 12.09MB
data
barbara.bmp 257KB
NEW2.BMP 65KB
cameraman.tif 64KB
lena512.bmp 257KB
lena512_reconstruct2.bmp 257KB
rice.bmp 65KB
func
func_Myappcoef2.m 679B
func_InvWT.m 1KB
func_Mywaverec2.m 156B
func_MyDescendant.m 680B
func_WT.m 919B
descramble.m 283B
encoding.m 7KB
decoding.m 5KB
scramble.m 240B
func_Mywavedec2.m 494B
Runme.m 2KB
共 18 条
- 1
资源评论
- m0_692284842023-12-10资源很赞,希望多一些这类资源。
fpga和matlab
- 粉丝: 15w+
- 资源: 2548
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功