⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seamcutgui.m

📁 Using the idea from Seam Carving for Content-Aware Image Resizing, the codes enables a selected im
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = SeamCutGUI(varargin)
% SEAMCUTGUI M-file for SeamCutGUI.fig
%      SEAMCUTGUI, by itself, creates a new SEAMCUTGUI or raises the existing
%      singleton*.
%
%      H = SEAMCUTGUI returns the handle to a new SEAMCUTGUI or the handle to
%      the existing singleton*.
%
%      SEAMCUTGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SEAMCUTGUI.M with the given input arguments.
%
%      SEAMCUTGUI('Property','Value',...) creates a new SEAMCUTGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before SeamCutGUI_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to SeamCutGUI_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 SeamCutGUI

% Last Modified by GUIDE v2.5 18-Dec-2007 18:51:51
%
% Author: Danny Luong
%         http://danluong.com
%
% Last updated: 12/20/07


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


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

% Add toolbar to figure
% set(hObject,'toolbar','figure');

disableButtons(handles);

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes SeamCutGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


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


% --- Executes when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in Reset.
function Reset_Callback(hObject, eventdata, handles)
% hObject    handle to Reset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.X = handles.rgbX;
handles.dispX=handles.X;

[handles.rows handles.cols handles.dim]=size(handles.X);


handles.E=findEnergy(handles.X);    %Finds the gradient image
handles.dispE=handles.E;
handles.dispS=zeros(handles.rows,handles.cols);

set(handles.popupmenu1,'Value',1);
set(handles.checkbox1,'Value',0);

ImagePlot(handles);
guidata(hObject,handles);

% --- Executes on button press in RemVerSeam.
function RemVerSeam_Callback(hObject, eventdata, handles)
% hObject    handle to RemVerSeam (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.rows>1&&handles.cols>1)
    
    disableButtons(handles);
    set(handles.figure1,'Pointer','watch');
    refresh(SeamCutGUI) %redraws the GUI to reflect changes

    %find "energy map" image used for seam calculation given the gradient image
    handles.S=findSeamImg(handles.E);

    %find seam vector given input "energy map" seam calculation image
    handles.SeamVector=findSeam(handles.S);

    %remove seam from image
    handles.X=SeamCut(handles.X,handles.SeamVector);
    handles.E=SeamCut(handles.E,handles.SeamVector);
    handles.S=SeamCut(handles.S,handles.SeamVector);
    
    %updates size of image
    [handles.rows handles.cols handles.dim]=size(handles.X);

    %plot image
    if get(handles.checkbox1,'Value')==1
        %creates image with seam line for visualization purposes
        handles.dispX=SeamPlot(handles.X,handles.SeamVector);
        handles.dispE=SeamPlot(handles.E,handles.SeamVector);
        handles.dispS=SeamPlot(handles.S,handles.SeamVector);
    else
        handles.dispX=handles.X;
        handles.dispE=handles.E;
        handles.dispS=handles.S;
    end

    ImagePlot(handles);
    
    set(handles.figure1,'Pointer','arrow');
    enableButtons(handles); 
    %updates handles struct
    guidata(hObject,handles);
end

% --------------------------------------------------------------------
function Open_Callback(hObject, eventdata, handles)
% hObject    handle to OpenImg (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function File_Callback(hObject, eventdata, handles)
% hObject    handle to File (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)





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

% 
% NewVal = get(hObject,'String');
% handles.edit1 = NewVal;
% guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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
% 
% NewVal = str2double(get(hObject,'String'));
% handles.edit2 = NewVal;
% 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




% --- Executes on button press in RemHorizSeam.
function RemHorizSeam_Callback(hObject, eventdata, handles)
% hObject    handle to RemHorizSeam (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.rows>1&&handles.cols>1)
    
    disableButtons(handles);
    set(handles.figure1,'Pointer','watch');
    refresh(SeamCutGUI) %redraws the GUI to reflect changes

    %for horizontal seam, take normal and gradient image and transpose.
    % NOTE: transpose of a 3-dim image must be done using permute fn. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -