【Matlab】实验⼆GUI图像灰度变换
1.实验⽬的:
1) 了解MATLAB软件平台的基本操作。
2) 学会应⽤GUI输⼊输出图像,能提取图像的直⽅图信息,并能对图像进⾏直⽅图均衡。
3) 基于MATLAB平台实现在GUI内图像间的交互处理。
2.实验内容:
1) 编写MATLAB程序,完成图像的输⼊,并将该图像的直⽅图信息输出并保存。
2) 对上述图像进⾏直⽅图均衡处理,将得到的新图像与原图进⾏对⽐展⽰。
3) 在1)读⼊的图像中任意选取⼀个⼤⼩150×150的⼦区域,输出并保存该⼦区域的灰度直⽅图,要求直⽅图的柱数(bin)为32。
3.具体实验:
界⾯设计如下:
具体代码如下:
<1>读⼊原图像:
% --- 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)
im=imread('D:\cc_test.jpg');
axes(handles.axes1);
imshow(im)
handles.im=im;
guidata(hObject,handles)
<2>直⽅图均衡处理:
% --- 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)
x = rgb2gray(handles.im);
y = histeq(x);
guidata(hObject,handles);
axes(handles.axes5);
imshow(y);
<3>⼦区域图像显⽰:
% --- 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)
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.axes3);
imshow(localimage)
handles.localimage = localimage;
guidata(hObject,handles)
<4>输出各图像的直⽅图:
matlab直方图
% --- 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)
x = rgb2gray(handles.im);
y = histeq(x);
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);
long = str2num(get(handles.edit2,'String'));
axes(handles.axes2);
imhist(x,long);
axes(handles.axes6);
imhist(y,long);
axes(handles.axes4);
imhist(localimage,long);
实验结果:
实验总结:
通过这次实验学会了使⽤imhist函数绘制直⽅图的⽅法,但是在实验过程中也遇到了⼀些问题,在“⼦区域显⽰”那块浪费了很多时间,⼀直报以下图⽚的那种错误:
但是在机房实验时并未发⽣这种错误,个⼈初步认为是matlab版本的问题才会报错。在新版本的matlab上并未报错。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。