马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
- close all;clc;clear;
- ss='cameraman';
- L=128;
- % Author's email: zjliu2001@163.com
- figure('Position',[55 198 903 349]);
- aa=axes('position',[0.15,0.06,0.3,0.8]);
- Im=imread([ss,'.tif']);
- N=256/L; p=1:L;
- Imt=Im';
- hoi=imshow(Im,[]);
- k=1;T=0;
- backcall=['if T==0;',...
- 'ka=get(gcbo,''UserData'');',...
- 'Q=get(ph(ka(1)),''cdata'');',...
- 'set(ph(ka(1)),''cdata'',[]);',...
- 'set(hpu,''cdata'',Q);',...
- 'else;',...
- 'kb=get(gcbo,''UserData'');',...
- 'QQ=get(ph(kb(1)),''cdata'');',...
- 'set(ph(kb(1)),''cdata'',Q);',....
- 'set(ph(ka(1)),''cdata'',QQ);',...
- 'set(hpu,''cdata'',[]);',...
- 'set(ph(kb(1)),''UserData'',[kb(1),ka(2)]);',...
- 'set(ph(ka(1)),''UserData'',[ka(1),kb(2)]);',...
- 'qa=find(ord==ka(2));qb=find(ord==kb(2));',...
- 'ord(qa)=kb(2);ord(qb)=ka(2);end;',...
- 'if min(diff(ord))==1;',...
- 'msgbox(''Congratulation!'');',...
- 'end;T=~T;'];
- ord=randperm(N*N);
- ph=zeros(N);
- for k=1:(N*N);
- [x,y]=ind2sub([N,N],k);
- ph(x,y)=uicontrol(gcf,'style','pushbutton',...
- 'unit','normalized','position',[0.47+0.3/N*(x-1),...
- 0.85-0.78/N*y,0.3/N,0.78/N],'UserData',[k,ord(k)],...
- 'callback',backcall);
- [xg,yg]=ind2sub([N,N],ord(k));
- sr=repmat(Imt((xg-1)*L+p,(yg-1)*L+p)',[1,1,3]);
- set(ph(k),'cdata',sr);
- end
- hpu=uicontrol(gcf,'style','push',...
- 'unit','normalized','position',[0.82,0.5,0.3/N,0.78/N],...
- 'BackgroundColor',[0.8,0.8,0.8],...
- 'ForegroundColor','b','fontsize',12,...
- 'string','preview chart');
- ht1=uicontrol(gcf,'style','text',...
- 'unit','normalized','position',[0.02,0.7,0.1,0.1],...
- 'BackgroundColor',[0.8,0.8,0.8],...
- 'ForegroundColor','b','fontsize',12,...
- 'string','chose a pic');
- Sc={'cameraman','rice','ic','testpat1'};
- hp=uicontrol(gcf,'style','popupmenu',...
- 'unit','normalized','position',[0.02,0.6,0.1,0.1],...
- 'string','cameraman|rice|ic|testpat1|lena','callback',...
- ['ss=char(Sc(get(hp,''value'')));',...
- 'Im=imread([ss,''.tif'']);Imt=Im'';',...
- 'set(hoi,''cdata'',Im);k=1;',...
- 'ord=randperm(N*N);[xx,yy]=ind2sub([N,N],ord);',...
- 'for k=1:N*N;',...
- '[x,y]=ind2sub([N,N],k);',...
- '[xg,yg]=ind2sub([N,N],ord(k));',...
- 'sr=repmat(Imt((xg-1)*L+p,(yg-1)*L+p)'',[1,1,3]);',...
- 'set(ph(k),''cdata'',sr);end;']);
- ht2=uicontrol(gcf,'style','text',...
- 'unit','normalized','position',[0.01,0.5,0.12,0.1],...
- 'BackgroundColor',[0.8,0.8,0.8],...
- 'ForegroundColor','b','fontsize',12,...
- 'string','size of the pic');
- Si=[128,64,32,16];
- aax=axes('position',[0.78,0.05,0.22,0.4]);
- text(0.02,0.8,'\copyright zjliu',...
- 'fontsize',14);axis off;
- text(0.02,0.6,'email:','fontsize',14);
- text(0.02,0.4,'zjliu@hit.edu.cn','fontsize',14);
- text(0.02,0.2,'zjliu2001@2001.com','fontsize',14);
- hs=uicontrol(gcf,'style','popupmenu',...
- 'unit','normalized','position',[0.02,0.4,0.1,0.1],...
- 'string','128x128|64x64|32x32|16x16','callback',...
- ['L=Si(get(hs,''value''));N=256/L;p=1:L;',...
- 'ss=char(Sc(get(hp,''value'')));',...
- 'Im=imread([ss,''.tif'']);Imt=Im'';',...
- 'set(hoi,''cdata'',Im);',...
- 'clf([aa,hs,hp,ht1,ht2,aax]);',...
- 'ord=randperm(N*N);T=0;ph=zeros(N);',...
- 'for k=1:(N*N);',...
- '[x,y]=ind2sub([N,N],k);',...
- 'ph(x,y)=uicontrol(gcf,''style'',''pushbutton'',',...
- '''unit'',''normalized'',''position'',[0.47+0.3/N*(x-1),',...
- '0.85-0.78/N*y,0.3/N,0.78/N],''UserData'',[k,ord(k)],',...
- '''callback'',backcall);',...
- '[xg,yg]=ind2sub([N,N],ord(k));',...
- 'sr=repmat(Imt((xg-1)*L+p,(yg-1)*L+p)'',[1,1,3]);',...
- 'set(ph(k),''cdata'',sr);end;',...
- 'hpu=uicontrol(gcf,''style'',''push'',',...
- '''unit'',''normalized'',''position'',[0.82,0.5,0.3/N,0.78/N],',...
- '''BackgroundColor'',[0.8,0.8,0.8],',...
- '''ForegroundColor'',''b'',''fontsize'',12,',...
- '''string'',{''preview'';''chart''});']);
复制代码
[ 本帖最后由 suffer 于 2006-10-26 18:03 编辑 ] |