function varargout = seamCarving_GUI(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @seamCarving_GUI_OpeningFcn, ...
'gui_OutputFcn', @seamCarving_GUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1}) %nargin 输入变量个数
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
% --- Executes just before seamCarving_GUI is made visible.
function seamCarving_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
global img; %image
global mask; %markup mask
if exist('ocean.bmp','file')~=0
img=imread('ocean.bmp');
axes(handles.img);
imshow(img);
mask=zeros(size(img,1),size(img,2));
handles.cwidth.String=num2str(size(img,2));
handles.cheight.String=num2str(size(img,1));
else
img=[];
handles.retarget_btn.Enable='off';
handles.markup_plus_btn.Enable='off';
handles.markup_minus_btn.Enable='off';
end
ha=axes('units','normalized','pos',[0 0 1 1]);
uistack(ha,'down');
ii=imread('background.jpg');
%设置程序的背景图
image(ii);
colormap gray
set(ha,'handlevisibility','off','visible','off');
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = seamCarving_GUI_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in browse_btn.
function browse_btn_Callback(hObject, eventdata, handles)
global img; %image
global mask; %markup mask
global filename;
global pathname;
[filename, pathname] = ...
uigetfile({'*.jpg';'*.bmp';'*.png';'*.jpeg'},'Image File Selector');
if filename~=0
img=imread(fullfile(pathname,filename));
mask=zeros(size(img,1),size(img,2));
handles.cwidth.String=num2str(size(img,2));
handles.cheight.String=num2str(size(img,1));
axes(handles.img); %show it
imshow(img);
handles.markup_plus_btn.Enable='on';
handles.markup_minus_btn.Enable='on';
handles.save_btn.Enable='off';
handles.remove_btn.Enable='on';
handles.amplification_btn.Enable='on';
handles.retarget_btn.Enable='on';
end
% --- Executes on button press in markup_plus_btn.
function markup_plus_btn_Callback(hObject, eventdata, handles)
global img;
global mask;
h=figure;
imshow(img);
title('Specify a polygonal region of interest (ROI)');
bw=roipoly;
mask=mask+(double(bw)*+100000000000000000);
close(h);
% --- Executes on button press in markup_minus_btn.
function markup_minus_btn_Callback(hObject, eventdata, handles)
global img;
global mask;
h=figure;
imshow(img);
title('Specify a polygonal region of interest (ROI)');
bw=roipoly; %get ROI
mask=mask+(double(bw)*-100000000000000000000);
close(h);
function nwidth_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function nwidth_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function nheight_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function nheight_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function cwidth_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function cwidth_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function cheight_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function cheight_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in getenergy.
function getenergy_Callback(hObject, eventdata, handles)
global img;
global mask;
global out_img;
global Gauss;
global Fuction;
if(Fuction==2)
out_img=getHOG(img,mask,Gauss);
else
out_img=getGradient(img,mask,Gauss);
end
ave=2*mean(out_img(:));
out_img=out_img/ave;
h=figure;
imshow(out_img);
title('Results');
handles.save_btn.Enable='on';
% --- Executes on button press in retarget_btn.
function retarget_btn_Callback(hObject, eventdata, handles)
global img;
global mask;
global out_img;
global Checkbox_;
global Gauss;
global Fuction;
if length(handles.nwidth.String)<=1 || length(handles.nheight.String)<=1
msgbox('Please specify valid dimensions of the image','Error','error');
else
w=round(str2double(handles.nwidth.String));
h=round(str2double(handles.nheight.String));
if w<=0 || h<=0
msgbox('Please specify non-zero dimensions of the image','Error','error');
else
out_img=seamCarving(img,mask,w,h,Checkbox_,Gauss,Fuction);
h=figure;
imshow(out_img);
title('Results');
handles.save_btn.Enable='on';
end
end
% --- Executes on button press in save_btn.
function save_btn_Callback(hObject, eventdata, handles)
global out_img;
global filename;
global pathname;
[filename,pathname]=uiputfile({'*.jpg';'*.bmp';'*.png';'*.jpeg'},'Image File save');
imwrite(out_img,fullfile(pathname,filename)); %save image
msgbox('saved!');
% --- Executes on button press in remove_btn.
function remove_btn_Callback(hObject, eventdata, handles)
global img;
global mask;
global out_img;
global Checkbox_;
global Gauss;
global Fuction;
if mask==zeros(size(img,1),size(img,2))
msgbox('You have not choose the mask area','Error','error');
else
out_img=objectRemove(img,mask,Checkbox_,Gauss,Fuction);
figure(4);
imshow(out_img);
title('Remove');
handles.save_btn.Enable='on';
end
% --- Executes on button press in RetargetOneSide_btn.
function RetargetOneSide_btn_Callback(hObject, eventdata, handles)
global img;
global mask;
global out_img;
global Checkbox_;
global Gauss;
global Fuction;
if length(handles.nwidth.String)<=1 || length(handles.nheight.String)<=1
msgbox('Please specify valid dimensions of the image','Error','error');
else
w=round(str2double(handles.nwidth.String)); %get new width
h=round(str2double(handles.nheight.String)); %get new height
if w<=0 || h<=0
msgbox('Please specify non-zero dimensions of the image','Error','error');
else
out_img=retargetOneSide(img,mask,w,h,Checkbox_,Gauss,Fuction);
h=figure;
imshow(out_img);
title('Results');
handles.save_btn.Enable='on';
end
end
% --- Executes on button press in amplification_btn.
function amplification_btn_Callback(hObject, eventdata, handles)
global img;
global mask;
global out_img;
global Checkbox_;
global Gauss;
global Fuction;
out_img=amplification(img,mask,Checkbox_,Gauss,Fuction);
figure(4);
imshow(out_img);
title('Amplification');
handles.amplification_btn.Enable='on';
function figure1_CreateFcn(hObject, eventdata, handles)
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
delete(hObject);
% --- Executes on button press in process.
function process_Callback(hObject, eventdata, handles)
global Checkbox_;
if(get(hObject,'Value'))
Checkbox_=1;
else
Checkbox_=0;
end
% --- Executes on selection change in fuction.
function fuction_Callback(hObject, eventdata, handles)
global Fuction;
Fuction=get(hObject,'Value');
% --- Executes during object creation, after setting all properties.
function fuction_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), g