MATLAB matlab图像压缩程序--采用嵌入式小波零树编码算法源码

news2024/11/16 17:56:20

MATLAB matlab图像压缩程序--采用嵌入式小波零树编码算法源码

function varargout = ezw(varargin)
% EZW MATLAB code for ezw.fig
%      EZW, by itself, creates a new EZW or raises the existing
%      singleton*.
%
%      H = EZW returns the handle to a new EZW or the handle to
%      the existing singleton*.
%
%      EZW('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in EZW.M with the given input arguments.
%
%      EZW('Property','Value',...) creates a new EZW or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ezw_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ezw_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help ezw

% Last Modified by GUIDE v2.5 02-May-2018 09:41:42

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ezw_OpeningFcn, ...
                   'gui_OutputFcn',  @ezw_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before ezw is made visible.
function ezw_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to ezw (see VARARGIN)

% Choose default command line output for ezw
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ezw wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ezw_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on selection change in dim.
function dim_Callback(hObject, eventdata, handles)
% hObject    handle to dim (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns dim contents as cell array
%        contents{get(hObject,'Value')} returns selected item from dim


% --- Executes during object creation, after setting all properties.
function dim_CreateFcn(hObject, eventdata, handles)
% hObject    handle to dim (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in times.
function times_Callback(hObject, eventdata, handles)
% hObject    handle to times (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns times contents as cell array
%        contents{get(hObject,'Value')} returns selected item from times


% --- Executes during object creation, after setting all properties.
function times_CreateFcn(hObject, eventdata, handles)
% hObject    handle to times (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- 选择图片按钮
function button1_Callback(hObject, eventdata, handles)
% hObject    handle to button1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

filter = { ...
        '*.bmp; *.jpg; *.gif; *.png; *.tif', '所有图像文件 (*.bmp; *.jpg; *.gif; *.png; *.tif)'; ...
        '*.bmp',  '位图文件 (*.bmp)'; ...
        '*.jpg', 'JPEG文件 (*.jpg)'; ...
        '*.gif', 'GIF文件 (*.gif)'; ...
        '*.png', '图元文件 (*.png)'; ...
        '*.*',  '所有文件 (*.*)' ...
};

%弹出选择图片文件的对话框
[filename, pathname, filterindex] = uigetfile(filter, '选择图片');
global X;

if filename == 0%未选择图片
    return;
end
X = imread([pathname filename]);

if numel(size(X))> 2
    X=rgb2gray(X);%如果是彩色的转成灰度图
end

global fileSizeIn;
%显示原图大小
d = dir([pathname filename]);
fileSizeIn = d.bytes / 1024;
set(handles.size1, 'vis', 'on');
set(handles.size1, 'String', [sprintf('%.2f', fileSizeIn) ' KB']);

axes(handles.axes1);%这句是定位到对应的坐标轴
imshow(X);
title('原图');


% --- 压缩图片按钮
function button2_Callback(hObject, eventdata, handles)
% hObject    handle to button2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global X;
if  isempty(X)
    msgbox('请先选择图片');
    return;
end

global dim; %变换级数
dim = get(handles.dim, 'value');
global r c;
[r,c] = size(X);
x = modmat(X);
[rowX, colX] = size(x);

maxDim = min(log2(rowX), log2(colX));
if dim > maxDim
    msgbox(['该图像分解级数最大为' num2str(maxDim) ',请重新选择']);
    return ;
end

scanTimes = get(handles.times, 'value');
global scf;%解码时逐层显示用到
[coef,scf]=myWavedec2(x,dim,'db1');
%转换成系数矩阵
cAll = cell2mat(coef,dim);

global row col;
[row, col] = size(cAll);

%获取阈值
maxDecIm = max(max(abs(cAll)));
T = zeros(1, scanTimes);
T(1) = 2 ^ floor(log2(maxDecIm));
%其他层的阈值
for i = 2 : scanTimes
    T(i) = T(i - 1) / 2;
end

%编码
[CodeList,LenSubCL,QuantiFlagList,LenSubQFL] = ezwcode(cAll,T,scanTimes,handles);
fileSizeOut = getEncodedSize(LenSubCL, LenSubQFL, scanTimes);

%解码
DecodeMat = ezwdecode(T(1),scanTimes,CodeList,LenSubCL,QuantiFlagList,LenSubQFL,handles);

%在size2上显示输出文件大小
set(handles.size2, 'vis', 'on');
set(handles.size2, 'String', [sprintf('%.2f', fileSizeOut) ' KB']);

global Y;
psnrV = psnr(X, Y);
ssimV = ssim(X, Y);
global fileSizeIn;
text7content = ['压缩比:' sprintf('%.2f', fileSizeIn / fileSizeOut) [' : 1']];
text7content = [text7content char(13,10)' 'PSNR:' sprintf('%.2f', psnrV) [' dB']];
text7content = [text7content char(13,10)' 'SSIM:' sprintf('%.2f', ssimV)];
set(handles.text7, 'vis', 'on');
set(handles.text7, 'string', text7content);

set(handles.news, 'string', ['进度条:已完成']);


% --- 保存图片按钮
function button3_Callback(hObject, eventdata, handles)
% hObject    handle to button3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global Y

filter = { ...
        '*.bmp; *.jpg; *.gif; *.png; *.tif', '所有图像文件 (*.bmp; *.jpg; *.gif; *.png; *.tif)'; ...
        '*.bmp',  '位图文件 (*.bmp)'; ...
        '*.jpg', 'JPEG文件 (*.jpg)'; ...
        '*.gif', 'GIF文件 (*.gif)'; ...
        '*.png', '图元文件 (*.png)'; ...
        '*.*',  '所有文件 (*.*)' ...
};
[filename ,pathname]=uiputfile(filter,'保存');
imwrite(Y, [pathname, filename]);

执行测试程序:

clc
clear
global row col dim;
dim = 5;
times = 10;
X = imread('lena-256.bmp');
figure(1)
imshow(X);
[coef,scf]=myWavedec2(X,dim,'db1');
x = cell2mat(coef,dim);
FlagX = sign(x);
[row,col] = size(x);
MaxX = max(max(abs(x)));
T(1) = 2^floor(log2(MaxX));
for i = 2:times
    T(i) = T(i-1)/2;
end
[CodeList,LenSubCL,QuantiFlagList,LenSubQFL] = ezwcode(x,T,times);
DecodeMat = ezwdecode(T(1),times,CodeList,LenSubCL,QuantiFlagList,LenSubQFL);
cell = mat2cell(DecodeMat,dim,scf);
xrec=myWaverec2(cell,scf,dim,'db1');
y = uint8(xrec);
figure(2)
imshow(y);
imwrite(y, ['D:\', '3.jpg']);
msgbox('保存成功');

如需整套源码可点击链接自行下载:

MATLABmatlab图像压缩程序-采用嵌入式小波零树编码算法源码资源-CSDN文库icon-default.png?t=N5K3https://download.csdn.net/download/m0_71122770/87952162

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/695520.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【裸机开发】GPT 定时器(三) —— 使用GPT实现高精度延时

延时最简单粗暴的方式就是使用空循环来延时,依赖的是时钟主频(默认是396M)来计数,一旦修改了 6ull 的时钟主频,延时效果就会存在偏差。 因此我们可以使用 EPIT 或者 GPT 的计数功能实现高精度延时,EPIT 是…

电气设备无线测温技术的优势有哪些?安科瑞 许敏

摘 要: 无线测温技术以其安装方便灵活、测温精度高、安全可靠、环境适应性好、便于集中管理等优点, 解决了电气设备长期带电运行状态下的温度在线监测问题, 提高了电气设备的运行可靠性, 在电力行业得到了广泛的应用。本文主要介…

将当前conda环境导出为yaml文件

conda环境的转移和复制 conda导出已有环境,环境会被保存在environment.yaml文件中。 conda env export > environment.yaml 当我们想再次创建该环境,或根据别人提供的.yaml文件复现环境时,就可以通过下面的命令来复现安装环境了。 conda …

【深度学习】Stable Diffusion

Stable Diffusion原理: https://zhuanlan.zhihu.com/p/632866251 训练过程: 文生图方法: 图生图方法:

CSS实现多头像叠加ui效果

第一种实现方式 简单粗暴直接使用margin-right实现&#xff0c;缺点是第一行右侧最右边头像溢出容器&#xff0c;代码中的三行注释的代码放开后可解决这个问题。 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8">&…

SQLyog登录错误解决

sqlyog登录错误号码2058解决 登录本地MySQL数据库 Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Users\Administrator>mysql -u root -p Enter password: **** Welcome to the MySQL monitor. Commands end with ; or \…

windows10 Linux子系统 Ubuntu 文件互相访问

ubuntu 访问Windows windows的磁盘被挂载到了/mnt下&#xff0c;可以看到我的电脑的c,d,e,f盘&#xff0c; windows 访问 ubuntu 在文件夹输入\wsl$ 再点击Ubuntu-22.04,进入文件夹

CSS 弹性布局

提示&#xff1a;这章比较重要&#xff0c;做复杂页面时经常会用到&#xff01;会不断更新❗ 文章目录 前言主轴和侧轴flex-direction 主轴方向flex-wrap 折行justify-content 主轴排列方式flex-start&#xff1a;默认左对齐flex-end&#xff1a;右对齐center&#xff1a;居中s…

如何在Maven中发布项目到Nexus私有服务器

本篇环境 nexus-3.55.0-01&#xff0c; Nexus安装在本地服务器 http://localhost:8081/maven-3.9.2 发布步骤 在项目机器的Maven的 settings.xml 配置Nexus的账号/密码 在settings.xml 的 <servers>节点增加 <server> 节点&#xff0c; 配置 Nexus 的登陆账号和…

Java使用pdf模板生成pdf文件

文章目录 前言如何生成pdf文件1. 制作pdf模板2. 填充pdf模板生成文件 前言 有时候&#xff0c;业务中我们需要使用pdf模板生成一份pdf文件。如何生成pdf文件&#xff1f; 如下&#xff0c;我们把左侧的模板生成为右侧的填充文件。 如何生成pdf文件 1. 制作pdf模板 &#xff…

【Linux】C++项目实战-UDP服务器

目录 UDP通信函数解析代码举例 广播函数解析代码举例 橙色 UDP通信 函数解析 #include <sys/types.h> #include <sys/socket.h> ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);- 参…

避雷器在线测试仪

一、产品概述 KDYZ-306氧化锌避雷器带电测试仪是用于检测氧化锌避雷器电气性能的专用仪器&#xff0c;该仪器适用于各种电压等级的氧化锌避雷器的带电或停电检测&#xff0c;从而及时发现设备内部绝缘受潮及阀片老化等危险缺陷。 仪器操作简单、使用方便&#xff0c;测量全过…

创建固定大小的文件(window 和 UBUNTU)

1、Windows Windows提供了一个强大的文件系统管理工具&#xff1a;fsutil.exe 例&#xff0c;在D盘上创建一个空文件file.txt&#xff0c;文件大小10k字节 fsutil file createnew D:\file.txt 1000 2、Ubuntu Ubuntu创建一个指定大小的文件用全零填充这个文件&#xff0c;例…

vue3 elementplus table合并

table表格下方合并写法&#xff1a; 1&#xff1a;单行合并 &#xff08;1&#xff09;在标签中加入属性 :summary-method"getSummaries":show-summary"true"<el-table:data"data"id"tableRef"ref"tableRef"row-key"…

CentOS Stream 10 计划已启动,即将进入初始化阶段

导读 但初始化的 CentOS Stream 10 暂时不会对外开放&#xff0c;也不会有太多活跃信息。从 Fedora 周期的规律来看&#xff0c;至少还有六个月的时间&#xff0c;CentOS Stream 10 才会正式启动开发流程&#xff0c;接受来自外部的贡献。周五的公告指出&#xff1a;你会看到 C…

智能优化算法改进策略之局部搜索算子(二)—模式搜索(以正余弦算法和灰狼算法为研究对象)

一、改进点基本介绍&#xff1a; 在目前多数的改进智能优化算法文献中&#xff0c;局部搜索算子的形式多种多样。它们主要被用来增强算法的局部开发能力&#xff0c;进而提升它们在优化问题特别在单峰问题上的收敛性能。作为一种高效的直接搜索法&#xff0c;模式搜索目前已被…

freemarker 使用word模板赋值

1. 引包<dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.28</version></dependency>word文档工具类import freemarker.template.Configuration; import freemarker.template.…

将List转化为String 以逗号隔开

一.前言 在我们日常开发中, 在前后端交互的时候 , 会遇到多个id或其他字段存放到一个字段中, 这时我们会遇到一个List(集合)---->String(单个字段), 这时我们要进行操作数据, 使得我们的数据可以保存到数据库中 . 二.解决方法 2.1 利用StringBurilder或StringBuffer pub…

【git】idea怎么去替换git的地址

git 打开git地址添加或者修改git地址 打开git地址 右击->git->repository->remotes 添加或者修改git地址

​BCC Art Looks:BCC+Color Infrared

BCCColor Infrared 彩色红外 Effect Presets & Docs 效果预设和文档 Mocha Mask and Track Mocha 蒙版和跟踪 Mocha Mask... Mocha 蒙版... Pixel Chooser / Mocha 像素选择器 / Mocha PixelChooser - 像素选择器 View Mask / Matte - 查看蒙版/遮罩 Intensity - 强度 Ma…