高手进来看看,关于灰度变换的程序
<P>function varargout = gray_Callback(h, eventdata, handles, varargin)<BR>axes(handles.axes2);<BR>hall=get(handles.axes2,'Children');<BR>delete(hall);<BR>set(handles.axes2,'XTick', , ...<BR> 'YTick', , ...<BR> 'XLim', , ...<BR> 'YLim', );<BR>title('Intensity Transformation');<BR>%设置坐标轴<BR>Std.Interruptible = 'off';<BR>Std.BusyAction = 'queue'; <BR>% Line objects for Intensity Adjustment<BR>handles.hAdjLineCtl = line(Std, ...<BR> 'Tag', 'linectl', ...<BR> 'Parent', handles.axes2, ...<BR> 'ButtonDownFcn', 'imgdjust(''BtnDown'',1)', ...<BR> 'Xdata',, ...<BR> 'Ydata', [.15 .15 .85 .85], ...<BR> 'EraseMode', 'xor', ...<BR> 'Color', );<BR>handles.hAdjTopCtl = line(Std, ...<BR> 'Tag','topctl',...<BR> 'Parent', handles.axes2, ...<BR> 'ButtonDownFcn', 'imgdjust(''BtnDown'',2)', ...%imgdjust是一个工具箱函数,可直接调用。<BR> 'LineStyle', 'none', ...<BR> 'Xdata',[.85], ...<BR> 'Ydata', [.85], ...<BR> 'Marker', 'square', ...<BR> 'MarkerFaceCol', [.8 0 0], ...<BR> 'EraseMode', 'xor', ...<BR> 'Color', );<BR>handles.hAdjGammaCtl = line(Std, ...<BR> 'Tag', 'gammactl',...<BR> 'Parent', handles.axes2, ...<BR> 'ButtonDownFcn', 'imgdjust(''BtnDown'',3)', ...<BR> 'LineStyle', 'none', ...<BR> 'Xdata',[.5], ...<BR> 'Ydata', [.5], ...<BR> 'Marker', 'o', ...<BR> 'MarkerFaceCol', , ...<BR> 'EraseMode', 'xor', ...<BR> 'Color', );<BR>handles.hAdjBotCtl = line(Std, ...<BR> 'Tag', 'botctl',...<BR> 'Parent', handles.axes2, ...<BR> 'ButtonDownFcn', 'imgdjust(''BtnDown'',4)', ...<BR> 'LineStyle', 'none', ...<BR> 'Xdata',[.15], ...<BR> 'Ydata', [.15], ...<BR> 'Marker', 'square', ...<BR> 'MarkerFaceCol', , ...<BR> 'EraseMode', 'xor', ...<BR> 'Color', );</P><P> handles.Gamma = 1; % Gamma for imadjust<BR> guidata(h,handles);<BR> <BR> img = get(handles.image, 'CData');<BR> img=double(img)/255;<BR>high =max(img(:)); low = min(img(:));<BR>%handles.Gamma = 1.0;<BR>%set(handles.hGammaEdit, 'String', 1.0);<BR>set(handles.hAdjLineCtl,'Xdata',,'Ydata',);<BR>set(handles.hAdjTopCtl,'Xdata',, 'Ydata', );<BR>set(handles.hAdjBotCtl,'Xdata',, 'Ydata', );<BR>set(handles.hAdjGammaCtl,'Xdata',[(high+low)/2], 'Ydata', );<BR>handles.LowHiBotTop = ;% Actual Low,high,bot,top<BR> guidata(h,handles);<BR>%drawnow;<BR>set(gcf,'UserData',handles);</P>
<P>%%%<BR>%%%Sub-function - Constrain<BR>%%%</P>
<P>function out = Constrain(control, in, handles)<BR>% Make sure the following conditions are all met:<BR>% 1. The line still represents a function (1 to 1 mapping)<BR>% 2. No part of the line extends beyond the range of the axes</P>
<P>low = handles.StartingLowHiBotTop(1);<BR>high = handles.StartingLowHiBotTop(2);<BR>bot = handles.StartingLowHiBotTop(3);<BR>top = handles.StartingLowHiBotTop(4);</P>
<P>out = in;</P>
<P>out(in>1) = 1;% Make sure the point stays in the axes<BR>out(in<0) = 0;</P>
<P>axpos = get(handles.hAdjustToolAxes, 'Position');<BR>xres = 1/axpos(3);<BR>yres = 1/axpos(4);<BR>switch control<BR>case 1 % the user grabbed the line<BR> start = handles.StartingPoint;<BR> dx = out(1)-start(1);<BR> dy = out(2)-start(2);<BR> if high+dx>1<BR> out(1) = 1-high+start(1);<BR> end<BR> if low+dx<0<BR> out(1) = start(1)-low;<BR> end<BR>case 2 % the user grabbed the top box<BR> if out(1) <= low, <BR> out(1) = low + xres;% One pixel<BR> end<BR>case 3 % The user grabbed the Gamma control (circle)<BR> start = handles.StartingPoint;<BR> out(1) = start(1);% Only move vertically<BR> if top > bot<BR> if out(2) >= top<BR> out(2) = top-yres;% One pixel<BR> elseif out(2) <= bot<BR> out(2) = bot+yres;<BR> end<BR> elseif top <= bot<BR> if out(2) > bot<BR> out(2) = bot-yres;<BR> elseif out(2) <= top<BR> out(2) = top+yres;<BR> end<BR> end<BR>case 4 % The user grabbed the Bottom control<BR> if out(1) >= high,<BR> out(1) = high - xres; <BR> end<BR>end</P>
<P>%%%<BR>%%%Sub-Function - DoAdjust<BR>%%%</P>
<P>function DoAdjust(DemoFig)</P>
<P>setptr(DemoFig, 'watch');<BR>setstatus(DemoFig, 'Adjusting image ...');</P>
<P>% The add/subtracts in Constrain can introduce eps level<BR>% errors which put us outside of <BR>low= max(0.0, get(handles.hAdjBotCtl, 'Xdata'));<BR>bot= max(0.0, get(handles.hAdjBotCtl, 'Ydata'));<BR>high = min(1.0, get(handles.hAdjTopCtl, 'Xdata'));<BR>top= min(1.0, get(handles.hAdjTopCtl, 'Ydata'));</P>
<P>if( abs(high-low)<eps )% Protect imadjust against divide by 0<BR> high = low+.0001;<BR>end</P>
<P>img = get(handles.image, 'CData');<BR>img=double(img/255);<BR>imgAd = imadjust(img, ,,ud.Gamma);<BR>set(handles.image, 'CData', imgAd);<BR>setstatus(DemoFig, '');<BR>setptr(DemoFig, 'arrow');<BR>以上是源程序,现在的问题是单击Gammer control的时候图像的灰度也会改变如何让它不改变?而且改变之后就不能恢复了,请问怎么解决,谢谢</P>
回复:(victor_zou)高手进来看看,关于灰度变换的程序...
这个程序中的灰度值好像做了归一化处理
页:
[1]