function RGB=definergb(rgb, default) %DEFINERGB User Graphical Interface to define any RGB color. % % RGB = DEFINERGB(rgb) % % Open a new figure and by mean of four slide controls % allows to define any color in the RGB mode. % The fourth slide control increase or decrease the brigthness. % % rgb is the starting color vector, black ([0 0 0]) if omitted. % RGB is the vector of the three R, G, B values defining a color. % % OK return the specified color. % CANCEL return the original color (rgb). % % % Claudio 7 Feb, 1995. % modified by M. Young 14 Feb, 1995 to put in a color palette to choose a starting color % % % Copyright (c) 1995 by Claudio Rivetti and Mark Young % claudio@alice.uoregon.edu, mark@alice.uoregon.edu % gvar='global Rsl Gsl Bsl Lsl Rvl Gvl Bvl RGBfr RGBtx df;'; global AlexDir Uibgcolor eval(gvar) if nargin <1, rgb=[0 0 0];end if nargin >2, error('Too many input arguments.');end if nargin ==1 df=rgb; else df=default; end if length(rgb) ~= 3, error('The argument must be a vector of R, G, B values.');end if find(rgb>1 == 1) | find(RGB<0 == 1), error('R, G, B values must be between 0 and 1.');end Bg=Uibgcolor; RGB=rgb; Figpos=[400 600 600 250]; Rtxpos=[50 200 75 20]; Gtxpos=[50 160 75 20]; Btxpos=[50 120 75 20]; Ltxpos=[20 80 100 20]; Rslpos=[130 200 250 20]; Gslpos=[130 160 250 20]; Bslpos=[130 120 250 20]; Lslpos=[130 80 250 20]; Rvlpos=[390 200 75 20]; Gvlpos=[390 160 75 20]; Bvlpos=[390 120 75 20]; RGBfrpos=[470 110 110 115]; RGBtxpos=[470 87 110 20]; DFbtpos=[250 20 80 40]; OKbtpos=[405 20 80 40]; CANCELbtpos=[505 20 80 40]; DFcbk=[gvar 'set(Rsl, ''value'', df(1));set(Rvl, ''string'', num2str(df(1)));',... 'set(Gsl, ''value'', df(2));set(Gvl, ''string'', num2str(df(2)));',... 'set(Bsl, ''value'', df(3));set(Bvl, ''string'', num2str(df(3)));',... 'set(Lsl, ''value'', 0);',... 'set(Lsl, ''min'',(-1*max([get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')])));',... 'set(Lsl, ''max'',(1-min([get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')])));',... 'set(RGBfr, ''Background'', [get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]);']; StartPalettePos=[30 203]; PaletteFrameSize = [20 20]; letters='ABCDEFGHILM'; numbers='12345678'; %%%%%%%%%% MAKE FIGURE %%%%%%%%%%%% fig=figure('Position', Figpos, 'Resize', 'Off', 'Color', Bg, 'NumberTitle', 'off', 'Name', 'RGB Definition', 'nextplot', 'new','Interruptible', 'yes'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Now begins Claudio's section - buttons and sliders %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% TEXT %%%%%%%%%%% uicontrol(fig, 'Style', 'text',... 'String', 'Red',... 'Units', 'pixels',... 'Position', Rtxpos,... 'BackgroundColor', Bg,... 'HorizontalAlignment', 'right'); uicontrol(fig, 'Style', 'text',... 'String', 'Green',... 'Units', 'pixels',... 'Position', Gtxpos,... 'BackgroundColor', Bg,... 'HorizontalAlignment', 'right'); uicontrol(fig, 'Style', 'text',... 'String', 'Blue',... 'Units', 'pixels',... 'Position', Btxpos,... 'BackgroundColor', Bg,... 'HorizontalAlignment', 'right'); uicontrol(fig, 'Style', 'text',... 'String', 'Brightness',... 'Units', 'pixels',... 'Position', Ltxpos,... 'BackgroundColor', Bg,... 'HorizontalAlignment', 'right'); %%%%%%%%%%%% SLIDES %%%%%%%%%%%%% Rsl=uicontrol(fig, 'Style', 'slider',... 'Units', 'pixels',... 'position', Rslpos,... 'Background', 'red',... 'Min', 0,... 'Max', 1,... 'Value', rgb(1),... 'CallBack', ['global Rsl Gsl Bsl Lsl Rvl Gvl Bvl RGBfr RGBtx;set(Rvl, ''string'', num2str(get(Rsl, ''value'')) );',... 'set(RGBtx, ''string'', '' '');',... 'set(Lsl, ''Min'', -1*max([get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]) );',... 'set(Lsl, ''Max'', 1-min([get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]) );',... 'set(Lsl, ''Value'', 0 , ''Userdata'', 0 );',... 'set(RGBfr, ''Background'', [get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]);']); Gsl=uicontrol(fig, 'Style', 'slider',... 'Units', 'pixels',... 'position', Gslpos,... 'Background', 'green',... 'Min', 0,... 'Max', 1,... 'Value', rgb(2),... 'CallBack', ['global Rsl Gsl Bsl Lsl Rvl Gvl Bvl RGBfr RGBtx;set(Gvl, ''string'', num2str(get(Gsl, ''value'')) );',... 'set(RGBtx, ''string'', '' '');',... 'set(Lsl, ''Min'', -1*max([get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]) );',... 'set(Lsl, ''Max'', 1-min([get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]) );',... 'set(Lsl, ''Value'', 0 , ''Userdata'', 0 );',... 'set(RGBfr, ''Background'', [get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]);']); Bsl=uicontrol(fig, 'Style', 'slider',... 'Units', 'pixels',... 'position', Bslpos,... 'Background', 'blue',... 'Min', 0,... 'Max', 1,... 'Value', rgb(3),... 'CallBack', ['global Rsl Gsl Bsl Lsl Rvl Gvl Bvl RGBfr RGBtx;set(Bvl, ''string'', num2str(get(Bsl, ''value'')) );',... 'set(RGBtx, ''string'', '' '');',... 'set(Lsl, ''Min'', -1*max([get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]) );',... 'set(Lsl, ''Max'', 1-min([get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]) );',... 'set(Lsl, ''Value'', 0 , ''Userdata'', 0);',... 'set(RGBfr, ''Background'', [get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]);']); Lsl=uicontrol(fig, 'Style', 'slider',... 'Units', 'pixels',... 'position', Lslpos,... 'Background', Bg,... 'Min', (-1*max([get(Rsl, 'value') get(Gsl, 'value') get(Bsl, 'value')])),... 'Max', (1-min([get(Rsl, 'value') get(Gsl, 'value') get(Bsl, 'value')])),... 'Value', 0,... 'Userdata', 0,... 'CallBack', ['global Rsl Gsl Bsl Lsl Rvl Gvl Bvl RGBfr RGBtx;',... 'val=(get(Rsl, ''value'') + get(Lsl, ''value'') - get(Lsl, ''Userdata''));',... 'if val > 1, val=1;end; if val < 0, val=0;end;',... 'set(Rsl, ''value'', val);',... 'val=get(Gsl, ''value'') + get(Lsl, ''value'') - get(Lsl, ''Userdata'');',... 'if val > 1, val=1;end; if val < 0, val=0;end;',... 'set(Gsl, ''value'', val);',... 'val=get(Bsl, ''value'') + get(Lsl, ''value'') - get(Lsl, ''Userdata'');',... 'if val > 1, val=1;end; if val < 0, val=0;end;',... 'set(Bsl, ''value'', val);',... 'set(Lsl, ''Userdata'', get(Lsl, ''value''));',... 'set(Rvl, ''string'', num2str(get(Rsl, ''value'')) );',... 'set(Gvl, ''string'', num2str(get(Gsl, ''value'')) );',... 'set(Bvl, ''string'', num2str(get(Bsl, ''value'')) );',... 'set(RGBtx, ''string'', '' '');',... 'set(RGBfr, ''Background'', [get(Rsl, ''value'') get(Gsl, ''value'') get(Bsl, ''value'')]);']); %%%%%%%%%%%% VALUES %%%%%%%%%%%%%%%%%% Rvl=uicontrol(fig, 'Style', 'text',... 'String', num2str(get(Rsl, 'value')),... 'Units', 'pixels',... 'Position', Rvlpos,... 'BackgroundColor', Bg,... 'HorizontalAlignment', 'left'); Gvl=uicontrol(fig, 'Style', 'text',... 'String', num2str(get(Gsl, 'value')),... 'Units', 'pixels',... 'Position', Gvlpos,... 'BackgroundColor', Bg,... 'HorizontalAlignment', 'left'); Bvl=uicontrol(fig, 'Style', 'text',... 'String', num2str(get(Bsl, 'value')),... 'Units', 'pixels',... 'Position', Bvlpos,... 'BackgroundColor', Bg,... 'HorizontalAlignment', 'left'); %%%%%%%%%% RGB FRAME %%%%%%%%%%%% RGBfr = uicontrol(fig, 'Style', 'frame',... 'Units', 'pixels',... 'Position', RGBfrpos,... 'BackgroundColor', [get(Rsl, 'value') get(Gsl, 'value') get(Bsl, 'value')]); RGBtx=uicontrol(fig, 'Style', 'text',... 'Units', 'pixels',... 'Position', RGBtxpos,... 'BackgroundColor', Bg,... 'HorizontalAlignment', 'center'); %%%%%%%%% OK - CANCEL %%%%%%%%%%%%% DFbt=uicontrol(fig, 'Style', 'push',... 'String', 'Default',... 'Units', 'pixels',... 'Interruptible','yes',... 'CallBack', DFcbk,... 'Position', DFbtpos); OKbt=uicontrol(fig, 'Style', 'push',... 'String', 'OK',... 'Units', 'pixels',... 'Interruptible','yes',... 'Position', OKbtpos); CANCELbt=uicontrol(fig, 'Style', 'push',... 'String', 'Cancel',... 'Units', 'pixels',... 'Interruptible','yes',... 'Position', CANCELbtpos); pbs=[OKbt CANCELbt]; while ~any(get(fig,'CurrentO')==pbs), drawnow end if get(fig,'CurrentO')== OKbt, RGB=[get(Rsl, 'value') get(Gsl, 'value') get(Bsl, 'value')];end close(fig); return; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%