1.实验目的:
1) 了解MATLAB软件平台的基本操作。
2) 学会应用GUI输入输出图像,能提取图像的直方图信息,并能对图像进行直方图均衡。
3) 基于MATLAB平台实现在GUI内图像间的交互处理。
2.实验内容:
1) 编写MATLAB程序,完成图像的输入,并将该图像的直方图信息输出并保存。
2) 对上述图像进行直方图均衡处理,将得到的新图像与原图进行对比展示。
3) 在1)读入的图像中任意选取一个150*150大小的子区域,输出并保存该子区域的灰度直方图,要求直方图的柱数(bin)为32。
3.具体实验:
构造简单界面
1.图像的输入
function pushbutton1_Callback(hObject, eventdata, handles)
[filename,pathname] = uigetfile;
im = imread([pathname filename]);
axes(handles.axes1);
imshow(im)
handles.im = im;
guidata(hObject,handles)
- 直方图均衡处理
function pushbutton2_Callback(hObject, eventdata, handles)
im2=handles.im;
ws=str2num(get(handles.edit1,'string'));
pos=(get(handles.axes1,'currentpoint'));
posx=floor(pos(1,2));
posy=floor(pos(1,1));
localimage=im2(posx-ws:posx+ws,posy-ws:posy+ws);
axes(handles.axes2)
imshow(localimage)
handles.localimage=localimage;
guidata(hObject,handles)
- 输出子区域的灰度直方图的柱数(bin)为32
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)
im3=handles.localimage;
bin=str2num(get(handles.edit2,'string'));
L=bin;
grap=256/bin;
I=ceil(im3/grap);
I(find(I==0))=1;
h=zeros(L,1);
s=zeros(L,1);
[r,c]=size(I);
n=r*c;
for i=1:r
for j=1:c
d=double(I(i,j));
s(d)=s(d)+1;
end
end
for i=1:L
h(i)=s(i)/n;
end
a = h(1:L/bin:L);
b = s(1:L/bin:L);
axes(handles.axes3);
bar(1:(L/bin):L,a);
4.实验总结
通过本实验,了解了MATLAB软件的基本操作,编写程序完成了图像的输入,以及对输入的图像进行一系列处理,例如,输出图像的直方图信息、对图像进行直方图均衡处理以及在图像中选取子区域,输出子区域的灰度直方图,并且规定了直方图的柱数为确定值。