声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1147|回复: 1

高手进来看看,关于灰度变换的程序

[复制链接]
发表于 2006-5-28 20:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
<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', [0 0.5 1], ...<BR>   'YTick', [0 0.5 1], ...<BR>   'XLim', [0 1], ...<BR>   'YLim', [0 1]);<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',[0 .15 .85 1], ...<BR>   'Ydata', [.15 .15 .85 .85], ...<BR>   'EraseMode', 'xor', ...<BR>   'Color', [0 0 1]);<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', [0 0 0]);<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', [1 1 0], ...<BR>   'EraseMode', 'xor', ...<BR>   'Color', [0 0 0]);<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', [0 1 0], ...<BR>   'EraseMode', 'xor', ...<BR>   'Color', [0 0 0]);</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',[0 low high 1],'Ydata',[0 0 1 1]);<BR>set(handles.hAdjTopCtl,'Xdata',[high], 'Ydata', [1]);<BR>set(handles.hAdjBotCtl,'Xdata',[low], 'Ydata', [0]);<BR>set(handles.hAdjGammaCtl,'Xdata',[(high+low)/2], 'Ydata', [0.5]);<BR>handles.LowHiBotTop = [low high 0 1];  % 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&gt;1) = 1;  % Make sure the point stays in the axes<BR>out(in&lt;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&gt;1<BR>      out(1) = 1-high+start(1);<BR>   end<BR>   if low+dx&lt;0<BR>      out(1) = start(1)-low;<BR>   end<BR>case 2                 % the user grabbed the top box<BR>   if out(1) &lt;= 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 &gt; bot  <BR>      if out(2) &gt;= top<BR>         out(2) = top-yres;  % One pixel<BR>      elseif out(2) &lt;= bot<BR>         out(2) = bot+yres;<BR>      end<BR>   elseif top &lt;= bot<BR>      if out(2) &gt; bot<BR>         out(2) = bot-yres;<BR>      elseif out(2) &lt;= top<BR>         out(2) = top+yres;<BR>      end<BR>   end<BR>case 4                 % The user grabbed the Bottom control<BR>   if out(1) &gt;= 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 [0 1]<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)&lt;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, [low;high],[bot;top],ud.Gamma);<BR>set(handles.image, 'CData', imgAd);<BR>setstatus(DemoFig, '');<BR>setptr(DemoFig, 'arrow');<BR>以上是源程序,现在的问题是单击Gammer control的时候图像的灰度也会改变如何让它不改变?而且改变之后就不能恢复了,请问怎么解决,谢谢</P>
回复
分享到:

使用道具 举报

发表于 2006-5-29 15:05 | 显示全部楼层

回复:(victor_zou)高手进来看看,关于灰度变换的程序...

这个程序中的灰度值好像做了归一化处理
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-29 09:35 , Processed in 0.079518 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表