You are on page 1of 5

function gui_1013(action)

global hnd data%


if nargin<1%
action='start';% start
end
if strcmp(action,'start')% start GUI
hnd.mainfig=figure;% figure
set(hnd.mainfig,'units','normalized','position',[0.2 0.1 0.6 0.8])
% figure
hnd.open1=uicontrol(hnd.mainfig,'units','normalized','style','pushbu
tton',...
'position',[0.03 0.96 0.06 0.035],'string','Open',...
'callback','gui_1013(''open1'')');
% hnd.mainfig pushbutton Open
hnd.file1=uicontrol(hnd.mainfig,'units','normalized','style','edit',...
'position',[0.10 0.96 0.37 0.035],'backgroundcolor',[1 1 1],...
'HorizontalAlignment','left');
% edit
hnd.open2=uicontrol(hnd.mainfig,'units','normalized','style','pushbu
tton',...
'position',[0.53 0.96 0.06 0.035],'string','Open',...
'callback','gui_1013(''open2'')');
hnd.file2=uicontrol(hnd.mainfig,'units','normalized','style','edit',...
'position',[0.60 0.96 0.37 0.035],'backgroundcolor',[1 1 1],...
'HorizontalAlignment','left');

hnd.roi=uicontrol(hnd.mainfig,'units','normalized','style','pushbutton
',...
'position',[0.45 0.01 0.08 0.04],'string','ROI',...
'callback','gui_1013(''roi'')');
hnd.cor=uicontrol(hnd.mainfig,'units','normalized','style','pushbutto
n',...
'position',[0.55 0.01 0.1 0.04],'string','Correlation',...
'callback','gui_1013(''cor'')');
hnd.edit3=uicontrol(hnd.mainfig,'units','normalized','style','edit',...
'position',[0.65 0.01 0.08 0.04],'backgroundcolor',[1 1 1],...
'HorizontalAlignment','left','String','0.9',...
'callback','gui_1013(''cor'')');
hnd.hist=uicontrol(hnd.mainfig,'units','normalized','style','pushbutto
n',...
'position',[0.75 0.01 0.08 0.04],'string','Hist',...
'callback','gui_1013(''hist'')','enable','on');
hnd.quit=uicontrol(hnd.mainfig,'units','normalized','style','pushbutto
n',...
'position',[0.9 0.01 0.08 0.04],'string','Quit',...

'callback','gui_1013(''quit'')');

hnd.sub4=axes('position',[0.55 0.1 0.4 0.4],...


'xlim',[0 255],'visible','off');
% axes
hnd.histline=line('xdata',[],'ydata',[]);
% hnd.sub4 line

elseif strcmp(action,'open1')% open1


hnd.sub1=axes('position',[0.05 0.55 0.4 0.4],'ydir','reverse',...
'xlim',[1 128],'ylim',[1 128]);
% axesy
axis off
hnd.img1=image('cdata',[]);% hnd.sub1 image
colormap(gray(128));% colormap 128
hnd.line=line('xdata',[],'ydata',[]);% ROI

[file,path]=uigetfile('*.*','Open data file');%


if file~=0%
fid=fopen([path file],'r');
img=fread(fid,[128 128],'uint16');
fclose(fid);
img=flipud(img');
data.img1=(img-min(min(img)))/(max(max(img))-min(min(img)));
% 0 1
set(hnd.img1,'cdata',127*data.img1,'xdata',[1 128],'ydata',[1 128]);
% hnd.img1 image
set(hnd.file1,'string',[path file]);% hnd.file1
end

elseif strcmp(action,'open2')% open2


hnd.sub2=axes('position',[0.55 0.55 0.4 0.4],'ydir','reverse',...
'xlim',[1 128],'ylim',[1 128]);
axis off
hnd.img2=image('cdata',[]);
colormap(gray(128));
[file,path]=uigetfile('*.*','Open data file');
if file~=0
fid=fopen([path file],'r');
img=fread(fid,[128 128],'uint16');
fclose(fid);
img=flipud(img');
data.img2=(img-min(min(img)))/(max(max(img))-min(min(img)));

set(hnd.img2,'cdata',127*data.img2,'xdata',[1 128],'ydata',[1 128]);


set(hnd.file2,'string',[path file]);
end

elseif strcmp(action,'roi')% roi hnd.roi


set(gcf,'pointer','crosshair');%
set(hnd.img1,'buttondownfcn','gui_1013(''down'')');
% hnd.img1 down
elseif strcmp(action,'down')% down hnd.img1

data.pt1=get(hnd.sub1,'currentpoint');%
data.pt1=data.pt1(1,1:2);
set(gcf,'windowbuttonmotionfcn','gui_1013(''move'')');
%
set(gcf,'windowbuttonupfcn','gui_1013(''up'')');
%
elseif strcmp(action,'move')%
data.pt2=get(hnd.sub1,'currentpoint');%
data.pt2=data.pt2(1,1:2);
set(hnd.line,'color',[0.5 0.5 0.5],...
'xdata',[data.pt1(1) data.pt2(1) data.pt2(1) data.pt1(1)
data.pt1(1)],...
'ydata',[data.pt1(2) data.pt1(2) data.pt2(2) data.pt2(2)
data.pt1(2)],...
'erasemode','xor','linestyle','--')
%
elseif strcmp(action,'up')%
data.pt2=get(hnd.sub1,'currentpoint');
data.pt2=data.pt2(1,1:2);
set(gcf,'buttondownfcn','');%
set(gcf,'windowbuttonmotionfcn','');%
set(gcf,'windowbuttonupfcn','');%
set(hnd.line,'color',[0 0 1],...
'xdata',[data.pt1(1) data.pt2(1) data.pt2(1) data.pt1(1)
data.pt1(1)],...
'ydata',[data.pt1(2) data.pt1(2) data.pt2(2) data.pt2(2)
data.pt1(2)],...
'erasemode','xor','linestyle','--')
% erasemode() none

drawnow
set(gcf,'pointer','arrow');%
if data.pt1(1)>data.pt2(1)%

pttemp=data.pt1(1);%
data.pt1(1)=data.pt2(1);%
data.pt2(1)=pttemp;
end
if data.pt1(2)>data.pt2(2)
pttemp=data.pt1(2);
data.pt1(2)=data.pt2(2);
data.pt2(2)=pttemp;
end
if data.pt1(1)<1,data.pt1(1)=1;end%
if data.pt2(1)<2,data.pt2(1)=2;end
if data.pt1(1)>127,data.pt1(1)=127;end
if data.pt2(1)>128,data.pt2(1)=128;end
if data.pt1(2)<1,data.pt1(2)=1;end
if data.pt2(2)<2,data.pt2(2)=2;end
if data.pt1(2)>127,data.pt1(2)=127;end
if data.pt2(2)>128,data.pt2(2)=128;end
%
data.W=length(round(data.pt1(1)):round(data.pt2(1)));
data.H=length(round(data.pt1(2)):round(data.pt2(2)));
data.cind=round(data.pt1(1));
data.rind=round(data.pt1(2));
set(hnd.hist,'enable','on')
elseif strcmp(action,'cor')% hnd.cor
hnd.sub3=axes('position',[0.05 0.1 0.4 0.4],'ydir','reverse',...
'xlim',[1 128],'ylim',[1 128]);
axis off
hnd.img3=image('cdata',[]);
data.cor=zeros(128,128);
temp=data.img1(data.rind:(data.rind+data.H-1),data.cind:
(data.cind+data.W-1));
%
denomi=sum(sum(temp.*temp));
for r=1:128-data.H+1% correlation
for c=1:128-data.W+1
nom=sum(sum(temp.*data.img2(r:r+data.H-1,c:c+data.W-1)));
denomj=sum(sum(data.img2(r:r+data.H-1,c:c+data.W1).*data.img2(r:r+data.H-1,c:c+data.W-1)));
data.cor(r,c)=nom/sqrt((denomi*denomj));
end
end
data.corimg=zeros(128,128);%
x=get(hnd.edit3,'string');% threshold
x=str2num(x);
if x>1,x=0.9999;end
if x<0,x=0;end
set(hnd.edit3,'string',num2str(x));

ind=find(data.cor>x);% threshold
tdata=data.cor(ind);%
tdata=scale(tdata,129,256);% rescale 129 256
data.corimg(ind)=tdata;% data.corimg
redmap=[zeros(64,2) linspace(0.6,1,64)';linspace(0.6,1,64)'
zeros(64,1) [linspace(1,0,32)';zeros(32,1)]];
cmap=[gray(128);redmap];
% colormap
colormap(cmap)
set(hnd.img3,'cdata',data.corimg);% coelaion
elseif strcmp(action,'hist')% hist
set(hnd.sub4,'visible','on')
data.g=reshape(data.cor,[1 128*128]);% correlaiton
1*16384
k=hist(data.g*255,255);% histogram
set(hnd.histline,'xdata',[0:254],'ydata',k,'color','b');%
elseif strcmp(action,'quit')% hnd.quit
close(gcf)% figure
clear global hnd data%
end

You might also like