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.

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

% Last Modified by GUIDE v2.5 14-Sep-2013 20:29:24

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

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

% Update handles structure
guidata(hObject, handles);

% Variables
global I;
[h,w] = size(I);

% Display image
axes(handles.imgContrast);
cla(handles.imgContrast);
image(I);
set(gca,'XTick',[],'YTick',[],'DataAspectRatio',[1 1 1]);

% Display histogram
Ir = I(:,:,1);
Ig = I(:,:,2);
Ib = I(:,:,3);

l = 0:1:255;
VIr = reshape(Ir,(h*(w/3)),1);
HIr = hist(VIr,l);
VIg = reshape(Ig,(h*(w/3)),1);
HIg = hist(VIg,l);
VIb = reshape(Ib,(h*(w/3)),1);
HIb = hist(VIb,l);

axes(handles.histContrast);
cla(handles.histContrast);
hold on;
area(l,HIr,'FaceColor','r');
area(l,HIg,'FaceColor','g');
area(l,HIb,'FaceColor','b');
set(gca,'Color',[40/255 40/255 40/255],'XTick',[],'YTick',[]);

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


% --- Outputs from this function are returned to the command line.
function varargout = IEcontrast_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 on slider movement.
function sldContrast_Callback(hObject, eventdata, handles)
% hObject    handle to sldContrast (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

% Variables
global val_contrast; val_contrast = round(get(handles.sldContrast,'Value'));
global I; global M; M = I;
[h,w] = size(M);

% Slider text
set(handles.sldTxtContrast,'String',val_contrast);

% Change contrast w/ interpolation
if val_contrast ~= 0
    Mr = M(:,:,1);
    Mg = M(:,:,2);
    Mb = M(:,:,3);

    x = [0 64+val_contrast/2 128-val_contrast/2 255];
    y = [0 64-val_contrast/2 128+val_contrast/2 255];

    MCr = floor(interp1(x, y, double(Mr), 'spline'));
    MCg = floor(interp1(x, y, double(Mg), 'spline'));
    MCb = floor(interp1(x, y, double(Mb), 'spline'));

    M(:, :, 1) = MCr;
    M(:, :, 2) = MCg;
    M(:, :, 3) = MCb;
end

% Display image
axes(handles.imgContrast);
cla(handles.imgContrast);
image(M);
set(gca,'XTick',[],'YTick',[],'DataAspectRatio',[1 1 1]);

% Display histogram
l = 0:1:255;
VMr = reshape(MCr,(h*(w/3)),1);
HMr = hist(VMr,l);
VMg = reshape(MCg,(h*(w/3)),1);
HMg = hist(VMg,l);
VMb = reshape(MCb,(h*(w/3)),1);
HMb = hist(VMb,l);

axes(handles.histContrast);
cla(handles.histContrast);
hold on;
area(l,HMr,'FaceColor','r');
area(l,HMg,'FaceColor','g');
area(l,HMb,'FaceColor','b');
set(gca,'Color',[40/255 40/255 40/255],'XTick',[],'YTick',[]);

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


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

% Reset  variables
global I; global M; M = I;
[h,w] = size(I);

% Reset image
axes(handles.imgContrast);
cla(handles.imgContrast);
image(I);
set(gca,'XTick',[],'YTick',[],'DataAspectRatio',[1 1 1]);

% Reset histogram
Ir = I(:,:,1);
Ig = I(:,:,2);
Ib = I(:,:,3);

l = 0:1:255;
VIr = reshape(Ir,(h*(w/3)),1);
HIr = hist(VIr,l);
VIg = reshape(Ig,(h*(w/3)),1);
HIg = hist(VIg,l);
VIb = reshape(Ib,(h*(w/3)),1);
HIb = hist(VIb,l);

axes(handles.histContrast);
cla(handles.histContrast);
hold on;
area(l,HIr,'FaceColor','r');
area(l,HIg,'FaceColor','g');
area(l,HIb,'FaceColor','b');
set(gca,'Color',[40/255 40/255 40/255],'XTick',[],'YTick',[]);

% Reset slider
set(handles.sldContrast,'Value',0);

% Reset slider text
set(handles.sldTxtContrast,'String',0);


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

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


% --- Executes on button press in cancelContrast.
function cancelContrast_Callback(hObject, eventdata, handles)
% hObject    handle to cancelContrast (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