ice_stand_alone.m ( File view )

  • By yueqiaohuayuan 2014-11-17
  • View(s):3508
  • Download(s):7
  • Point(s): 3
			function varargout = ice(varargin)
%ICE Interactive Color Editor.
%
%   OUT = ICE('Property Name', 'Property Value', ...) transforms
%   an image's color components based on interactively specified
%   mapping functions. Inputs are Property Name/Property Value pairs: 
%
%     Name            Value
%     ------------    -------------------------------------------------
%     'image'         An RGB or monochrome input image to be transformed
%                     by interactively specified mappings.
%     'space'         The color space of the components to be modified.
%                     Possible values are 'rgb', 'cmy', 'hsi',
%                     'hsv', 'ntsc' (or 'yiq'), 'ycbcr'. When omitted,
%                     the RGB color space is assumed.
%     'wait'          If 'on' (the default), OUT is the mapped input image
%                     and ICE returns to the calling function or workspace
%                     when closed. If 'off', OUT is the handle of the mapped
%                     input image and ICE returns immediately.
%
%   EXAMPLES:
%     ice                                  % Demo curves mode
%     ice('image', f)                      % Map RGB or mono image
%     ice('image', f, 'space', 'hsv')      % Map HSV of RGB image
%     g = ice('image', f, 'wait', 'off');  % Return with handles of g
%
%   ICE displays one popup menu selectable mapping function at a time.
%   Each image component is mapped by a dedicated curve (e.g., R, G,
%   or B) and then bt an all-component curve (e.g., RGB). Each curve's
%   control points are depicted as circles that can be moved, added,
%   or deleted with a three-button mouse:
%
%     Mouse Button    Editing Operation
%     ------------    -------------------------------------------------
%     Left            Move control point by pressing and dragging.
%     Middle          Add and position a control point by pressing
%                     and dragging. (Optionally Shift-Left)
%     Right           Deleted a control point. (Optionally Control-Left)
%
%   Checkboxes determine how  mapping function are computed, whether
%   the input image and reference pseudo- and full-color bars are
%   mapped, and the displayed reference curve information (e.g., PDF):
%
%     Checkbox        Function
%     ------------    -------------------------------------------------
%     Smooth          Checked for cubic spline (smooth curve) interpo-
%                     lation. If unchecked, piecewise linear.
%     Clamp Ends      Checked to force the starting and ending curve
%                     slopes in cubic spline interpolation to 0. No
%                     effect on piecewise linear.
%     Show PDF        Display probablity density function(s) [i.e.,
%                     histogram(s)] of the image components effected by
%                     the mapping function.
%     Show CDF        Display cumulative distributions function(s)
%                     instead of PDFs.
%                     <Note: Show PDF/CDF are mutually exclusive.>
%     Map Image       If checked, image mapping is enabled; else not.
%     Map Bars        If checked, pseudo- and full-color bar mapping is
%                     enabled; else display th eunmapped bars (a gray
%                     wedge and hue wedge, respectively).
%
%   Mapping functions can be initialized via pushbuttons:
%
%     Button          Function
%     ------------    -------------------------------------------------
%     Reset           Init the currently displayed mapping function
%                     and uncheck all curve parameters.
%     Reset All       Initalize all mapping functions.

%   Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
%   Digital Image Processing Using MATLAB, Prentice-Hall, 2004
%   $Revision: 1.2 $  $Date: 2003/02/19 22:10:00 $

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ice_OpeningFcn, ...
                   'gui_OutputFcn',  @ice_OutputFcn, ...
                   'gui_LayoutFcn',  @ice_LayoutFcn, ...
                   'gui_Callback',   []);
if nargin & isstr(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

%-------------------------------------------------------------------%
function ice_OpeningFcn(hObject, eventdata, handles, varargin)
%  When ICE is opened, perform basic initialization (e.g., setup
%  globals, ...) before it is made visible.

% Set ICE globals to defaults.
handles.updown = 'none';            % Mouse updown state
handles.plotbox = [0 0 1 1];        % Plot area parameters in pixels
handles.set1 = [0 0; 1 1];          % Curve 1 control points
handles.set2 = [0 0; 1 1];          % Curve 2 control points
handles.set3 = [0 0; 1 1];          % Curve 3 control points
handles.set4 = [0 0; 1 1];          % Curve 4 control points
handles.curve = 'set1';             % Structure name of selected curve
handles.cindex = 1;                 % Index of selected curve
handles.node = 0;                   % Index of selected control point
handles.below = 1;                  % Index of node below control point
handles.above = 2;                  % Index of node above control point
handles.smooth = [0; 0; 0; 0];      % Curve smoothing states
handles.slope = [0; 0; 0; 0];       % Curve end slope control states
handles.cdf = [0; 0; 0; 0];         % Curve CDF states
handles.pdf = [0; 0; 0; 0];         % Curve PDF states
handles.output = [];                % Output image handle
handles.df = [];                    % Input PDFs and CDFs
handles.colortype = 'rgb';          % Input image color space
handles.input = [];                 % Input image data
handles.imagemap = 1;               % Image map enable
handles.barmap = 1;                 % Bar map enable
handles.graybar = [];               % Pseudo (gray) bar image
handles.colorbar = [];              % Color (hue) bar image

% Process Property Name/Property Value input argument pairs.
wait = 'on';
if(nargin > 3)
    for i = 1: 2: (nargin - 3),
        if nargin - 3 == i break;  end
        switch lower(varargin{
i
})
            case 'image'
            if ndims(varargin{
i + 1
}) == 3
                handles.input = varargin{
i + 1
};
            elseif ndims(varargin{
i + 1
}) == 2
                handles.input = cat(3, varargin{
i + 1
}, ...
                    varargin{
i + 1
}, varargin{
i + 1
});  end;
            handles.input = double(handles.input);
            inputmax = max(handles.input(:));
            if inputmax > 255   handles.input = handles.input / 65535;
            elseif inputmax > 1
            handles.input = handles.input / 255;    end
        
            case 'space'
                handles.colortype = lower(varargin{
i + 1
});
                switch handles.colortype
                    case 'cmy',  list = {
'CMY' 'Cyan' 'Magenta' 'Yellow'
};
                    case {
'ntsc', 'yiq'
}
                        list = {
'YIQ' 'Luminance' 'Hue' 'Saturation'
};
                        handles.colortype = 'ntsc';
                    case 'ycbcr',    list = {
'YCbCr' 'Luminance' 'Blue' ...
                        'Difference'  'Red Difference'
};
                    case 'hsv',  list = {
'HSV' 'Hue' 'Saturation' 'Value'
};
                    case 'hsi',  list = {
'HSI' 'Hue' 'Saturation' 'Intensity'
};
                    otherwise
                        list = {
'RGB' 'Red' 'Green' 'Blue'
};
                        handles.colortype = 'rgb';
                end
                set(handles.component_popup, 'String', list);
            
            case 'wait', wait = lower(varargin{
i + 1
});
        end
    end
end
   
% Create pseudo- and full-color mapping bars (grays and hues). Store a
% color space converted 1x128x3 line of each bar for mapping.
xi = 0: 1/127: 1;          x = 0: 1 / 6: 1;     x = x';
y = [1 1 0 0 0 1 1; 0 1 1 1 0 0 0; 0 0 0 1 1 1 0]';
gb = repmat(xi, [1 1 3]);       cb = interp1q(x, y, xi');
cb = reshape(cb, [1 128 3]);
if ~strcmp(handles.colortype, 'rgb')
    gb = eval(['rgb2' handles.colortype '(gb)']);
    cb = eval(['rgb2' handles.colortype '(cb)']);   end
gb = round(255 * gb);     gb = max(0, gb);      gb = min(255, gb);
cb = round(255 * cb);     cb = max(0, cb);      cb = min(255, cb);
handles.graybar = gb;     handles.colorbar = cb;

% Do color space transforms, clamp to [0, 255], compute histograms
% and cumulative distribution functions, and create output figure.
if size(handles.input, 1)
    if ~strcmp(handles.colortype, 'rgb')
        handles.input = eval(['rgb2' handles.colortype ...
            '(handles.input)']);    end
    handles.input = round(255 * handles.input);
    handles.input = max(0, handles.input);
    handles.input = min(255, handles.input);
    for i = 1: 3
        color = handles.input(:, :, i);
        df = hist(color(:), 0: 255);
        handles.df = [handles.df; df / max(df(:))];
        df = df / sum(df(:));   df = cumsum(df);
        handles.df = [handles.df; df];
    end
    figure;     handles.output = gcf;
end

% Compute ICE's screen position and display image/graph.
set(0, 'Units', 'pixels');      ssz = get(0, 'Screensize');
set(handles.ice, 'Units', 'pixels');
uisz = get(handles.ice, 'Position');
if size(handles.input, 1)
    fsz = get(handles.output, 'Position');
    bc = (fsz(4) - uisz(4)) / 3;
    if bc > 0    bc = bc + fsz(2);
    else bc = fsz(2) + fsz(4) - uisz(4) - 10;  end
    lc = fsz(1) + (size(handles.input, 2) / 4) + (3 * fsz(3) / 4);
    lc = min(lc, ssz(3) - uisz(3) - 10);
    set(handles.ice, 'Position', [lc bc 463 391]);
else
    bc = round((ssz(4) - uisz(4)) / 2) - 10;
    lc = round((ssz(3) - uisz(3)) / 2) - 10;
    set(handles.ice, 'Position', [lc bc uisz(3) uisz(4)]);
end
set(handles.ice, 'Units', 'normalized');
graph(handles);     render(handles);

% Update handles and Make ICE wait before exit if required.
guidata(hObject, h
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 3

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
01.97 kB
0_Read_Me_First.txt5.00 kB2012-02-29|09:51
Contents.m5.98 kB2012-02-29|09:51
Readme.m5.30 kB2012-02-29|09:51
adpmedian.m1.54 kB2012-02-29|09:51
average.m651.00 B2012-02-29|09:51
bayesgauss.m2.96 kB2012-02-29|09:51
bound2eight.m2.99 kB2012-02-29|09:51
bound2four.m2.42 kB2012-02-29|09:51
bound2im.m2.17 kB2012-02-29|09:51
boundaries.m5.64 kB2012-02-29|09:51
bsubsamp.m3.87 kB2012-02-29|09:51
changeclass.m592.00 B2012-02-29|09:51
colorgrad.m2.30 kB2012-02-29|09:51
colorseg.m2.37 kB2012-02-29|09:51
compare.m1.15 kB2012-02-29|09:51
connectpoly.m1.02 kB2012-02-29|09:51
conwaylaws.m799.00 B2012-02-29|09:51
covmatrix.m977.00 B2012-02-29|09:51
dftcorr.m687.00 B2012-02-29|09:51
dftfilt.m882.00 B2012-02-29|09:51
dftuv.m736.00 B2012-02-29|09:51
diameter.m6.47 kB2012-02-29|09:51
endpoints.m874.00 B2012-02-29|09:51
entropy.m1.00 kB2012-02-29|09:51
fchcode.m8.55 kB2012-02-29|09:51
frdescp.m1.42 kB2012-02-29|09:51
fwtcompare.m992.00 B2012-02-29|09:51
gmean.m447.00 B2012-02-29|09:51
gscale.m2.04 kB2012-02-29|09:51
histroi.m920.00 B2012-02-29|09:51
hough.m2.64 kB2012-02-29|09:51
houghlines.m2.82 kB2012-02-29|09:51
houghpeaks.m2.65 kB2012-02-29|09:51
houghpixels.m1.02 kB2012-02-29|09:51
hpfilter.m1.23 kB2012-02-29|09:51
hsi2rgb.m1.94 kB2012-02-29|09:51
huff2mat.m2.46 kB2012-02-29|09:51
huffman.m2.82 kB2012-02-29|09:51
ice.fig45.71 kB2012-02-29|09:51
ice.m26.30 kB2012-02-29|09:51
ice_stand_alone.m46.55 kB2012-02-29|09:51
ifrdescp.m1.38 kB2012-02-29|09:51
ifwtcompare.m1.12 kB2012-02-29|09:51
im2jpeg.m2.90 kB2012-02-29|09:51
im2jpeg2k.m3.97 kB2012-02-29|09:51
imnoise2.m4.20 kB2012-02-29|09:51
imnoise3.m2.12 kB2012-02-29|09:51
improd.m791.00 B2012-02-29|09:51
imratio.m1.30 kB2012-02-29|09:51
imstack2vectors.m1.83 kB2012-02-29|09:51
intline.m1.20 kB2012-02-29|09:51
intrans.m3.25 kB2012-02-29|09:51
invmoments.m3.24 kB2012-02-29|09:51
jpeg2im.m2.41 kB2012-02-29|09:51
jpeg2k2im.m1.90 kB2012-02-29|09:51
lpc2mat.m1.42 kB2012-02-29|09:51
lpfilter.m1.44 kB2012-02-29|09:51
mahalanobis.m1.97 kB2012-02-29|09:51
manualhist.m1.75 kB2012-02-29|09:51
mat2huff.m2.75 kB2012-02-29|09:51
mat2lpc.m1.28 kB2012-02-29|09:51
minperpoly.m7.15 kB2012-02-29|09:51
paddedsize.m1.29 kB2012-02-29|09:51
pixeldup.m950.00 B2012-02-29|09:51
polyangles.m6.14 kB2012-02-29|09:51
princomp.m2.88 kB2012-02-29|09:51
quantize.m1.33 kB2012-02-29|09:51
randvertex.m1.15 kB2012-02-29|09:51
regiongrow.m1.66 kB2012-02-29|09:51
rgb2hsi.m1.46 kB2012-02-29|09:51
rgbcube.m1.98 kB2012-02-29|09:51
signature.m4.45 kB2012-02-29|09:51
specxture.m2.57 kB2012-02-29|09:51
spfilt.m3.78 kB2012-02-29|09:51
splitmerge.m4.13 kB2012-02-29|09:51
statmoments.m1.72 kB2012-02-29|09:51
statxture.m1.55 kB2012-02-29|09:51
strsimilarity.m1.78 kB2012-02-29|09:51
subim.m713.00 B2012-02-29|09:51
twodsin.m1.04 kB2012-02-29|09:51
twomodegauss.m1.16 kB2012-02-29|09:51
unravel.dll7.00 kB2012-02-29|09:51
unravel.m967.00 B2012-02-29|09:51
unravel.mexaxp24.00 kB2012-02-29|09:51
unravel.mexglx18.97 kB2012-02-29|09:51
unravel.mexhpux12.00 kB2012-02-29|09:51
unravel.mexmac8.68 kB2012-02-29|09:51
unravel.mexrs62.71 kB2012-02-29|09:51
unravel.mexsg24.44 kB2012-02-29|09:51
unravel.mexsol8.54 kB2012-02-29|09:51
vistformfwd.m1.66 kB2012-02-29|09:51
wave2gray.m4.67 kB2012-02-29|09:51
waveback.m4.52 kB2012-02-29|09:51
wavecopy.m940.00 B2012-02-29|09:51
wavecut.m1.06 kB2012-02-29|09:51
wavefast.m4.14 kB2012-02-29|09:51
wavefilter.m4.77 kB2012-02-29|09:51
wavepaste.m1.04 kB2012-02-29|09:51
wavework.m3.45 kB2012-02-29|09:51
wavezero.m696.00 B2012-02-29|09:51
x2majoraxis.m3.59 kB2012-02-29|09:51
...
Sponsored links

ice_stand_alone.m (160.12 kB)

Need 3 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D