图像变换matlab代码

  • s0_817730
    了解作者
  • matlab
    开发工具
  • 187.5KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-02-23 09:42
    上传日期
对Lena图像进行了傅立叶、离散余弦、哈达玛变换,并通过逆变换观察不同变换下的图像重建质量情况(PSNR)。这写的是GUI界面,门限是指通过设定门限,将系数矩阵中一定百分比(如95%则门限为0.95)的(小值)系数置为0,对图像进行反变换,获得逆变换后图像。
tuxiangbianhuan.zip
  • tuxiangbianhuan
  • experiment1.fig
    37KB
  • experiment1.m
    9.4KB
  • lena.png
    147.7KB
内容介绍
function varargout = experiment1(varargin) % EXPERIMENT1 MATLAB code for experiment1.fig % EXPERIMENT1, by itself, creates a new EXPERIMENT1 or raises the existing % singleton*. % % H = EXPERIMENT1 returns the handle to a new EXPERIMENT1 or the handle to % the existing singleton*. % % EXPERIMENT1('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in EXPERIMENT1.M with the given input arguments. % % EXPERIMENT1('Property','Value',...) creates a new EXPERIMENT1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before experiment1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to experiment1_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 experiment1 % Last Modified by GUIDE v2.5 18-May-2018 19:10:11 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @experiment1_OpeningFcn, ... 'gui_OutputFcn', @experiment1_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 experiment1 is made visible. function experiment1_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 experiment1 (see VARARGIN) % Choose default command line output for experiment1 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes experiment1 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = experiment1_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 button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) image=imread('lena.png'); axes(handles.axes1); imshow(image); title('Lena 原图'); % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %傅立叶变换 image=imread('lena.png'); fourier = fft2(image); shiftfft = fftshift(fourier); Re = real(shiftfft); % 取傅立叶变换的实部 Im = imag(shiftfft); % 取傅立叶变换的虚部 Spectrum = sqrt(Re.^2+Im.^2); % 计算频谱幅值 spectrum_norm = (Spectrum-min(min(Spectrum)))/(max(max(Spectrum))-min(min(Spectrum)))*255;%归一化 axes(handles.axes2); imshow(spectrum_norm); % 显示原图像的频谱 title('傅立叶变换频谱图') set(handles.edit1,'string',''); set(handles.edit2,'string',''); % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) image=imread('lena.png'); fourier = fft2(image); shiftfft = fftshift(fourier); Re = real(shiftfft); Im = imag(shiftfft); Spectrum = sqrt(Re.^2+Im.^2); % 计算频谱幅值 spectrum_norm = (Spectrum-min(min(Spectrum)))/(max(max(Spectrum))-min(min(Spectrum)))*255;%归一化 Size=size(image); height=Size(1); width=Size(2); Spectrum2=sort(reshape(Spectrum,[1,width*height]));%排序 thre_ratio = str2double(get(handles.edit1,'string'));%门限 threshold=Spectrum2(round(width*height*thre_ratio)); %找到阈值 for p=1:height for j=1:width if Spectrum(p,j)<=threshold Re(p,j)=0; Im(p,j)=0; end end end refigure=ifft2(ifftshift(Re+1j*Im)) ; axes(handles.axes2); imshow(refigure/255); title('逆变换图像'); PSNR = psnr(image,uint8(refigure)); set(handles.edit2,'string',PSNR); % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) image=imread('lena.png'); DCT=dct2(image); %离散余弦变换 axes(handles.axes2); imshow(abs(DCT),[0 255]); title('离散余弦变换频谱图') set(handles.edit1,'string',''); set(handles.edit2,'string',''); % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) image=imread('lena.png'); DCT=dct2(image); Size=size(DCT); height=Size(1); width=Size(2); DCT_sort=sort(reshape(DCT,1,width*height));%排序 thre_ratio = str2double(get(handles.edit1,'string'));%门限 threhold=DCT_sort(round(width*height*thre_ratio)); %找到阈值 DCT(abs(DCT)<threhold)=0; refigure=idct2(DCT); axes(handles.axes2); imshow(refigure,[0 255]); title('逆变换图像'); PSNR = psnr(image,uint8(refigure)); %计算PSNR set(handles.edit2,'string',PSNR); % --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) image=imread('lena.png'); H=hadamard(512); image=double(image); DHT=H*image*H./(512^2); axes(handles.axes2); imshow(DHT*2^10,[0,255]); title('哈达玛变换') set(handles.edit1,'string',''); set(handles.edit2,'string',''); % --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) image=imread('lena.png'); H=hadamard(512); image=double(image); DHT=H*image*H./(512^2); Size=size(image); height=Size(1); width=Size(2); DHT_sort=sort(reshape(DHT,1,width*height)); %排序 thre_ratio = str2double(get(handles.edit1,'string'));%门限 threshold=abs(DHT_sort(round(width*height*thre_ratio))); %找到阈值 DHT(abs(DHT)<=threshold)=0; refigure=H*DHT*H; axes(handles.axes2); imshow(refigure,[0,255]); title('逆变换图像'); PSNR = psnr(uint8(image),uint8(refigure)); %计算PSNR set(handles.edit2,'string',PSNR); function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') retu
评论
    相关推荐
    • Matlab合集
      冈萨雷斯数字图像处理MATLAB版.中文版+数字图像处理第二版中文版(冈萨雷斯)+MATLAB-R2014a完全自学一本通+MATLAB R2016a完全自学一本通 素材文件+[模式识别与智能计算:MATLAB技术实现(第2版)].杨淑莹.扫描版
    • Matlab教程
      MatlaB经典ppt,主要讲解了MatlaB的入门知识,图形编程以及仿真。
    • matlab 课件
      matlab 功能很强大,本课件详细的介绍了matlab在科学计算中的应用。
    • matlab编译器
      matlab编译为exe文件所需要的文件; 使用时解压,将解压后文件拖入至matlab命令行即可
    • matlab
      matlab的基础知识进行介绍
    • MatLab
      “#MatLab
    • MATLAB编译器
      基于MATLAB 2018b版本介绍MATLAB编译器。介绍如何利用编译器将MATLAB代码编译为独立应用程序或组件,并在没有安装MATLAB的计算机上进行部署。
    • matlab入门
      matlab的入门教程,很值得仔细看看,对提高matlab能力有帮助
    • matlab
      matlab经典课堂讲义
    • matlab
      matlab