Code covered by the BSD License  

Highlights from
Image Enhancer

image thumbnail

Image Enhancer

by

 

A simple GUI image editing application which is able to compress images and apply effects to them.

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

% Last Modified by GUIDE v2.5 16-Jul-2013 22:32:18

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @IEcrop_OpeningFcn, ...
                   'gui_OutputFcn',  @IEcrop_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 IEcrop is made visible.
function IEcrop_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 IEcrop (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = IEcrop_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)


% --- Executes when selected object is changed in cropMethod.
function cropMethod_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in cropMethod 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)

global M; global I; M = I;

if hObject == handles.square
    set(handles.panCustom,'Visible','off');
    set(handles.panSquare,'Visible','on');
    set(handles.txtSize,'Visible','off');    
    infoSquare = imread('ico/square.jpg'); axes(handles.imgSquare); image(infoSquare); set(gca,'DataAspectRatio',[1 1 1]); axis off;
elseif hObject == handles.custom
    sent1 = 'The size of this image is ';
    [h,w] = size(M);
    h = num2str(h);
    w = num2str(w/3);
    sent2 = ' x ';
    set(handles.panSquare,'Visible','off');
    set(handles.panCustom,'Visible','on');
    set(handles.txtSize,'Visible','on'); set(handles.txtSize,'String',[sent1,w,sent2,h]);
    xAxis = imread('ico/xAxis.jpg'); axes(handles.imgX); image(xAxis); set(gca,'DataAspectRatio',[1 1 1]); axis off;
    yAxis = imread('ico/yAxis.jpg'); axes(handles.imgY); image(yAxis); set(gca,'DataAspectRatio',[1 1 1]); axis off;
end


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

global xFrom; xFrom = str2double(get(handles.xFrom,'String'));

% --- Executes during object creation, after setting all properties.
function xFrom_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xFrom (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 xTo_Callback(hObject, eventdata, handles)
% hObject    handle to xTo (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 xTo as text
%        str2double(get(hObject,'String')) returns contents of xTo as a double

global xTo; xTo = str2double(get(handles.xTo,'String'));

% --- Executes during object creation, after setting all properties.
function xTo_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xTo (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 yFrom_Callback(hObject, eventdata, handles)
% hObject    handle to yFrom (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 yFrom as text
%        str2double(get(hObject,'String')) returns contents of yFrom as a double

global yFrom; yFrom = str2double(get(handles.yFrom,'String'));

% --- Executes during object creation, after setting all properties.
function yFrom_CreateFcn(hObject, eventdata, handles)
% hObject    handle to yFrom (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 yTo_Callback(hObject, eventdata, handles)
% hObject    handle to yTo (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 yTo as text
%        str2double(get(hObject,'String')) returns contents of yTo as a double

global yTo; yTo = str2double(get(handles.yTo,'String'));

% --- Executes during object creation, after setting all properties.
function yTo_CreateFcn(hObject, eventdata, handles)
% hObject    handle to yTo (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 customOK.
function customOK_Callback(hObject, eventdata, handles)
% hObject    handle to customOK (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global M; global xFrom; global xTo; global yFrom; global yTo;
M = M(yFrom:yTo,xFrom:xTo,:);

global I; I = M;
uiresume(handles.figure1);
delete(handles.figure1);


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

delete(handles.figure1);


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

global M;
[h,w] = size(M);

if w/3 > h
    out = round((w/3-h)/2);
    set(handles.text2,'String',out);
    M = M(1:h,out:h+out,:);
elseif h > w/3
    out = round((h-w/3)/2);
    set(handles.text2,'String',out);
    M = M(out:out+w/3,1:w/3,:);
elseif w/3 == h
    M = M;
else disp('OMPc! What did you do?');
end

global I; I = M;
uiresume(handles.figure1);
delete(handles.figure1);


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

delete(handles.figure1);

Contact us