这是用于浏览图像和将图像转换为灰度的matlab gui代码 有人请更正我的代码它不能正常工作,我尝试了很多,但不能得到它在这个错误
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)
set(handles.edit3, 'Visible','off');
% Build the complete filename
global im,im2
[filename, pathname]=uigetfile( {'*.jpg';'*.jpeg';'*.gif';'*.png';'*.bmp'},'Select file');
MyImage = strcat(pathname, filename);
%This code checks if the user pressed cancel on the dialog.
if isequal(filename,0) || isequal(pathname,0)
uiwait(msgbox ('User pressed cancel','failed','modal') )
hold on;
else
uiwait(msgbox('User selected image sucessfully','sucess','modal'));
hold off;
end
im=imread(path);
im=im2double(im); %converts to double
%for backup process :)
imshow(MyImage,'Parent',handles.axes2);
title('INPUT IMAGE WITH NOISE')
handles.output = hObject;
guidata(hObject, handles);
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a fusture version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata,handles,varargin)
global im
imblack=im;
rgb2gray(imblack);
imshow(imblack,'Parent',handles.axes2);
title(' IMAGE AFTER GRAYSCALE CONVERSION')
%gaussian filter:
%set(handles.axes2, 'Visible','off');
%set(handles.edit3, 'Visible','on');
答案 0 :(得分:-1)
这是更新后的代码
/((?:^|>)\s*)[^<>]+May[^<>]+(\s*(?:<|$))/g
1st Capturing group ((?:^|>)\s*)
(?:^|>) Non-capturing group
1st Alternative: ^
^ assert position at start of the string
2nd Alternative: >
> matches the characters > literally
\s* match any white space character [\r\n\t\f ]
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
[^<>]+ match a single character not present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
<> a single character in the list <> literally (case sensitive)
May matches the characters May literally (case sensitive)
[^<>]+ match a single character not present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
<> a single character in the list <> literally (case sensitive)
2nd Capturing group (\s*(?:<|$))
\s* match any white space character [\r\n\t\f ]
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
(?:<|$) Non-capturing group
1st Alternative: <
< matches the characters < literally
2nd Alternative: $
$ assert position at end of the string
g modifier: global. All matches (don't return on first match)
所做的更改
1)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)
set(handles.edit3, 'Visible','off');
% Build the complete filename
global im
[filename, pathname]=uigetfile( {'*.jpg';'*.jpeg';'*.gif';'*.png';'*.bmp'},'Select file');
MyImage = strcat(pathname, filename);
%This code checks if the user pressed cancel on the dialog.
if isequal(filename,0) || isequal(pathname,0)
uiwait(msgbox ('User pressed cancel','failed','modal') )
hold on;
else
uiwait(msgbox('User selected image sucessfully','sucess','modal'));
hold off;
end
im=imread(MyImage);
im=im2double(im); %converts to double
%for backup process :)
imshow(im,'Parent',handles.axes2);
title('INPUT IMAGE WITH NOISE')
handles.output = hObject;
guidata(hObject, handles);
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a fusture version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata,handles,varargin)
global im
imblack=rgb2gray(im);
imshow(imblack,'Parent',handles.axes2);
title(' IMAGE AFTER GRAYSCALE CONVERSION')
%gaussian filter:
%set(handles.axes2, 'Visible','off');
%set(handles.edit3, 'Visible','on');
其中没有名称为im=imread(path);
的变量。
2)path
imshow(MyImage,'Parent',handles.axes2);
包含文件路径。 MyImage
包含图片。
3)im
返回的值必须存储在变量中,以便在下一行中绘制。
4)rgb2gray(imblack);
如果图像从上一个按钮回调中正确传递。然后将显示输入图像而不是灰度。
5)imshow(imblack,'Parent',handles.axes2);
global im,im2
未使用im2
已删除