当前位置:文档之家› 简单数字图像处理系统

简单数字图像处理系统

数字图像课程设计简单数字图像处理系统function varargout = untitled(varargin)% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @untitled_OpeningFcn, ...'gui_OutputFcn', @untitled_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);if nargin && ischar(varargin{1})= str2func(varargin{1});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before untitled is made visible.function untitled_OpeningFcn(hObject, eventdata, handles, varargin) %界面初始化函数setappdata,'I',0);% 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 untitled (see VARARGIN)% Choose default command line output for untitled= hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes untitled wait for user response (see UIRESUME)% uiwait;% --- Outputs from this function are returned to the command line.function varargout = untitled_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 structurevarargout{1} = ;% --------------------------------------------------------------------function m_file_Callback(hObject, eventdata, handles)% hObject handle to m_file (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function my_file_open_Callback(hObject, eventdata, handles)global I;[FileName,PathName] = uigetfile('*.bmp;*.jpg;*.tiff;*.gif');%弹出对话框得到打开的路径I=imread(strcat(PathName,FileName));%打开得到的路径下的文件imshow(I)setappdata,'I',I);% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function my_file_save_Callback(hObject, eventdata, handles)global I;%这个是要保存的东西,一般是global的[FileName,PathName] = uiputfile('*.bmp;*.jpg;*.tiff;*.gif');%弹出对话框的到保存的路径imwrite(I,strcat(PathName,FileName));%存储到该路径下%uigetfile Open standard dialog box for retrieving files%saveas(figure_handle,filename,fileformat)%saveas(gcf,'picname','jpg')%if isequal(filename,0)||isequal(pathname,0)% return; %如果点了取消%else% fpath=fullfile(pathname,filename); %获取全路径的另一种方法%end%I=getappdata,'I');%imwrite(I,fpath); %保存图片% --------------------------------------------------------------------function my_file_exit_Callback(hObject, eventdata, handles)close; %退出% hObject handle to my_file_exit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function my_file_print_Callback(hObject, eventdata, handles)% hObject handle to my_file_print (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (seeGUIDATA)C:\Users\swj\Documents\MATLAB\% --------------------------------------------------------------------function m_image_Callback(hObject, eventdata, handles)% hObject handle to m_image (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function m_image_2bw_Callback(hObject, eventdata, handles)% hObject handle to m_image_2bw (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function m_image_tongji_Callback(hObject, eventdata, handles)%图像直方图的统计与绘制直方图反应灰度值与像素个数的关系%[FileName,PathName] = uigetfile('*.bmp;*.jpg;*.tiff;*.gif');%弹出对话框得到打开的路径%I=imread(strcat(PathName,FileName));%打开得到的路径下的文件global I;A = rgb2gray(I); %将真彩色图像转换为灰度图像%figure('Name', '显示灰度图像')subplot(2,2,1);imshow(I);title('原图');%imshow(A);[J,I] = histeq(A);%imshow(J);subplot(2,2,2);imhist(A,64); %提取图像中的直方图信息title('直方图的统计');%BW= bwperim(A,8);%figure('name','周长')%imshow(BW);% --------------------------------------------------------------------function m_image_mianji_Callback(hObject, eventdata, handles)global I;BW = bwperim(im2bw(I)); %显示二值化后的图像Area = bwarea(BW)[labeled,numobjects]=bwlabel(BW,8);BW=regionprops(labeled, 'basic')BW = ;set,'String',strcat('区域面积 = ',num2str(BW)));% --------------------------------------------------------------------function m_image_zhouchang_Callback(hObject, eventdata, handles)% hObject handle to m_image_zhouchang (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function juli_Callback(hObject, eventdata, handles)% hObject handle to juli (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function m_change_Callback(hObject, eventdata, handles)% hObject handle to m_change (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function m_change_ft_Callback(hObject, eventdata, handles) %普通傅里叶变换与逆变换global I; %傅里叶变换是将时域信号分解为不同频率的正弦和/余弦和的形式subplot(2,2,1); %其通过在时域和频域来回切换图像imshow(I); title('原图');f=rgb2gray(I);A=fftshift(fft2(f));%figure;subplot(2,2,2);imshow(log(abs(A)),[8,10]);title('傅里叶变换图像');% --------------------------------------------------------------------function m_change_fft_Callback(hObject, eventdata, handles) %快速普通傅里叶变换与逆变换global I;subplot(2,2,1),imshow(I);title('原图');f=rgb2gray(I);%subplot(2,2,2),imshow(f);F=fft2(f); %二维傅里叶变换FS=fftshift(F);S=log(1+abs(FS)); %频谱subplot(2,2,3);imshow(S,[]);title('快速傅里叶变换图像');fr=real(ifft2(ifftshift(FS))); %二维傅里叶逆变换ret=im2uint8(mat2gray(fr));subplot(2,2,4),imshow(ret);title('快速傅里叶逆变换图像');% --------------------------------------------------------------------function m_change_DCT_Callback(hObject, eventdata, handles) %离散余弦变换global I;subplot(2,2,1),imshow(I);title('原图');A= rgb2gray(I); %将其转为灰度B = dct2(A); %==二维dct变换,即离散余弦变换subplot(2,2,2),imshow(B);title('离散余弦变换图像')% --------------------------------------------------------------------function m_change_xiaobo_Callback(hObject, eventdata, handles) %小波变换global I; %定义图片数据存储的全局变量subplot(2,2,1);imshow(I);title('原始图像');A=rgb2gray(I);subplot(2,2,2);imshow(A);title('黑白图像');[m,n]=wavedec2(A,3,'');%多尺度二维小波分解B=appcoef2(m,n,'',2);%将低频取出进行二层的小波变换subplot(2,2,3);imshow(B);title('二维离散小波变换2层');C=appcoef2(m,n,'',3);%将低频取出进行二层的小波变换subplot(2,2,4);imshow(C);title('二维离散小波变换3层');function m_division_Callback(hObject, eventdata, handles)% hObject handle to m_division (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function m_division_line_Callback(hObject, eventdata, handles)%图像分割点线global I;A= rgb2gray(I); %将彩色图转化成灰度图B=immultiply(A,;subplot(2,2,1);imshow(I);title('原图');subplot(2,2,2);imshow(B);title('点分割图片');% --------------------------------------------------------------------function m_division_edge_Callback(hObject, eventdata, handles) %图像边缘检测提取图像高频分量global I; %定义图片数据存储的全局变量A=rgb2gray(I); % 图片用的是灰度图像%[x,y]=size(A);%BW=edge(A);BW1=edge(A,'Canny',, %edge调用Canny为检测算子判别阈值为BW2=edge(A,'log',,; % 做阈值为的高斯—拉普拉斯(Log)算法把subplot(2,2,1),imshow(A);title('原图');subplot(2,2,3),imshow(BW1);title('Canny算子边缘检测图像阀值');subplot(2,2,4),imshow(BW2);title('拉普拉斯算子边缘检测图像阀值');% --------------------------------------------------------------------function m_zengqiang_Callback(hObject, eventdata, handles)% hObject handle to m_zengqiang (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function m_zengqiang_zhongzhi_Callback(hOguidebject, eventdata, handles) %中值滤波使图像在某一部分的频率信息通过,其他过低或过高都抑制global I; %滤除噪声滤除噪声保持图像边缘J=rgb2gray(I); %将真彩色图像转换为灰度图像A= medfilt2(J); %对躁声进行中值滤波subplot(2,2,1);imshow(I);title('原图');subplot(2,2,2);imshow(A);title('中值滤波后图像');% --------------------------------------------------------------------function m_zengqiang_ditong_Callback(hObject, eventdata, handles) %低通滤波让图像使高频分量抑制,低频分量通过global I; %定义图片数据存储的全局变量A=rgb2gray(I); %将真彩色图像转换为灰度图像subplot(2,2,1);imshow(I);title('原图');s=fftshift(fft2(A));[a,b]=size(s);a0=round(a/2);b0=round(b/2);d=10;for i=1:afor j=1:bdistance=sqrt((i-a0)^2+(j-b0)^2);if distance<=d h=1;else h=0;end;s(i,j)=h*s(i,j);end;end;s=uint8(real(ifft2(ifftshift(s))));subplot(2,2,2);imshow(s);title('低通滤波后图像');% --------------------------------------------------------------------function m_zengqiang_gaotong_Callback(hObject, eventdata, handles) %高通滤波让图像使低频分量抑制,高频分量通过global I; %定义图片数据存储的全局变量subplot(2,2,1);imshow(I);title('原图');A=rgb2gray(I); %将真彩色图像转换为灰度图像s=fftshift(fft2(A));[a,b]=size(s);a0=round(a/2);b0=round(b/2);d=10;p=;q=;for i=1:afor j=1:bdistance=sqrt((i-a0)^2+(j-b0)^2);if distance<=d h=0;else h=1;end;s(i,j)=h*s(i,j);end;end;s=uint8(real(ifft2(ifftshift(s))));subplot(2,2,2);imshow(s);title('高通滤波后图像');% --------------------------------------------------------------------function m_zengqiang_junhenghua_Callback(hObject, eventdata, handles) %直方图均衡化将原始图像的直方图变换为均匀分布的形式global I; %定义图片数据存储的全局变量subplot(2,2,1);imshow(I);title('原图');A=rgb2gray(I);%将真彩色图像转换为灰度图像B=histeq(A); %直方图均衡化缺省64subplot(2,2,2);imshow(B);title('直方图均衡化后图像'); %subplot(2,2,3);imhist(B);title('直方图均衡化后图像');。

相关主题