matlab新手求救

各位大大好

小弟第一次寫matlab GUI

想要寫一個簡單的對灰度圖片做去背的小程式

現在卡在建立好的editor輸入值無法丟進去blkproc裡面

想要每次輸入的值不同取代固定的[16 16]

請問blkproc要如何使用呢?

--------------基本程式碼---------------------------------
I = imread('cameraman.tif');
bks = blkproc(I, [16 16], 'min(x(:))');
bg = imresize(bks, size(I), 'bilinear');
tm = imsubtract(I, bg);
figure;
subplot(1, 2, 1); imshow(I); title('原图像')
subplot(1, 2, 2); imshow(tm); title('去掉背景后的图像')
--------------------------------------------------------

-----------------------------GUI程式------------------------
function varargout = GUI(varargin)
% GUI MATLAB code for GUI.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',im,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI_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 GUI

% Last Modified by GUIDE v2.5 01-May-2015 12:30:15

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_OpeningFcn, ...
'gui_OutputFcn', @GUI_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 GUI is made visible.
function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% im 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 GUI (see VARARGIN)

% Choose default command line output for GUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
%在此之下加入你要程式一開始執行時所做的動作


% --- Outputs from this function are returned to the command line.
function varargout = GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% im 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

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% im 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)
bks = blkproc(im, [user_entry_1 user_entry_2], 'min(x(:))');
bg = imresize(bks, size(im), 'bilinear');
tm = imsubtract(im, bg);
figure;
imshow(tm);




% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% im 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)
[FileName,PathName]=uigetfile({'*.tif';'*.jpg';'*.bmp';'*.png';'*.*'},'選擇圖片');
set(handles.editShowPath,'String',[PathName,FileName]);
if isequal([FileName,PathName],[0,0])
msgbox('請檢查路徑')
return;
end
str=[PathName,FileName];
im=imread(str);
axes(handles.axes1);
imshow(im);



function edit_1_Callback(hObject, eventdata, handles)
% hObject handle to edit_1 (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') returns contents of edit_1 as text
% str2double(get(hObject,'String')) returns contents of edit_1 as a double
user_entry_1 = str2double(get(hObject,'string'));
if isnan(user_entry_1)
errordlg('你必須輸入數值','Bad Input','modal')
end
if(isempty(user_entry_1))
set(hObject,'String',0)
end
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function edit_1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double

user_entry_2 = str2double(get(hObject,'string'));
if isnan(user_entry_2)
errordlg('你必須輸入數值','Bad Input','modal')
end
if(isempty(user_entry_2))
set(hObject,'String',0)
end
guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
----------------------------------------------------------

想要取代可是不知道如何表示

有大大可以給方向嗎?

謝謝
2015-05-01 13:33 發佈
文章關鍵字 MATLAB 新手求救
內文搜尋
X
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?