OSCR

Choosing a skull clearing technique for chronic mesoscopic optical imaging in awake mice.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

Paper

Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 1,905 lines · 58 KB · no license

  1. function varargout = rsfcGUI(varargin)
  2. % RSFCGUI MATLAB code for rsfcGUI.fig
  3. % RSFCGUI, by itself, creates a new RSFCGUI or raises the existing
  4. % singleton*.
  5. %
  6. % H = RSFCGUI returns the handle to a new RSFCGUI or the handle to
  7. % the existing singleton*.
  8. %
  9. % RSFCGUI('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in RSFCGUI.M with the given input arguments.
  11. %
  12. % RSFCGUI('Property','Value',...) creates a new RSFCGUI or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before rsfcGUI_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to rsfcGUI_OpeningFcn via varargin.
  17. %
  18. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
  19. % instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES
  22. % Edit the above text to modify the response to help rsfcGUI
  23. % Last Modified by GUIDE v2.5 12-Mar-2020 00:52:04
  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name', mfilename, ...
  27. 'gui_Singleton', gui_Singleton, ...
  28. 'gui_OpeningFcn', @rsfcGUI_OpeningFcn, ...
  29. 'gui_OutputFcn', @rsfcGUI_OutputFcn, ...
  30. 'gui_LayoutFcn', [] , ...
  31. 'gui_Callback', []);
  32. if nargin && ischar(varargin{1})
  33. gui_State.gui_Callback = str2func(varargin{1});
  34. end
  35. if nargout
  36. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38. gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT
  41. % --- Executes just before rsfcGUI is made visible.
  42. function rsfcGUI_OpeningFcn(hObject, eventdata, handles, varargin)
  43. % This function has no output args, see OutputFcn.
  44. % hObject handle to figure
  45. % eventdata reserved - to be defined in a future version of MATLAB
  46. % handles structure with handles and user data (see GUIDATA)
  47. % varargin command line arguments to rsfcGUI (see VARARGIN)
  48. % Choose default command line output for rsfcGUI
  49. handles.output = hObject;
  50. % Update handles structure
  51. guidata(hObject, handles);
  52. % UIWAIT makes rsfcGUI wait for user response (see UIRESUME)
  53. % uiwait(handles.figure1);
  54. % --- Outputs from this function are returned to the command line.
  55. function varargout = rsfcGUI_OutputFcn(hObject, eventdata, handles)
  56. % varargout cell array for returning output args (see VARARGOUT);
  57. % hObject handle to figure
  58. % eventdata reserved - to be defined in a future version of MATLAB
  59. % handles structure with handles and user data (see GUIDATA)
  60. % Get default command line output from handles structure
  61. varargout{1} = handles.output;
  62. % --- Executes on button press in pushbuttonTestMovie.
  63. function pushbuttonTestMovie_Callback(hObject, eventdata, handles)
  64. % hObject handle to pushbuttonTestMovie (see GCBO)
  65. % eventdata reserved - to be defined in a future version of MATLAB
  66. % handles structure with handles and user data (see GUIDATA)
  67. global rsfc
  68. % cross-correlate for different seeds
  69. [nY,nX,nLam,nT] = size(rsfc.I);
  70. brainIdx = find(rsfc.brain_mask == 1);
  71. yAll = reshape(rsfc.I(:,:,1,:),[nY*nX,nT]);
  72. y = yAll(brainIdx,:);
  73. idx = find(isnan(mean(y,1)) == 0)
  74. y1 = y(:,idx);
  75. rsfc.tRS1 = rsfc.tRS(idx);
  76. nT1 = length(idx);
  77. size(y)
  78. size(y1)
  79. y1 = interp1(rsfc.tRS1',y1',rsfc.tRS')';
  80. yMean = mean(y1,1);
  81. a = pinv(yMean*yMean')*yMean*y1';
  82. ynew = y1'-yMean'*a;
  83. h = 3;
  84. Chb1 = zeros(nY*nX,nT);
  85. size(Chb1)
  86. size(ynew')
  87. Chb1(brainIdx,:) = ynew';
  88. Chb1 = reshape(Chb1, [nY, nX, nT]);
  89. pROI = [60 40; 60 80; 74 34];
  90. y2 = zeros(nT,size(pROI,1));
  91. for ii=1:size(pROI,1)
  92. y2(:,ii) = squeeze(mean(mean(Chb1(pROI(ii,2)+[-h:h], pROI(ii,1)+[-h:h],:),1),2));
  93. end
  94. iLam = 1;
  95. % bandpass filter
  96. wn(2) = 0.08*2/rsfc.fs;
  97. wn(1) = 0.009*2/rsfc.fs;
  98. [fb,fa] = butter(5,wn,'bandpass');
  99. y = reshape(Chb1,[nY*nX nT]);
  100. % y = reshape(I(:,:,iLam,:),[nY*nX nT]);
  101. y = y(brainIdx,:);
  102. % lstInc = find(~isnan(mean(y,1)));
  103. % y = y(:,lstInc);
  104. y = filtfilt(fb,fa,y')';
  105. xLst = [20:2:75];
  106. for iX = 1:length(xLst)
  107. pSeed = [xLst(iX) 80];
  108. ySeed = squeeze(mean(mean(Chb1(pSeed(2)+[-h:h],pSeed(1)+[-h:h],:),1),2));
  109. % ySeed = squeeze(mean(mean(I(pSeed(2)+[-h:h],pSeed(1)+[-h:h],iLam,lstInc),1),2));
  110. ySeed = filtfilt(fb,fa,ySeed);
  111. yCC = (y*ySeed) ./ (std(y,[],2)*std(ySeed)) / length(ySeed);
  112. Chb1CC = zeros(nY,nX);
  113. Chb1CC(brainIdx) = yCC;
  114. axes(handles.axes1)
  115. imagesc(Chb1CC,[-1 1])
  116. hold on
  117. plot(pSeed(1),pSeed(2),'o')
  118. hold off
  119. pause(0.5)
  120. end
  121. % --------------------------------------------------------------------
  122. function menuLoad_Callback(hObject, eventdata, handles)
  123. % hObject handle to menuLoad (see GCBO)
  124. % eventdata reserved - to be defined in a future version of MATLAB
  125. % handles structure with handles and user data (see GUIDATA)
  126. % load your needed variables into rsfc.XXX rsfc.YYY etc
  127. % clear -global all
  128. global rsfc
  129. [filename, pathname] = uigetfile('*_I.mat');
  130. hwait = waitbar(0,'Loading...');
  131. load([pathname filename]);
  132. rsfc.I = I;
  133. rsfc.Iunfilt = Iunfilt;
  134. rsfc.I0 = I0;
  135. rsfc.tRS = tRS;
  136. rsfc.I0_unsampled = I0_unsampled;
  137. rsfc.sampling_rate = size(rsfc.I0_unsampled,1)/size(rsfc.I0,1);
  138. rsfc.atlas = imread('miceatlas.png');
  139. waitbar(0.66,hwait)
  140. axes(handles.axes1)
  141. colormap('jet');
  142. if (exist('rsfc_brainMask.mat','file') ~= 0) && (get(handles.radiobutton_brainmaskON,'Value') == get(handles.radiobutton_brainmaskON,'Max'))
  143. mask = load('rsfc_brainMask.mat');
  144. rsfc.brain_mask = mask.brain_mask;
  145. rsfc.Xi = mask.Xi;
  146. rsfc.Yi = mask.Yi;
  147. img = rsfc.I0(:,:,1).*uint16(rsfc.brain_mask);
  148. clims = [min(img(:)) max(img(:))];
  149. imagesc(img,clims);
  150. else
  151. img = rsfc.I0(:,:,1);
  152. clims = [min(img(:)) max(img(:))];
  153. imagesc(img,clims);
  154. end
  155. axes(handles.axes4)
  156. imagesc(rsfc.atlas);
  157. close(hwait);
  158. clear A I mask;
  159. % --- Executes on mouse press over axes background.
  160. function axes1_ButtonDownFcn(hObject, eventdata, handles)
  161. % hObject handle to axes1 (see GCBO)
  162. % eventdata reserved - to be defined in a future version of MATLAB
  163. % handles structure with handles and user data (see GUIDATA)
  164. global rsfc
  165. keyboard
  166. % --- Executes on button press in pushbuttonSelectSeed.
  167. function pushbuttonSelectSeed_Callback(hObject, eventdata, handles)
  168. % hObject handle to pushbuttonSelectSeed (see GCBO)
  169. % eventdata reserved - to be defined in a future version of MATLAB
  170. % handles structure with handles and user data (see GUIDATA)
  171. global rsfc
  172. global count;
  173. global pts;
  174. global str
  175. global Chb1CC
  176. global ct
  177. ct = 0;
  178. str = {};
  179. cstring = 'rgbcmyk';
  180. [nY,nX,nLam,nT] = size(rsfc.I);
  181. nT = length(rsfc.tRS);
  182. brainIdx = find(rsfc.brain_mask == 1);
  183. hpf = str2num(get(handles.editHPF,'string'));
  184. lpf = str2num(get(handles.editLPF,'string'));
  185. wn(2) =lpf*2/rsfc.fs;
  186. wn(1) = hpf*2/rsfc.fs;
  187. if wn(1)>0 && wn(2)>0
  188. [fb,fa] = butter(5,wn,'bandpass');
  189. elseif wn(2) > 0
  190. [fb,fa] = butter(5,wn(2),'low');
  191. elseif wn(1) > 0
  192. [fb,fa] = butter(5,wn(2),'high');
  193. end
  194. pSeed = ginput(1);
  195. % If the seed in selected in the baseline image. (Baseline image was unsampled and other images were downsampled.)
  196. if get(handles.togglebuttonbaselineimage,'value') == 1
  197. pSeed = pSeed/rsfc.sampling_rate;
  198. end
  199. pSeed = round(pSeed)
  200. if count == 0
  201. pts = pSeed;
  202. else
  203. pts = [pts; pSeed];
  204. end
  205. y = rsfc.y;
  206. h = str2double(get(handles.seedsize,'string'));
  207. ySeed = squeeze(mean(mean(y(pSeed(2)+[-floor(h/2):floor(h/2)],pSeed(1)+[-floor(h/2):floor(h/2)],:),1),2));
  208. % ySeed = squeeze(mean(mean(I(pSeed(2)+[-h:h],pSeed(1)+[-h:h],iLam,lstInc),1),2));
  209. if wn(1)>0 || wn(2)>0
  210. ySeed = filtfilt(fb,fa,ySeed);
  211. end
  212. ySeedunfilt = squeeze(mean(mean(rsfc.Iunfilt(pSeed(2)+[-floor(h/2):floor(h/2)],pSeed(1)+[-floor(h/2):floor(h/2)],:),1),2));
  213. ySeedunGR = squeeze(mean(mean(rsfc.yunGR(pSeed(2)+[-floor(h/2):floor(h/2)],pSeed(1)+[-floor(h/2):floor(h/2)],:),1),2));
  214. y = reshape(y,[nY*nX nT]);
  215. y = y(brainIdx,:);
  216. % yCC = (y*ySeed) ./ (std(y,[],2)*std(ySeed)) / length(ySeed);
  217. yCC = corr(y.',ySeed);
  218. Chb1CC = zeros(nY,nX);
  219. Chb1CC(brainIdx) = yCC;
  220. seedTC = mean(abs(yCC));
  221. set(handles.text4,'String',num2str(seedTC))
  222. axes(handles.axes1)
  223. h = imagesc(Chb1CC,[-1 1]),colorbar;
  224. colormap('jet');
  225. set(h, 'ButtonDownFcn', {@mouseclick, handles});
  226. for u = 1:size(pts,1)
  227. text(pts(u,1),pts(u,2),['O seed' num2str(u)], 'FontSize', 13);
  228. end
  229. for u = 1:length(rsfc.refX)
  230. text(rsfc.refX(u),rsfc.refY(u),'X', 'FontSize', 13);
  231. end
  232. % Dispaly time course of seed
  233. axes(handles.axes2)
  234. hold on
  235. if get(handles.radiobutton_globalsignal,'Value') == get(handles.radiobutton_globalsignal,'Max')
  236. h = plot(rsfc.tRS,ySeedunfilt, cstring(mod(count,7)+1));
  237. else
  238. h = plot(rsfc.tRS,ySeed, cstring(mod(count,7)+1));
  239. end
  240. for u = 1: count+1
  241. str{u} = ['seed' num2str(u)];
  242. end
  243. legend(str);
  244. hold off
  245. count = count+1;
  246. % Display power spectrum of filtered and unfiltered data
  247. L = length(ySeed);
  248. NFFT = 2^nextpow2(L); % Next power of 2 from length of y
  249. ySeedf = fft(ySeed,NFFT)/L;
  250. f = rsfc.fs/2*linspace(0,1,NFFT/2+1);
  251. axes(handles.axes3)
  252. semilogx(f,2*abs(ySeedf(1:NFFT/2+1)),'b','LineWidth',2);
  253. hold on
  254. xlim([0.005 1])
  255. % f = log(f);
  256. ySeedunfiltf = fft(ySeedunfilt,NFFT)/L;
  257. semilogx(f,2*abs(ySeedunfiltf(1:NFFT/2+1)),'r','LineWidth',2);
  258. xlim([0.005 1])
  259. hold on
  260. ySeedunGRf = fft(ySeedunGR,NFFT)/L;
  261. semilogx(f,2*abs(ySeedunGRf(1:NFFT/2+1)),'k','LineWidth',2);
  262. xlim([0.005 1])
  263. hold off
  264. filtpower = rsfc.df*sum(abs(ySeedf).^2);
  265. unfiltpower = rsfc.df*sum(abs(ySeedunfiltf).^2);
  266. filterunGRpower = rsfc.df*sum(abs(ySeedunGRf).^2);
  267. set(handles.text_filteredpower,'String',num2str(filtpower));
  268. set(handles.text_unfilteredpower,'String',num2str(unfiltpower));
  269. set(handles.text21,'String',num2str(filterunGRpower));
  270. % plotyy(f,2*abs(ySeedf(1:NFFT/2+1)),f,2*abs(ySeedunfilt(1:NFFT/2+1)));
  271. % figure;
  272. % colormap('gray');
  273. % imagesc(rsfc.I0_unsampled',[0 800]);
  274. % for u = 1:size(pts,1)
  275. % text(4*pts(u,2),4*pts(u,1),['O seed'], 'FontSize', 13);
  276. % end
  277. %
  278. if (get(handles.radiobutton_savetsps,'Value') == get(handles.radiobutton_savetsps,'Max'))
  279. figure(2);
  280. subplot(5,1,1)
  281. plot(rsfc.tRS,ySeedunfilt);
  282. xlabel('time');
  283. ylabel('magnitude')
  284. title('Unfiltered Signal');
  285. subplot(5,1,2)
  286. plot(rsfc.tRS,rsfc.yglobal);
  287. xlabel('time');
  288. ylabel('magnitude')
  289. title('Global Unfiltered Signal');
  290. subplot(5,1,3)
  291. plot(rsfc.tRS,ySeed)
  292. xlabel('time');
  293. ylabel('magnitude');
  294. title('Filtered Signal');
  295. subplot(5,1,4)
  296. semilogx(f,2*abs(ySeedf(1:NFFT/2+1)),'b','LineWidth',2);
  297. hold on
  298. xlim([0.005 1]);
  299. semilogx(f,2*abs(ySeedunfiltf(1:NFFT/2+1)),'r','LineWidth',2);
  300. title('Frequency Spectrum');
  301. xlabel('frequency');
  302. ylabel('power');
  303. subplot(5,1,5)
  304. semilogx(f,2*abs(rsfc.meanyallf(1:NFFT/2+1)),'b','LineWidth',2);
  305. xlim([0.005 1]);
  306. title('Golabl Frequency Spectrum');
  307. xlabel('frequency');
  308. ylabel('power');
  309. figure(101);
  310. hold on;
  311. h = plot(rsfc.tRS,ySeed, cstring(mod(count,7)+1));
  312. xlabel('time(sec)');
  313. ylabel('magnitude');
  314. Ts = rsfc.tRS;
  315. save('plotdata.mat','ySeed','Ts');
  316. for u = 1: count+1
  317. str{u} = ['seed' num2str(u)];
  318. end
  319. legend(str);
  320. hold off;
  321. nameplot = inputdlg('Please enter the name to save the plot');
  322. ts = rsfc.tRS;
  323. save([nameplot{1} '.mat'],'ySeed','ts');
  324. end
  325. if (get(handles.radiobutton_SaveImage,'Value') == get(handles.radiobutton_SaveImage,'Max'))
  326. figure;
  327. colormap('jet');
  328. imagesc(Chb1CC,[-1 1]),colorbar;
  329. for u = 1:size(pts,1)
  330. text(pts(u,1),pts(u,2),['O seed' num2str(u)], 'FontSize', 18);
  331. % text(pts(u,2),pts(u,1),['O seed'], 'FontSize', 13);
  332. end
  333. name = inputdlg('Please enter the name to save the image');
  334. save([name{1} '.mat'],'Chb1CC');
  335. end
  336. set(handles.togglebuttonbaselineimage,'value',0);
  337. % --- Executes on button press in pushbuttonPreProcess.
  338. function pushbuttonPreProcess_Callback(hObject, eventdata, handles)
  339. % hObject handle to pushbuttonPreProcess (see GCBO)
  340. % eventdata reserved - to be defined in a future version of MATLAB
  341. % handles structure with handles and user data (see GUIDATA)
  342. global rsfc
  343. global count
  344. count = 0;
  345. hpf = str2num(get(handles.editHPF,'string'));
  346. lpf = str2num(get(handles.editLPF,'string'));
  347. hwait = waitbar(0,'Pre-processing...');
  348. [nY,nX,nLam,nT] = size(rsfc.I);
  349. % nY1 = size(rsfc.I0,1);
  350. % sampling_rate = nY1/nY;
  351. % brain_mask = rsfc.brain_mask(1:sampling_rate:end,1:sampling_rate:end);
  352. % brainIdx = find(brain_mask == 1);
  353. brainIdx = find(rsfc.brain_mask == 1);
  354. % Selecting the data matrix
  355. yAll = reshape(rsfc.I(:,:,1,:),[nY*nX,nT]);
  356. y1 = yAll(brainIdx,:);
  357. tRS = rsfc.tRS;
  358. % idx = find(isnan(mean(y,1)) == 0 & mean(y,1) < 220);
  359. % idx = find(isnan(mean(y,1)) == 0) ;
  360. % y1 = y(:,idx);
  361. % tRS1 = rsfc.tRS(idx);
  362. nT
  363. % Removing data with artifacts
  364. if isfield(rsfc,'excludeData')
  365. disp('here');
  366. if (isempty(rsfc.excludeData) == 0)
  367. for u = 1:size(rsfc.excludeData,1)
  368. u
  369. idx1 = length(find(tRS<=rsfc.excludeData(u,1)));
  370. idx2 = length(find(tRS<=rsfc.excludeData(u,2)));
  371. if u == 1
  372. idxs = idx1:idx2;
  373. else
  374. idxs = [idxs idx1:idx2];
  375. end
  376. end
  377. y1(:,idxs) = [];
  378. tRS(idxs) = [];
  379. rsfc.I(:,:,:,idxs) = [];
  380. rsfc.excludeData = [];
  381. rsfc.Iunfilt(:,:,:,idxs) = [];
  382. axes(handles.axes2)
  383. cla reset
  384. end
  385. end
  386. % nT1 = length(tRS1);
  387. rsfc.tRS = tRS;
  388. % y11 = y1;
  389. % y1 = interp1(rsfc.tRS1',y1',rsfc.tRS')';
  390. nT = length(tRS);
  391. size(y1)
  392. nY
  393. nX
  394. nT
  395. rsfc.yunGR = zeros(nY*nX,nT);
  396. rsfc.yunGR(brainIdx,:) = y1;
  397. rsfc.yunGR = reshape(rsfc.yunGR,[nY nX nT]);
  398. % size(y1)
  399. % figure; plot(rsfc.tRS1,y11(5000,:)); figure; plot(rsfc.tRS,y1(5000,:));
  400. % normalize data...
  401. % Just testing this out... is it a good thing to do?
  402. % we are trying it out so that pixels with large amplitude from spectular
  403. % reflections don't dominate the mean
  404. % y1 = y1./(mean(y1,2)*ones(1,size(y1,2)));
  405. % subtract global mean
  406. % if 0
  407. % check matlab regression also
  408. if get(handles.radiobutton_noGSR,'Value')
  409. ynew = y1';
  410. elseif get(handles.radiobutton_GSR,'Value')
  411. yMean = mean(y1,1);
  412. a = pinv(yMean*yMean')*yMean*y1';
  413. size(a)
  414. ynew = y1'-yMean'*a;
  415. else
  416. infarctIdx = find(rsfc.infarct_mask == 1);
  417. yAll = reshape(rsfc.I(:,:,1,:),[nY*nX,nT]);
  418. yinfarct = yAll(infarctIdx,:);
  419. yinfarctMean = mean(yinfarct,1);
  420. % a = pinv(yMean*yMean')*yMean*yinfarct';
  421. % yinfarctnew = yinfarct'-yMean'*a;
  422. noninfarctIdx = setdiff(brainIdx,infarctIdx);
  423. ynoninfarct = yAll(noninfarctIdx,:);
  424. ynoninfarctMean = mean(ynoninfarct,1);
  425. % a = pinv(yMean*yMean')*yMean*ynoninfarct';
  426. % ynoninfarctnew = ynoninfarct'-yMean'*a;
  427. yMean = [ynoninfarctMean; yinfarctMean];
  428. a = pinv(yMean*yMean')*yMean*y1';
  429. disp('size of a is')
  430. size(a)
  431. ynew = y1'-yMean'*a;
  432. % yAll(infarctIdx,:) = yinfarctnew';
  433. % yAll(noninfarctIdx,:) = ynoninfarctnew';
  434. %
  435. % ynew = yAll(brainIdx,:);
  436. % ynew = ynew';
  437. % noninfarctIdx = setdiff(brainIdx,infarctIdx);
  438. % % Selecting the data matrix
  439. % yAll = reshape(rsfc.I(:,:,1,:),[nY*nX,nT]);
  440. % yinfarct = yAll(infarctIdx,:);
  441. % ynoninfarct = yAll(noninfarctIdx,:);
  442. % yinfarctMean = mean(yinfarct,1);
  443. % ynoninfarctMean = mean(ynoninfarct,1);
  444. % yMean = yinfarctMean.*ynoninfarctMean;
  445. % a = pinv(yMean*yMean')*yMean*y1';
  446. % ynew = y1'-yMean'*a;
  447. end
  448. size(ynew)
  449. % else
  450. % ynew = y1';
  451. % end
  452. % Chb1 = zeros(nY*nX,nT1);
  453. % Chb1(brainIdx,:) = ynew';
  454. % Chb1 = reshape(Chb1, [nY, nX, nT1]);
  455. Chb1 = zeros(nY*nX,nT);
  456. size(Chb1)
  457. Chb1(brainIdx,:) = ynew';
  458. Chb1 = reshape(Chb1, [nY, nX, nT]);
  459. % bandpass filter
  460. rsfc.fs = 1/(rsfc.tRS(2)-rsfc.tRS(1));
  461. wn(2) = lpf*2/rsfc.fs;
  462. wn(1) = hpf*2/rsfc.fs;
  463. if wn(1)>0 && wn(2)>0
  464. [fb,fa] = butter(5,wn,'bandpass');
  465. elseif wn(2) > 0
  466. [fb,fa] = butter(5,wn(2),'low');
  467. elseif wn(1) > 0
  468. [fb,fa] = butter(5,wn(2),'high');
  469. end
  470. y = reshape(Chb1,[nY*nX nT]);
  471. y = y(brainIdx,:);
  472. if wn(1) > 0 || wn(2)>0
  473. y = filtfilt(fb,fa,y')';
  474. end
  475. yy = zeros(nY*nX,nT);
  476. yy(brainIdx,:) = y;
  477. % yy = reshape(yy,[nY nX nT1]);
  478. yy = reshape(yy,[nY nX nT]);
  479. % nMin = 8;
  480. % dt = 0.5;
  481. % tRS = min(rsfc.tRS)+dt:dt:(nMin*60-dt);
  482. % nT = length(tRS);
  483. % yyy = zeros(nY,nX,nT);
  484. % for iT = 1:nT
  485. % iT
  486. % lstIdx = find(rsfc.tRS>(tRS(iT)-dt) & rsfc.tRS<=(tRS(iT)+dt));
  487. % yyy(:,:,1,iT) = mean(yy(:,:,lstIdx),3);
  488. % end
  489. % rsfc.tRS = tRS;
  490. rsfc.y = yy;
  491. y = rsfc.y;
  492. [nY,nX,nT] = size(y);
  493. y = reshape(y,[nY*nX nT]);
  494. axes(handles.axes1)
  495. colormap(jet);
  496. h = imagesc(rsfc.I0.*(rsfc.brain_mask));
  497. set(h, 'ButtonDownFcn', {@mouseclick, handles});
  498. brainIdx = find(rsfc.brain_mask == 1);
  499. y = y(brainIdx,:);
  500. hpf = str2num(get(handles.editHPF,'string'));
  501. lpf = str2num(get(handles.editLPF,'string'));
  502. wn(2) =lpf*2/rsfc.fs;
  503. wn(1) = hpf*2/rsfc.fs;
  504. if wn(1)>0 && wn(2)>0
  505. [fb,fa] = butter(5,wn,'bandpass');
  506. elseif wn(2) > 0
  507. [fb,fa] = butter(5,wn(2),'low');
  508. elseif wn(1) > 0
  509. [fb,fa] = butter(5,wn(2),'high');
  510. end
  511. I = rsfc.y;
  512. t = rsfc.tRS;
  513. save('Processeddata','I','t');
  514. % create N*N correlation matrix (N = number of pixels in the brain)
  515. % yCC = (y*y') ./ (std(y,[],2)*std(y,[],2)') / size(y,1);
  516. yCC = corr(y.',y.');
  517. load('atlas.mat');
  518. rsfc.areaM = 8/(sqrt((xi(2)-xi(1))^2+(yi(2)-yi(1))^2));
  519. yCCavg = mean(abs(yCC),1);
  520. CI = mean(yCCavg);
  521. set(handles.text_avgconnectivityglobal,'String',num2str(CI));
  522. cutoff = str2num(get(handles.edit_cutoffCI,'string'));
  523. idxs = find(yCCavg >= cutoff);
  524. set(handles.text_globalArea,'String',num2str(length(idxs)*rsfc.areaM));
  525. BOC = zeros(nY,nX);
  526. BOC(brainIdx) = yCCavg;
  527. axes(handles.axes5)
  528. colormap(jet);
  529. imagesc(BOC); colorbar;
  530. rsfc.GCM = BOC;
  531. rsfc.Sign_img = ((repmat((1:nY)',1,nX)-xi(1)).*(yi(2)-yi(1)))-((repmat(1:nX,nY,1)-yi(1)).*(xi(2)-xi(1)));
  532. Oneside_idxs = find(rsfc.GCM >= cutoff & rsfc.Sign_img > 0 & rsfc.brain_mask == 1);
  533. Otherside_idxs = find(rsfc.GCM >= cutoff & rsfc.Sign_img < 0 & rsfc.brain_mask == 1);
  534. Oneside_idxs_CI = find( rsfc.Sign_img > 0 & rsfc.brain_mask == 1);
  535. Otherside_idxs_CI = find( rsfc.Sign_img < 0 & rsfc.brain_mask == 1);
  536. Oneside_CI = mean(abs(rsfc.GCM(Oneside_idxs_CI)));
  537. Otherside_CI = mean(abs(rsfc.GCM(Otherside_idxs_CI)));
  538. set(handles.text_ConnectivityIndex_1,'String',num2str(Oneside_CI ));
  539. set(handles.text_ConnectivityIndex_2,'String',num2str(Otherside_CI));
  540. set(handles.text_area_1,'String',num2str(length(Oneside_idxs)*rsfc.areaM));
  541. set(handles.text_area_2,'String',num2str(length(Otherside_idxs)*rsfc.areaM));
  542. % calculate gobal time series signal
  543. rsfc.yglobal = squeeze(mean(mean(rsfc.Iunfilt,1),2));
  544. % calculate global frequency signal
  545. L = length(rsfc.yglobal);
  546. NFFT = 2^nextpow2(L); % Next power of 2 from length of y
  547. yall = reshape(rsfc.Iunfilt,[nY*nX nT]);
  548. yall = yall(brainIdx,:);
  549. yallf = fft(yall',NFFT)/L;
  550. rsfc.meanyallf = mean(abs(yallf),2);
  551. rsfc.f = rsfc.fs/2*linspace(0,1,NFFT/2+1);
  552. rsfc.df = (rsfc.f(2)-rsfc.f(1))/2;
  553. globalpower = rsfc.df*sum(abs(rsfc.meanyallf).^2);
  554. set(handles.text_globalpower,'String',num2str(globalpower));
  555. % Left Right Spatial Correlation
  556. axes(handles.axes6)
  557. imagesc(rsfc.I0); colormap('gray');
  558. if exist('BLpts.mat','file')
  559. load('BLpts.mat')
  560. else
  561. h = msgbox(' Please select 2 points bregma and lambda in axes 6');
  562. uiwait(h);
  563. [y,x] = ginput(2);
  564. save('BLpts.mat','y','x');
  565. end
  566. a = y(2)-y(1);
  567. b = x(1)-x(2);
  568. c = (y(1)-y(2))*x(1)+(x(2)-x(1))*y(1);
  569. rsfc.yLRC = zeros(nY,nX);
  570. for u = 1:nY
  571. for v = 1:nX
  572. if rsfc.brain_mask(u,v) == 1
  573. xs = round(2*(b^2*u-a*b*v-a*c)/(a^2+b^2)-u);
  574. ys = round(2*(a^2*v-a*b*u-b*c)/(a^2+b^2)-v);
  575. if xs <1
  576. xs = 1;
  577. end
  578. if xs > nY
  579. xs = nY;
  580. end
  581. if ys <1
  582. ys = 1;
  583. end
  584. if ys > nX
  585. ys = nX;
  586. end
  587. h = str2double(get(handles.seedsize,'string'));
  588. x1_min = min(max(xs-floor(h/2),1),nY);
  589. x1_max = min(max(xs+floor(h/2),1),nY);
  590. y1_min = min(max(ys-floor(h/2),1),nY);
  591. y1_max = min(max(ys+floor(h/2),1),nY);
  592. x2_min = min(max(u-floor(h/2),1),nY);
  593. x2_max = min(max(u+floor(h/2),1),nY);
  594. y2_min = min(max(v-floor(h/2),1),nY);
  595. y2_max = min(max(v+floor(h/2),1),nY);
  596. % CR = corr(squeeze(rsfc.y(xs,ys,:)),squeeze(rsfc.y(u,v,:)));
  597. CR = corr(squeeze(mean(mean(rsfc.y(x1_min:x1_max,y1_min:y1_max,:),1),2)),squeeze(mean(mean(rsfc.y(x2_min:x2_max,y2_min:y2_max,:),1),2)));
  598. rsfc.yLRC(xs,ys) = CR;
  599. rsfc.yLRC(u,v) = CR;
  600. end
  601. end
  602. end
  603. imagesc(rsfc.yLRC,[-1 1]); colormap('jet'); colorbar;
  604. LRC = rsfc.yLRC;
  605. save('LRC.mat','LRC');
  606. close(hwait);
  607. % --- Executes on button press in togglebuttonbaselineimage.
  608. function togglebuttonbaselineimage_Callback(hObject, eventdata, handles)
  609. % hObject handle to togglebuttonbaselineimage (see GCBO)
  610. % eventdata reserved - to be defined in a future version of MATLAB
  611. % handles structure with handles and user data (see GUIDATA)
  612. % Hint: get(hObject,'Value') returns toggle state of togglebuttonbaselineimage
  613. global rsfc
  614. global pts
  615. global Chb1CC
  616. axes(handles.axes1);
  617. if get(hObject,'Value') == 1
  618. colormap('gray');
  619. % img = rsfc.I0(:,:,1).*rsfc.brain_mask;
  620. img = rsfc.I0_unsampled(:,:,1);
  621. clims = [min(img(:)) max(img(:))];
  622. imagesc(img,[rsfc.MinS rsfc.MaxS]); colorbar;
  623. hold on
  624. for u = 1:size(pts,1)
  625. text(rsfc.sampling_rate*pts(u,1),rsfc.sampling_rate*pts(u,2),['O seed' num2str(u)], 'FontSize', 13);
  626. end
  627. for u = 1:length(rsfc.refX)
  628. text(rsfc.sampling_rate*rsfc.refX(u),rsfc.sampling_rate*rsfc.refY(u),'X', 'FontSize', 13);
  629. end
  630. hold off
  631. else
  632. colormap('jet');
  633. h = imagesc(Chb1CC,[-1 1]); colorbar;
  634. hold on
  635. for u = 1:size(pts,1)
  636. text(pts(u,1),pts(u,2),['O seed' num2str(u)], 'FontSize', 13);
  637. end
  638. for u = 1:length(rsfc.refX)
  639. text(rsfc.refX(u),rsfc.refY(u),'X', 'FontSize', 13);
  640. end
  641. hold off
  642. set(h, 'ButtonDownFcn', {@mouseclick, handles});
  643. end
  644. % --- Executes on button press in togglebutton2.
  645. function togglebutton2_Callback(hObject, eventdata, handles)
  646. % hObject handle to togglebutton2 (see GCBO)
  647. % eventdata reserved - to be defined in a future version of MATLAB
  648. % handles structure with handles and user data (see GUIDATA)
  649. % Hint: get(hObject,'Value') returns toggle state of togglebutton2
  650. global count
  651. global pts
  652. global rsfc
  653. count = 0;
  654. pts = [0 0];
  655. axes(handles.axes2)
  656. cla reset
  657. axes(handles.axes3);
  658. cla reset
  659. axes(handles.axes1);
  660. cla reset
  661. colormap('jet');
  662. % img = rsfc.I0(:,:,1).*rsfc.brain_mask;
  663. img = rsfc.I0(:,:,1);
  664. clims = [min(img(:)) max(img(:))];
  665. h = imagesc(img,clims);
  666. for u = 1:length(rsfc.refX)
  667. text(rsfc.refX(u),rsfc.refY(u),'X', 'FontSize', 13);
  668. end
  669. set(h, 'ButtonDownFcn', {@mouseclick, handles});
  670. set(handles.togglebuttonbaselineimage,'value',0);
  671. % --- Executes on button press in pushbuttonbrainmask.
  672. function pushbuttonbrainmask_Callback(hObject, eventdata, handles)
  673. % hObject handle to pushbuttonbrainmask (see GCBO)
  674. % eventdata reserved - to be defined in a future version of MATLAB
  675. % handles structure with handles and user data (see GUIDATA)
  676. global rsfc
  677. final_brain_mask = false(size(rsfc.I0));
  678. while(1)
  679. axes(handles.axes1)
  680. MinMinS = min(rsfc.I0(:)); MaxMaxS = max(rsfc.I0(:));
  681. while(1)
  682. imagesc(rsfc.I0(:,:,1),[ MinMinS MaxMaxS]); colorbar;
  683. colormap('gray');
  684. button = questdlg('Are you happy with the image contrast?','Repeat selection or not...','No');
  685. if strcmp(button,'No')
  686. answer= inputdlg({'Enter minimum intensity level of survey scan image'},'Enter minimum intensity level:',1,{num2str(MinMinS)}); % {'0'});
  687. answer1 = cell2struct(answer, 'number', 1);
  688. MinMinS = str2num(answer1.number);
  689. answer= inputdlg({'Enter maximum intensity level of survey scan image'},'Enter maximum intensity level:',1,{num2str(MaxMaxS)}); % {'0'});
  690. answer1 = cell2struct(answer, 'number', 1);
  691. MaxMaxS = str2num(answer1.number);
  692. else
  693. break;
  694. end
  695. end
  696. rsfc.MaxS = MaxMaxS;
  697. rsfc.MinS = MinMinS;
  698. h = msgbox(' Please select the brain region');
  699. uiwait(h)
  700. % axes(handles.axes6)
  701. % imagesc(rsfc.yLRC,[-1 1]);
  702. [brain_mask,Xi,Yi] = roipoly;
  703. hold on;
  704. plot(Xi,Yi,'color','k');
  705. hold off;
  706. button = questdlg('Are you statisfied with ROI?');
  707. if strcmp(button, 'Yes')
  708. final_brain_mask(brain_mask==1) = 1;
  709. button = questdlg('Do you want to select another ROI?');
  710. if ~strcmp(button, 'Yes')
  711. break;
  712. end
  713. end
  714. end
  715. if (get(handles.radiobutton4,'Value') == get(handles.radiobutton4,'Max'))
  716. figure; imshow(rsfc.I0,[MinMinS MaxMaxS]); colormap('gray');
  717. end
  718. brain_mask = final_brain_mask;
  719. save('rsfc_brainMask.mat','brain_mask','Xi','Yi');
  720. rsfc.brain_mask = final_brain_mask;
  721. rsfc.Xi = Xi;
  722. rsfc.Yi = Yi;
  723. % --- Executes on button press in pushbutton_slecttime.
  724. function pushbutton_slecttime_Callback(hObject, eventdata, handles)
  725. % hObject handle to pushbutton_slecttime (see GCBO)
  726. % eventdata reserved - to be defined in a future version of MATLAB
  727. % handles structure with handles and user data (see GUIDATA)
  728. global rsfc
  729. global tidx
  730. global h
  731. global ct
  732. if ct > 0
  733. delete(h);
  734. end
  735. ct = 1;
  736. axes(handles.axes2)
  737. [X,~] =ginput(1);
  738. tidx = length(find(rsfc.tRS < X))+1;
  739. % tp = rsfc.tRS(idx);
  740. axes(handles.axes1)
  741. colormap('jet');
  742. if (get(handles.radiobutton_brainmaskON,'Value') == get(handles.radiobutton_brainmaskON,'Max'))
  743. img = rsfc.I(:,:,1,tidx).*rsfc.brain_mask;
  744. clims = [min(img(:)) max(img(:))];
  745. imagesc(img,clims);
  746. else
  747. img = rsfc.I0(:,:,1);
  748. clims = [min(img(:)) max(img(:))];
  749. imagesc(img,clims);
  750. end
  751. axes(handles.axes2)
  752. hold on
  753. h = text(rsfc.tRS(tidx),0,'X','FontSize',15);
  754. hold off
  755. % --- Executes on button press in pushbutton_forward.
  756. function pushbutton_forward_Callback(hObject, eventdata, handles)
  757. % hObject handle to pushbutton_forward (see GCBO)
  758. % eventdata reserved - to be defined in a future version of MATLAB
  759. % handles structure with handles and user data (see GUIDATA)
  760. global rsfc
  761. global tidx
  762. global h
  763. delete(h)
  764. tidx = tidx+1;
  765. axes(handles.axes1)
  766. colormap('jet');
  767. if (get(handles.radiobutton_brainmaskON,'Value') == get(handles.radiobutton_brainmaskON,'Max'))
  768. img = rsfc.I(:,:,1,tidx).*rsfc.brain_mask;
  769. clims = [min(img(:)) max(img(:))];
  770. imagesc(img,clims);
  771. else
  772. img = rsfc.I(:,:,1,tidx);
  773. colormap('gray');
  774. clims = [min(img(:)) max(img(:))];
  775. imagesc(img,clims);
  776. end
  777. axes(handles.axes2)
  778. hold on
  779. h = text(rsfc.tRS(tidx),0,'X','FontSize',13);
  780. hold off
  781. % --- Executes on button press in pushbutton_backward.
  782. function pushbutton_backward_Callback(hObject, eventdata, handles)
  783. % hObject handle to pushbutton_backward (see GCBO)
  784. % eventdata reserved - to be defined in a future version of MATLAB
  785. % handles structure with handles and user data (see GUIDATA)
  786. global rsfc
  787. global tidx
  788. global h
  789. delete(h)
  790. tidx = tidx-1;
  791. axes(handles.axes1)
  792. colormap('jet');
  793. if (get(handles.radiobutton_brainmaskON,'Value') == get(handles.radiobutton_brainmaskON,'Max'))
  794. img = rsfc.I(:,:,1,tidx).*rsfc.brain_mask;
  795. clims = [min(img(:)) max(img(:))];
  796. imagesc(img,clims);
  797. else
  798. img = rsfc.I(:,:,1,tidx);
  799. colormap('gray');
  800. clims = [min(img(:)) max(img(:))];
  801. imagesc(img,clims);
  802. end
  803. axes(handles.axes2)
  804. hold on
  805. h = text(rsfc.tRS(tidx),0,'X','FontSize',13);
  806. hold off
  807. function editHPF_Callback(hObject, eventdata, handles)
  808. % hObject handle to editHPF (see GCBO)
  809. % eventdata reserved - to be defined in a future version of MATLAB
  810. % handles structure with handles and user data (see GUIDATA)
  811. % Hints: get(hObject,'String') returns contents of editHPF as text
  812. % str2double(get(hObject,'String')) returns contents of editHPF as a double
  813. function editLPF_Callback(hObject, eventdata, handles)
  814. % hObject handle to editLPF (see GCBO)
  815. % eventdata reserved - to be defined in a future version of MATLAB
  816. % handles structure with handles and user data (see GUIDATA)
  817. % Hints: get(hObject,'String') returns contents of editLPF as text
  818. % str2double(get(hObject,'String')) returns contents of editLPF as a double
  819. % --- Executes on button press in pushbutton.
  820. function pushbutton_Callback(hObject, eventdata, handles)
  821. % hObject handle to pushbutton (see GCBO)
  822. % eventdata reserved - to be defined in a future version of MATLAB
  823. % handles structure with handles and user data (see GUIDATA)
  824. global rsfc
  825. global obj_count
  826. k = waitforbuttonpress;
  827. if k==0
  828. pt1 = get(gca,'CurrentPoint'); % button down detected
  829. finalRect = rbbox; % return figure units
  830. pt2 = get(gca,'CurrentPoint');
  831. %Checking boundary conditions
  832. if pt1(1,1) < rsfc.tRS(1)
  833. pt1(1,1) = rsfc.tRS(1);
  834. end
  835. if pt1(1,1) > rsfc.tRS(end)
  836. pt1(1,1) = rsfc.tRS(end);
  837. end
  838. if pt2(1,1) < rsfc.tRS(1)
  839. pt2(1,1) = rsfc.tRS(1);
  840. end
  841. if pt2(1,1) > rsfc.tRS(end)
  842. pt2(1,1) = rsfc.tRS(end);
  843. end
  844. %Arrange pts in increasing order
  845. if pt1(1,1) > pt2(1,1)
  846. temp = pt1(1,1);
  847. pt1(1,1) = pt2(1,1);
  848. pt2(1,1) = temp;
  849. end
  850. if isfield(rsfc,'excludeData')
  851. rsfc.excludeData(end+1,:) = [pt1(1,1) pt2(1,1)];
  852. else
  853. rsfc.excludeData(1,:) = [pt1(1,1) pt2(1,1)];
  854. end
  855. axes(handles.axes2)
  856. yy = ylim();
  857. hp = patch([pt1(1,1) pt2(1,1) pt2(1,1) pt1(1,1)],[yy(1) yy(1) yy(2) yy(2)],'m','facealpha',0.3,'edgecolor','k');
  858. idx = size(rsfc.excludeData,1);
  859. rsfc.excludeData_handle(idx) = hp;
  860. obj_count(idx) = idx;
  861. set(hp,'ButtonDownFcn', sprintf('rsfc_excludeData_PatchCallback(%d)',idx) );
  862. end
  863. % --- Executes on button press in radiobutton_brainmaskON.
  864. function radiobutton_brainmaskON_Callback(hObject, eventdata, handles)
  865. % hObject handle to radiobutton_brainmaskON (see GCBO)
  866. % eventdata reserved - to be defined in a future version of MATLAB
  867. % handles structure with handles and user data (see GUIDATA)
  868. % Hint: get(hObject,'Value') returns toggle state of radiobutton_brainmaskON
  869. % --- Executes on button press in pushbutton_iterrativeparcellation.
  870. function pushbutton_iterrativeparcellation_Callback(hObject, eventdata, handles)
  871. % hObject handle to pushbutton_iterrativeparcellation (see GCBO)
  872. % eventdata reserved - to be defined in a future version of MATLAB
  873. % handles structure with handles and user data (see GUIDATA)
  874. global rsfc
  875. y = rsfc.y;
  876. [nY,nX,nT] = size(y);
  877. y = reshape(y,[nY*nX nT]);
  878. brainIdx = find(rsfc.brain_mask == 1);
  879. y = y(brainIdx,:);
  880. hpf = str2num(get(handles.editHPF,'string'));
  881. lpf = str2num(get(handles.editLPF,'string'));
  882. wn(2) =lpf*2/rsfc.fs;
  883. wn(1) = hpf*2/rsfc.fs;
  884. if wn(1)>0 && wn(2)>0
  885. [fb,fa] = butter(5,wn,'bandpass');
  886. elseif wn(2) > 0
  887. [fb,fa] = butter(5,wn(2),'low');
  888. elseif wn(1) > 0
  889. [fb,fa] = butter(5,wn(2),'high');
  890. end
  891. % create N*N correlation matrix (N = number of pixels in the brain)
  892. % yCC = (y*y') ./ (std(y,[],2)*std(y,[],2)') / size(y,1);
  893. yCC = corr(y.',y.');
  894. % yCCavg = mean(abs(yCC),1);
  895. % BOC = zeros(nY,nX);
  896. % BOC(brainIdx) = yCCavg;
  897. % figure; imagesc(BOC); colorbar;
  898. % Singular Value Decomposition
  899. % [U,~,V] = svd(yCC);
  900. axes(handles.axes1)
  901. while(1)
  902. % intial assumption of parcels based on first ten modes of connectivity matrix
  903. yatlas = zeros(1,length(brainIdx));
  904. l = length(yatlas);
  905. button = questdlg('Would you like to calculate another parcellation map ?');
  906. if strcmp(button,'Yes')
  907. button2 = questdlg('Would you like to open saved seeds for parcellation');
  908. if strcmp(button2,'Yes')
  909. [filename,pathname] = uigetfile;
  910. load([pathname filename]);
  911. load('atlas.mat');
  912. ya = [328 328]; xa = [129 459];
  913. fixedPoints = [[xi(1) yi(1)]; [xi(2) yi(2)]];
  914. movingPoints = [[xa(1) ya(1)]; [xa(2) ya(2)]];
  915. tform = fitgeotrans(movingPoints,fixedPoints,'nonreflectivesimilarity');
  916. [xp,yp] = transformPointsForward(tform, xp, yp);
  917. yp = round(yp);
  918. xp = round(xp);
  919. else
  920. answer = char(inputdlg('Please enter number of parcellations'));
  921. psize = str2num(answer);
  922. % for u = 1:l
  923. % [~,id] = max(abs(U(u,1:psize)));
  924. % yatlas(u) = U(u,id)*id/abs(U(u,id));
  925. % end
  926. % yintial_atlas = yatlas;
  927. % idx = find(yatlas < 0);
  928. % yatlas(idx) = yatlas(idx) + (2*psize+1);
  929. % For seed based parcellation
  930. imagesc(rsfc.I0);
  931. colormap('gray');
  932. h = msgbox('Please select the seeds for parcellation');
  933. uiwait(h);
  934. [yp,xp] = ginput(psize);
  935. yp = round(yp);
  936. xp = round(xp);
  937. end
  938. p_timetraces = zeros(length(xp),nT);
  939. for u = 1:size(p_timetraces,1)
  940. p_timetraces(u,:) = rsfc.y(xp(u),yp(u),:);
  941. end
  942. yR = corr(y.',p_timetraces.');
  943. for w = 1:l
  944. [~,id] = max(yR(w,:));
  945. yatlas(w) = id;
  946. end
  947. brain_atlas = zeros(nY,nX);
  948. brain_atlas(brainIdx) = yatlas;
  949. figure; imagesc(brain_atlas); colorbar;
  950. % iterative parcellation (clustering algorithm)
  951. % p_timetraces = zeros(2*psize,nT);
  952. count = 0;
  953. u = 0;
  954. while(1)
  955. u = u+1;
  956. % for v = 1:10
  957. % idx1 = find(yatlas == -v);
  958. % idx2 = find(yatlas == v);
  959. % p_timetraces(v,:) = mean(y(idx1,:),1);
  960. % p_timetraces(v+10,:) = mean(y(idx2,:),1);
  961. % end
  962. for v = 1:size(p_timetraces,1)
  963. % idx1 = find(yatlas == -v);
  964. % idx2 = find(yatlas == v);
  965. idx = find(yatlas == v);
  966. p_timetraces(v,:) = mean(y(idx,:),1);
  967. % p_timetraces(v+10,:) = mean(y(idx2,:),1);
  968. if idx < 50
  969. if count == 0
  970. lst = v;
  971. count = count+1;
  972. else
  973. lst = [lst idx];
  974. count = count+1;
  975. end
  976. end
  977. end
  978. if count > 0
  979. p_timetraces(lst,:) = [];
  980. lst = [];
  981. count = 0;
  982. end
  983. if wn(1)>0 || wn(2)>0
  984. p_timetraces = filtfilt(fb,fa,p_timetraces')';
  985. end
  986. % yR = (y*p_timetraces')./ (std(y,[],2)*std(p_timetraces,[],2)') / size(y,1);
  987. yR = corr(y.',p_timetraces.');
  988. for w = 1:l
  989. [~,id] = max(yR(w,:));
  990. yatlas(w) = id;
  991. end
  992. if u > 1
  993. if isequal(yatlas,yatlasCond)
  994. break;
  995. end
  996. end
  997. yatlasCond = yatlas;
  998. % idx1 = find(yatlas < 11);
  999. % yatlas(idx1) = -1*yatlas(idx1);
  1000. % idx2 = find(yatlas > 10);
  1001. % yatlas(idx2) = yatlas(idx2)-10;
  1002. end
  1003. no_of_iterations = u
  1004. brain_atlas = zeros(nY,nX);
  1005. brain_atlas(brainIdx) = yatlas;
  1006. figure; imagesc(brain_atlas); colorbar;
  1007. save('brain_atlas.mat','brain_atlas');
  1008. % pR = corr(p_timetraces.',p_timetraces.');
  1009. % C = linkage(pR);
  1010. % figure; dendrogram(C);
  1011. else
  1012. break;
  1013. end
  1014. end
  1015. % U = U(:,1:10);
  1016. % Rmatrix = (y*U')./(std(y,[],2)'*std(U,[],2))/ size(y,1);
  1017. % for u = 1:l
  1018. % [min,id] = unique(Rmatrix(1:10,u));
  1019. % yatlas(u) = min*id/abs(min);
  1020. % end
  1021. function seedsize_Callback(hObject, eventdata, handles)
  1022. % hObject handle to seedsize (see GCBO)
  1023. % eventdata reserved - to be defined in a future version of MATLAB
  1024. % handles structure with handles and user data (see GUIDATA)
  1025. % Hints: get(hObject,'String') returns contents of seedsize as text
  1026. % str2double(get(hObject,'String')) returns contents of seedsize as a double
  1027. % --- Executes during object creation, after setting all properties.
  1028. function seedsize_CreateFcn(hObject, eventdata, handles)
  1029. % hObject handle to seedsize (see GCBO)
  1030. % eventdata reserved - to be defined in a future version of MATLAB
  1031. % handles empty - handles not created until after all CreateFcns called
  1032. % Hint: edit controls usually have a white background on Windows.
  1033. % See ISPC and COMPUTER.
  1034. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1035. set(hObject,'BackgroundColor','white');
  1036. end
  1037. % --- Executes on button press in pushbutton_avgfreqspectrum.
  1038. function pushbutton_avgfreqspectrum_Callback(hObject, eventdata, handles)
  1039. % hObject handle to pushbutton_avgfreqspectrum (see GCBO)
  1040. % eventdata reserved - to be defined in a future version of MATLAB
  1041. % handles structure with handles and user data (see GUIDATA)
  1042. global rsfc
  1043. y = rsfc.y;
  1044. [nY,nX,nT] = size(y);
  1045. y = reshape(y,[nY*nX nT]);
  1046. brainIdx = find(rsfc.brain_mask == 1);
  1047. y = y(brainIdx,:);
  1048. hpf = str2num(get(handles.editHPF,'string'));
  1049. lpf = str2num(get(handles.editLPF,'string'));
  1050. wn(2) =lpf*2/rsfc.fs;
  1051. wn(1) = hpf*2/rsfc.fs;
  1052. if wn(1)>0 && wn(2)>0
  1053. [fb,fa] = butter(5,wn,'bandpass');
  1054. elseif wn(2) > 0
  1055. [fb,fa] = butter(5,wn(2),'low');
  1056. elseif wn(1) > 0
  1057. [fb,fa] = butter(5,wn(2),'high');
  1058. end
  1059. % create N*N correlation matrix (N = number of pixels in the brain)
  1060. % yCC = (y*y') ./ (std(y,[],2)*std(y,[],2)') / size(y,1);
  1061. yCC = corr(y.',y.');
  1062. yCCavg = mean(abs(yCC),1);
  1063. BOC = zeros(nY,nX);
  1064. BOC(brainIdx) = yCCavg;
  1065. figure; imagesc(BOC,[0 0.5]); colormap('jet'); colorbar;
  1066. % y = rsfc.y;
  1067. % fs = 11;
  1068. % [nY,nX,nT] = size(y);
  1069. % y = reshape(y,[nY*nX nT]);
  1070. % brainIdx = find(rsfc.brain_mask == 1);
  1071. % y = y(brainIdx,:);
  1072. % L = size(y,1);
  1073. % NFFT = 2^nextpow2(L); % Next power of 2 from length of y
  1074. % yf = fft(y',NFFT)'/L;
  1075. % f = fs/2*linspace(0,1,NFFT/2+1);
  1076. % yfavg = mean(yf,1);
  1077. % figure;
  1078. % semilogx(f,2*abs(yfavg(1:NFFT/2+1)),'b','LineWidth',2);
  1079. % --- Executes on button press in radiobutton_SaveImage.
  1080. function radiobutton_SaveImage_Callback(hObject, eventdata, handles)
  1081. % hObject handle to radiobutton_SaveImage (see GCBO)
  1082. % eventdata reserved - to be defined in a future version of MATLAB
  1083. % handles structure with handles and user data (see GUIDATA)
  1084. % Hint: get(hObject,'Value') returns toggle state of radiobutton_SaveImage
  1085. % --- Executes on button press in pushbutton11.
  1086. function pushbutton11_Callback(hObject, eventdata, handles)
  1087. % hObject handle to pushbutton11 (see GCBO)
  1088. % eventdata reserved - to be defined in a future version of MATLAB
  1089. % handles structure with handles and user data (see GUIDATA)
  1090. global rsfc
  1091. y = rsfc.y;
  1092. [AVIfileOut, AVIpathOut] = uiputfile( '*.avi','Create AVI movie name...');
  1093. AVIfileName = [AVIpathOut AVIfileOut];
  1094. writerObj = VideoWriter(AVIfileName,'Uncompressed AVI');
  1095. writerObj.FrameRate = 40;
  1096. open(writerObj);
  1097. l = size(y,3);
  1098. cmap = colormap(jet(256));
  1099. % cmap = cmap(1:51,:);
  1100. ymin = min(y(:));
  1101. ymax = max(y(:));
  1102. y = (y-ymin)/(ymax-ymin);
  1103. MinMinS = min(y(:));
  1104. MaxMaxS = max(y(:));
  1105. while(1)
  1106. figure(1); imagesc(y(:,:,1),[MinMinS MaxMaxS]);
  1107. colormap(jet);
  1108. colorbar;
  1109. button = questdlg('Are you happy with the image contrast?','Repeat selection or not...','No');
  1110. if strcmp(button,'No')
  1111. answer= inputdlg({'Enter minimum intensity level of survey scan image'},'Enter minimum intensity level:',1,{num2str(MinMinS)}); % {'0'});
  1112. answer1 = cell2struct(answer, 'number', 1);
  1113. MinMinS = str2num(answer1.number);
  1114. answer= inputdlg({'Enter maximum intensity level of survey scan image'},'Enter maximum intensity level:',1,{num2str(MaxMaxS)}); % {'0'});
  1115. answer1 = cell2struct(answer, 'number', 1);
  1116. MaxMaxS = str2num(answer1.number);
  1117. else
  1118. break;
  1119. end
  1120. end
  1121. for u = 1:l
  1122. figure(111)
  1123. imagesc(squeeze(y(:,:,u)),[MinMinS MaxMaxS]);
  1124. text(10,10,[num2str(int16(rsfc.tRS(u))) 'Secs']);
  1125. colormap(jet);
  1126. F = getframe(gcf);
  1127. writeVideo(writerObj,F);
  1128. %mov = addframe(mov,F);
  1129. end;
  1130. %mov = close(mov);
  1131. close(writerObj);
  1132. % --- Executes on button press in pushbutton_registeratlas.
  1133. function pushbutton_registeratlas_Callback(hObject, eventdata, handles)
  1134. % hObject handle to pushbutton_registeratlas (see GCBO)
  1135. % eventdata reserved - to be defined in a future version of MATLAB
  1136. % handles structure with handles and user data (see GUIDATA)
  1137. global rsfc
  1138. h = msgbox('Please select two points in the image');
  1139. uiwait(h);
  1140. % reading the points Bregma and Lambda from image.
  1141. MinMinS = min(rsfc.I0(:)); MaxMaxS = max(rsfc.I0(:));
  1142. axes(handles.axes1)
  1143. while(1)
  1144. imagesc(rsfc.I0(:,:,1),[ MinMinS MaxMaxS]); colorbar;
  1145. colormap('gray');
  1146. button = questdlg('Are you happy with the image contrast?','Repeat selection or not...','No');
  1147. if strcmp(button,'No')
  1148. answer= inputdlg({'Enter minimum intensity level of survey scan image'},'Enter minimum intensity level:',1,{num2str(MinMinS)}); % {'0'});
  1149. answer1 = cell2struct(answer, 'number', 1);
  1150. MinMinS = str2num(answer1.number);
  1151. answer= inputdlg({'Enter maximum intensity level of survey scan image'},'Enter maximum intensity level:',1,{num2str(MaxMaxS)}); % {'0'});
  1152. answer1 = cell2struct(answer, 'number', 1);
  1153. MaxMaxS = str2num(answer1.number);
  1154. else
  1155. break;
  1156. end
  1157. end
  1158. rsfc.MaxS = MaxMaxS;
  1159. rsfc.MinS = MinMinS;
  1160. [y,x] = ginput(2)
  1161. yi = y;
  1162. xi = x;
  1163. save('atlas.mat','yi','xi');
  1164. % Bregma and Lambda locations from atlas.
  1165. ya = [328 328]; xa = [129 459];
  1166. % Since trying to register atlas to the data, atlas points are moving
  1167. % points and image points are fixed points
  1168. fixedPoints = [[x(1) y(1)]; [x(2) y(2)]];
  1169. movingPoints = [[xa(1) ya(1)]; [xa(2) ya(2)]];
  1170. [m1,n1] = size(rsfc.I0)
  1171. [m2,n2,~] = size(rsfc.atlas);
  1172. tform = fitgeotrans(movingPoints,fixedPoints,'nonreflectivesimilarity');
  1173. count = 0;
  1174. % img3(:,:,1) = imwarp(rsfc.atlas(:,:,1),tform);
  1175. % img3(:,:,2) = imwarp(rsfc.atlas(:,:,2),tform);
  1176. % img3(:,:,3) = imwarp(rsfc.atlas(:,:,3),tform);
  1177. u = repmat((1:m2)',1,n2);
  1178. v = repmat(1:n2,m2,1);
  1179. [ut,vt] = transformPointsForward(tform, u(:), v(:));
  1180. img3 = rsfc.atlas(1:m1,1:n1,:)*0;
  1181. L = length(u(:));
  1182. for xx = 1:L
  1183. if ut(xx) < 1 || ut(xx) > m1 || vt(xx) < 1 || vt(xx) > n1
  1184. else
  1185. img3(round(ut(xx)),round(vt(xx)),:) = rsfc.atlas(u(xx),v(xx),:);
  1186. end
  1187. end
  1188. % for xx = 1:
  1189. % img3(round(ut),round(vt),:) = rsfc.atlas(u,v,:);
  1190. % figure;
  1191. % imagesc(img3)
  1192. % for u = 1:m2
  1193. % % u
  1194. % for v = 1:n2
  1195. % [tempx,tempy] = transformPointsForward(t,v,u);
  1196. % % [tempx,tempy] = tforminv(t,u,v);
  1197. % if tempx < 1 || tempx > n1 || tempy < 1 || tempy > m1
  1198. % else
  1199. % count = count+1;
  1200. % img3(round(tempy),round(tempx),:) = rsfc.atlas(u,v,:);
  1201. % % img3(u,v,:) = img1(round(tempy),round(tempx),:);
  1202. % end
  1203. % end
  1204. % end
  1205. % count
  1206. % u
  1207. % v
  1208. axes(handles.axes4)
  1209. imagesc(img3)
  1210. % axis([0,m1,0,n1]);
  1211. % --- Executes during object creation, after setting all properties.
  1212. function text4_CreateFcn(hObject, eventdata, handles)
  1213. % hObject handle to text4 (see GCBO)
  1214. % eventdata reserved - to be defined in a future version of MATLAB
  1215. % handles empty - handles not created until after all CreateFcns called
  1216. % --- Executes on button press in pushbutton_selectROI.
  1217. function pushbutton_selectROI_Callback(hObject, eventdata, handles)
  1218. % hObject handle to pushbutton_selectROI (see GCBO)
  1219. % eventdata reserved - to be defined in a future version of MATLAB
  1220. % handles structure with handles and user data (see GUIDATA)
  1221. global rsfc
  1222. GCM = rsfc.GCM;
  1223. while(1)
  1224. axes(handles.axes5)
  1225. imagesc(rsfc.GCM,[0 max(GCM(:))]); colorbar;
  1226. for u = 1:length(rsfc.refX)
  1227. text(rsfc.refX(u),rsfc.refY(u),'X', 'FontSize', 13);
  1228. end
  1229. [mask,Xi,Yi] = roipoly;
  1230. axes(handles.axes5)
  1231. hold on;
  1232. plot(Xi,Yi,'color','k');
  1233. button = questdlg('Are you statisfied with ROI');
  1234. if strcmp(button, 'Yes');
  1235. break;
  1236. end
  1237. end
  1238. cutoff = str2num(get(handles.edit_cutoffCI,'string'));
  1239. idxs1 = find(mask==1);
  1240. idxs2 = find(mask==1 & rsfc.GCM >= cutoff);
  1241. set(handles.text_areaofROI,'String',num2str(length(idxs2)));
  1242. if(isempty(idxs1)==0)
  1243. set(handles.text_avgconnectivity,'String',num2str(mean(GCM(idxs1))));
  1244. else
  1245. set(handles.text_avgconnectivity,'String','0');
  1246. end
  1247. axes(handles.axes5)
  1248. imagesc(rsfc.GCM,[cutoff max(GCM(:))]); colorbar;
  1249. plot(Xi,Yi,'color','k');
  1250. for u = 1:length(rsfc.refX)
  1251. text(rsfc.refX(u),rsfc.refY(u),'X', 'FontSize', 13);
  1252. end
  1253. rsfc.Smask = mask;
  1254. rsfc.SXi = Xi;
  1255. rsfc.SYi = Yi;
  1256. function edit_cutoffCI_Callback(hObject, eventdata, handles)
  1257. % hObject handle to edit_cutoffCI (see GCBO)
  1258. % eventdata reserved - to be defined in a future version of MATLAB
  1259. % handles structure with handles and user data (see GUIDATA)
  1260. % Hints: get(hObject,'String') returns contents of edit_cutoffCI as text
  1261. % str2double(get(hObject,'String')) returns contents of edit_cutoffCI as a double
  1262. global rsfc
  1263. cutoff = str2num(get(handles.edit_cutoffCI,'string'));
  1264. idxs = find(rsfc.brain_mask==1 & rsfc.GCM >= cutoff);
  1265. set(handles.text_globalArea,'String',num2str(length(idxs)*rsfc.areaM));
  1266. Oneside_idxs = find(rsfc.GCM >= cutoff & rsfc.Sign_img > 0 & rsfc.brain_mask == 1);
  1267. Otherside_idxs = find(rsfc.GCM >= cutoff & rsfc.Sign_img < 0 & rsfc.brain_mask == 1);
  1268. % Oneside_CI = mean(abs(rsfc.GCM(Oneside_idxs)));
  1269. % Otherside_CI = mean(abs(rsfc.GCM(Otherside_idxs)));
  1270. % set(handles.text_ConnectivityIndex_1,'String',num2str(Oneside_CI ));
  1271. % set(handles.text_ConnectivityIndex_2,'String',num2str(Otherside_CI));
  1272. set(handles.text_area_1,'String',num2str(length(Oneside_idxs)*rsfc.areaM));
  1273. set(handles.text_area_2,'String',num2str(length(Otherside_idxs)*rsfc.areaM));
  1274. if isfield(rsfc,'Smask')
  1275. cutoff = str2num(get(handles.edit_cutoffCI,'string'));
  1276. idxs2 = find(rsfc.Smask==1 & rsfc.GCM >= cutoff);
  1277. set(handles.text_areaofROI,'String',num2str(length(idxs2)*rsfc.areaM));
  1278. end
  1279. axes(handles.axes5)
  1280. if cutoff >= max(rsfc.GCM(:))
  1281. maxI = cutoff+0.1;
  1282. else
  1283. maxI = max(rsfc.GCM(:));
  1284. end
  1285. imagesc(rsfc.GCM,[cutoff maxI]); colorbar;
  1286. if isfield(rsfc,'Smask')
  1287. plot(rsfc.SXi,rsfc.SYi,'color','k');
  1288. end
  1289. for u = 1:length(rsfc.refX)
  1290. text(rsfc.refX(u),rsfc.refY(u),'X', 'FontSize', 13);
  1291. end
  1292. % --- Executes during object creation, after setting all properties.
  1293. function edit_cutoffCI_CreateFcn(hObject, eventdata, handles)
  1294. % hObject handle to edit_cutoffCI (see GCBO)
  1295. % eventdata reserved - to be defined in a future version of MATLAB
  1296. % handles empty - handles not created until after all CreateFcns called
  1297. % Hint: edit controls usually have a white background on Windows.
  1298. % See ISPC and COMPUTER.
  1299. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1300. set(hObject,'BackgroundColor','white');
  1301. end
  1302. function edit_minI_Callback(hObject, eventdata, handles)
  1303. % hObject handle to edit_minI (see GCBO)
  1304. % eventdata reserved - to be defined in a future version of MATLAB
  1305. % handles structure with handles and user data (see GUIDATA)
  1306. % Hints: get(hObject,'String') returns contents of edit_minI as text
  1307. % str2double(get(hObject,'String')) returns contents of edit_minI as a double
  1308. % --- Executes during object creation, after setting all properties.
  1309. function edit_minI_CreateFcn(hObject, eventdata, handles)
  1310. % hObject handle to edit_minI (see GCBO)
  1311. % eventdata reserved - to be defined in a future version of MATLAB
  1312. % handles empty - handles not created until after all CreateFcns called
  1313. % Hint: edit controls usually have a white background on Windows.
  1314. % See ISPC and COMPUTER.
  1315. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1316. set(hObject,'BackgroundColor','white');
  1317. end
  1318. function edit_MaxI_Callback(hObject, eventdata, handles)
  1319. % hObject handle to edit_MaxI (see GCBO)
  1320. % eventdata reserved - to be defined in a future version of MATLAB
  1321. % handles structure with handles and user data (see GUIDATA)
  1322. % Hints: get(hObject,'String') returns contents of edit_MaxI as text
  1323. % str2double(get(hObject,'String')) returns contents of edit_MaxI as a double
  1324. % --- Executes during object creation, after setting all properties.
  1325. function edit_MaxI_CreateFcn(hObject, eventdata, handles)
  1326. % hObject handle to edit_MaxI (see GCBO)
  1327. % eventdata reserved - to be defined in a future version of MATLAB
  1328. % handles empty - handles not created until after all CreateFcns called
  1329. % Hint: edit controls usually have a white background on Windows.
  1330. % See ISPC and COMPUTER.
  1331. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1332. set(hObject,'BackgroundColor','white');
  1333. end
  1334. function mouseclick(hObject, eventdata, handles)
  1335. global rsfc
  1336. parent = (get(hObject, 'Parent')) ;
  1337. pts = round(get(parent, 'CurrentPoint'));
  1338. %
  1339. cutoff = str2num(get(handles.edit_cutoffCI,'string'));
  1340. if cutoff >= max(rsfc.GCM(:))
  1341. maxI = cutoff+0.1;
  1342. else
  1343. maxI = max(rsfc.GCM(:));
  1344. end
  1345. axes(handles.axes5)
  1346. imagesc(rsfc.GCM,[cutoff maxI]); colorbar;
  1347. y = [pts(1,2) pts(1,2)];
  1348. x = xlim();
  1349. line(x,y,'LineWidth',2,'color','r');
  1350. y = ylim();
  1351. x = [pts(1,1), pts(1,1)];
  1352. line(x,y,'LineWidth',2,'color','r');
  1353. % --- Executes on button press in pushbutton_SelectReferencePoints.
  1354. function pushbutton_SelectReferencePoints_Callback(hObject, eventdata, handles)
  1355. % hObject handle to pushbutton_SelectReferencePoints (see GCBO)
  1356. % eventdata reserved - to be defined in a future version of MATLAB
  1357. % handles structure with handles and user data (see GUIDATA)
  1358. global rsfc
  1359. axes(handles.axes1)
  1360. imagesc(rsfc.I0);
  1361. [X,Y] = ginput(3);
  1362. rsfc.refX = X;
  1363. rsfc.refY = Y;
  1364. for u = 1:length(X)
  1365. text(X(u),Y(u),'X', 'FontSize', 13);
  1366. end
  1367. % axes(handles.axes5)
  1368. % imagesc(rsfc.GCM);
  1369. % for u = 1:length(rsfc.refX)
  1370. % text(rsfc.refX(u),rsfc.refY(u),'X', 'FontSize', 13);
  1371. % end
  1372. % --- Executes on button press in radiobutton_globalsignal.
  1373. function radiobutton_globalsignal_Callback(hObject, eventdata, handles)
  1374. % hObject handle to radiobutton_globalsignal (see GCBO)
  1375. % eventdata reserved - to be defined in a future version of MATLAB
  1376. % handles structure with handles and user data (see GUIDATA)
  1377. % Hint: get(hObject,'Value') returns toggle state of radiobutton_globalsignal
  1378. % --- Executes on button press in radiobutton4.
  1379. function radiobutton4_Callback(hObject, eventdata, handles)
  1380. % hObject handle to radiobutton4 (see GCBO)
  1381. % eventdata reserved - to be defined in a future version of MATLAB
  1382. % handles structure with handles and user data (see GUIDATA)
  1383. % Hint: get(hObject,'Value') returns toggle state of radiobutton4
  1384. % --- Executes on button press in radiobutton_savetsps.
  1385. function radiobutton_savetsps_Callback(hObject, eventdata, handles)
  1386. % hObject handle to radiobutton_savetsps (see GCBO)
  1387. % eventdata reserved - to be defined in a future version of MATLAB
  1388. % handles structure with handles and user data (see GUIDATA)
  1389. % Hint: get(hObject,'Value') returns toggle state of radiobutton_savetsps
  1390. % --- Executes on button press in pushbutton_atlasseeds.
  1391. function pushbutton_atlasseeds_Callback(hObject, eventdata, handles)
  1392. % hObject handle to pushbutton_atlasseeds (see GCBO)
  1393. % eventdata reserved - to be defined in a future version of MATLAB
  1394. % handles structure with handles and user data (see GUIDATA)
  1395. global rsfc
  1396. % --- Executes on button press in radiobutton_globaltimesignal.
  1397. function radiobutton_globaltimesignal_Callback(hObject, eventdata, handles)
  1398. % hObject handle to radiobutton_globaltimesignal (see GCBO)
  1399. % eventdata reserved - to be defined in a future version of MATLAB
  1400. % handles structure with handles and user data (see GUIDATA)
  1401. % Hint: get(hObject,'Value') returns toggle state of radiobutton_globaltimesignal
  1402. global rsfc
  1403. if (get(handles.radiobutton_globaltimesignal,'Value') == get(handles.radiobutton_brainmaskON,'Max'))
  1404. axes(handles.axes2)
  1405. hold on
  1406. plot(rsfc.tRS,rsfc.yglobal);
  1407. end
  1408. % --- Executes on button press in radiobutton_globalfreqsignal.
  1409. function radiobutton_globalfreqsignal_Callback(hObject, eventdata, handles)
  1410. % hObject handle to radiobutton_globalfreqsignal (see GCBO)
  1411. % eventdata reserved - to be defined in a future version of MATLAB
  1412. % handles structure with handles and user data (see GUIDATA)
  1413. % Hint: get(hObject,'Value') returns toggle state of radiobutton_globalfreqsignal
  1414. global rsfc
  1415. if (get(handles.radiobutton_globalfreqsignal,'Value') == get(handles.radiobutton_brainmaskON,'Max'))
  1416. L = length(rsfc.yglobal);
  1417. NFFT = 2^nextpow2(L);
  1418. axes(handles.axes3)
  1419. hold on
  1420. semilogx(rsfc.f,2*abs(rsfc.meanyallf(1:NFFT/2+1)),'k','LineWidth',2);
  1421. xlim([0.005 1])
  1422. end
  1423. % --- Executes on button press in pushbutton_autoanalysis.
  1424. function pushbutton_autoanalysis_Callback(hObject, eventdata, handles)
  1425. % hObject handle to pushbutton_autoanalysis (see GCBO)
  1426. % eventdata reserved - to be defined in a future version of MATLAB
  1427. % handles structure with handles and user data (see GUIDATA)
  1428. global rsfc
  1429. y = rsfc.y;
  1430. [nY, nX, nT] = size(y);
  1431. brainIdx = find(rsfc.brain_mask == 1);
  1432. h1 = msgbox('Please select the seeds file');
  1433. uiwait(h1);
  1434. [filename,pathname] = uigetfile;
  1435. h2 = msgbox('please select the folder for output files');
  1436. uiwait(h2);
  1437. pathnameout = uigetdir;
  1438. load([pathname filename]);
  1439. load('atlas.mat');
  1440. ya = [328 328]; xa = [129 459];
  1441. fixedPoints = [[xi(1) yi(1)]; [xi(2) yi(2)]];
  1442. movingPoints = [[xa(1) ya(1)]; [xa(2) ya(2)]];
  1443. tform = fitgeotrans(movingPoints,fixedPoints,'nonreflectivesimilarity');
  1444. [xp,yp] = transformPointsForward(tform, xp, yp);
  1445. yp = round(yp);
  1446. xp = round(xp);
  1447. h = str2num(get(handles.seedsize,'string'));%Seed dimension will be h*2+1 x h*2+1
  1448. seedTC = zeros(length(xp),1);
  1449. filtandGRpower = zeros(length(xp),1);
  1450. unfiltpower= zeros(length(xp),1);
  1451. filteredpower= zeros(length(xp),1);
  1452. y1 = reshape(y,[nY*nX nT]);
  1453. y1 = y1(brainIdx,:);
  1454. for u=1:length(xp)
  1455. ySeed = squeeze(mean(mean(y(xp(u)+[-floor(h/2):floor(h/2)],yp(u)+[-floor(h/2):floor(h/2)],:),1),2));
  1456. ySeedunfilt = squeeze(mean(mean(rsfc.Iunfilt(xp(u)+[-floor(h/2):floor(h/2)],yp(u)+[-floor(h/2):floor(h/2)],:),1),2));
  1457. ySeedunGR = squeeze(mean(mean(rsfc.yunGR(xp(u)+[-floor(h/2):floor(h/2)],yp(u)+[-floor(h/2):floor(h/2)],:),1),2));
  1458. % yCC = (y*ySeed) ./ (std(y,[],2)*std(ySeed)) / length(ySeed);
  1459. yCC = corr(y1.',ySeed);
  1460. Chb1CC = zeros(nY,nX);
  1461. Chb1CC(brainIdx) = yCC;
  1462. f1 = figure(101); imagesc(Chb1CC,[-1 1]); colormap('jet'); text(yp(u),xp(u),'X');
  1463. saveas(f1, [pathnameout '/Seed' num2str(u) '.tif']);
  1464. close(f1);
  1465. seedTC(u) = mean(abs(yCC));
  1466. L = length(ySeed);
  1467. NFFT = 2^nextpow2(L); % Next power of 2 from length of y
  1468. ySeedf = fft(ySeed,NFFT)/L;
  1469. f = rsfc.fs/2*linspace(0,1,NFFT/2+1);
  1470. ySeedunfiltf = fft(ySeedunfilt,NFFT)/L;
  1471. ySeedunGRf = fft(ySeedunGR,NFFT)/L;
  1472. filtandGRpower(u) = rsfc.df*sum(abs(ySeedf).^2);
  1473. unfiltpower(u) = rsfc.df*sum(abs(ySeedunfiltf).^2);
  1474. filteredpower(u) = rsfc.df*sum(abs(ySeedunGRf).^2);
  1475. f2 = figure(202);
  1476. subplot(5,1,1)
  1477. plot(rsfc.tRS,ySeedunfilt);
  1478. xlabel('time');
  1479. ylabel('magnitude')
  1480. title('Unfiltered Signal');
  1481. subplot(5,1,2)
  1482. plot(rsfc.tRS,rsfc.yglobal);
  1483. xlabel('time');
  1484. ylabel('magnitude')
  1485. title('Global Unfiltered Signal');
  1486. subplot(5,1,3)
  1487. plot(rsfc.tRS,ySeed)
  1488. xlabel('time');
  1489. ylabel('magnitude');
  1490. title('Filtered Signal');
  1491. subplot(5,1,4)
  1492. semilogx(f,2*abs(ySeedf(1:NFFT/2+1)),'b','LineWidth',2);
  1493. hold on
  1494. xlim([0.005 1]);
  1495. semilogx(f,2*abs(ySeedunfiltf(1:NFFT/2+1)),'r','LineWidth',2);
  1496. title('Frequency Spectrum');
  1497. xlabel('frequency');
  1498. ylabel('power');
  1499. subplot(5,1,5)
  1500. semilogx(f,2*abs(rsfc.meanyallf(1:NFFT/2+1)),'b','LineWidth',2);
  1501. xlim([0.005 1]);
  1502. title('Golabl Frequency Spectrum');
  1503. xlabel('frequency');
  1504. ylabel('power');
  1505. saveas(f2, [pathnameout '/Seed' num2str(u) 'plot.tif']);
  1506. close(f2);
  1507. end
  1508. T = table(seedTC, filtandGRpower, unfiltpower, filteredpower);
  1509. writetable(T,[pathnameout '/Outputdata.csv']);
  1510. function edit_filterunGR_Callback(hObject, eventdata, handles)
  1511. % hObject handle to edit_filterunGR (see GCBO)
  1512. % eventdata reserved - to be defined in a future version of MATLAB
  1513. % handles structure with handles and user data (see GUIDATA)
  1514. % Hints: get(hObject,'String') returns contents of edit_filterunGR as text
  1515. % str2double(get(hObject,'String')) returns contents of edit_filterunGR as a double
  1516. % --- Executes during object creation, after setting all properties.
  1517. function edit_filterunGR_CreateFcn(hObject, eventdata, handles)
  1518. % hObject handle to edit_filterunGR (see GCBO)
  1519. % eventdata reserved - to be defined in a future version of MATLAB
  1520. % handles empty - handles not created until after all CreateFcns called
  1521. % Hint: edit controls usually have a white background on Windows.
  1522. % See ISPC and COMPUTER.
  1523. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1524. set(hObject,'BackgroundColor','white');
  1525. end
  1526. % --- Executes on button press in pushbutton_selectInfarctRegion.
  1527. function pushbutton_selectInfarctRegion_Callback(hObject, eventdata, handles)
  1528. % hObject handle to pushbutton_selectInfarctRegion (see GCBO)
  1529. % eventdata reserved - to be defined in a future version of MATLAB
  1530. % handles structure with handles and user data (see GUIDATA)
  1531. global rsfc
  1532. global rsfc
  1533. while(1)
  1534. axes(handles.axes1)
  1535. MinMinS = min(rsfc.I0(:)); MaxMaxS = max(rsfc.I0(:));
  1536. while(1)
  1537. imagesc(rsfc.I0(:,:,1),[ MinMinS MaxMaxS]); colorbar;
  1538. colormap('gray');
  1539. button = questdlg('Are you happy with the image contrast?','Repeat selection or not...','No');
  1540. if strcmp(button,'No')
  1541. answer= inputdlg({'Enter minimum intensity level of survey scan image'},'Enter minimum intensity level:',1,{num2str(MinMinS)}); % {'0'});
  1542. answer1 = cell2struct(answer, 'number', 1);
  1543. MinMinS = str2num(answer1.number);
  1544. answer= inputdlg({'Enter maximum intensity level of survey scan image'},'Enter maximum intensity level:',1,{num2str(MaxMaxS)}); % {'0'});
  1545. answer1 = cell2struct(answer, 'number', 1);
  1546. MaxMaxS = str2num(answer1.number);
  1547. else
  1548. break;
  1549. end
  1550. end
  1551. rsfc.MaxS = MaxMaxS;
  1552. rsfc.MinS = MinMinS;
  1553. h = msgbox(' Please select the brain region');
  1554. uiwait(h)
  1555. % axes(handles.axes6)
  1556. % imagesc(rsfc.yLRC,[-1 1]);
  1557. [brain_mask,Xi,Yi] = roipoly;
  1558. hold on;
  1559. plot(Xi,Yi,'color','k');
  1560. hold off;
  1561. button = questdlg('Are you statisfied with ROI?');
  1562. if strcmp(button, 'Yes')
  1563. break;
  1564. end
  1565. end
  1566. if (get(handles.radiobutton4,'Value') == get(handles.radiobutton4,'Max'))
  1567. figure; imshow(rsfc.I0,[MinMinS MaxMaxS]); colormap('gray');
  1568. end
  1569. % save('rsfc_brainMask.mat','brain_mask','Xi','Yi');
  1570. rsfc.infarct_mask = brain_mask;
  1571. % rsfc.Xi = Xi;
  1572. % rsfc.Yi = Yi;

rsfcGUI.m at commit 80811b6, no license · at the source

Overview

Authors: Bengisu Solgun1, Buket Dönmez-Demir1, Aslıhan Bahadır-Varol1, Hülya Karataş, Şefik Evren Erdener1
  1. Hacettepe University, Institute of Neurological Sciences and Psychiatry, Ankara, Turkey
Institutions: Hacettepe University (Türkiye)
Journal: Neurophotonics, volume 13, issue 2, article 025006
Dates: received 21 July 2025; accepted 26 February 2026; published online 24 March 2026; in print April 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1117/1.nph.13.2.025006 · PMID 41884118 · PMCID PMC13012183 · OpenAlex W7140201567
Open access: gold, a free copy (OpenAlex)
Status: code verified (how the code is found and verified)
Categories: mouse (organism)
Methods: Spectral & time-frequency, Connectivity, Statistics, Preprocessing, fMRI & imaging
Keywords: mouse skull, optical clearing, optical transparent window, cortical spreading depression, laser speckle contrast imaging, intrinsic optical signal imaging
Topic: Optical Imaging and Spectroscopy Techniques (Radiology, Nuclear Medicine and Imaging, Medicine), according to OpenAlex
Citations: not cited yet (Europe PMC); 73 references in the paper

Abstract

Significance: Transcranial imaging windows are crucial for in vivo imaging in rodents. Although conventional methods such as open-skull and thinned-skull windows have been widely utilized, minimally invasive skull clearing methods have recently been developed and have yet to be comprehensively evaluated for chronic mesoscopic imaging in awake mice.

Aim: We aimed to methodically compare and modify current topical skull optical clearing methods in search of an optimal technique for chronic awake widefield imaging.

Approach: We used widefield intrinsic optical-signal imaging and laser speckle contrast imaging to investigate the applicability of these methods.

Results: Application of a UV-curable optical adhesive, NOA61 both as a monotreatment and in combination with EDTA, proved suitable for long-term awake mesoscopic imaging, providing long-term global transparency. The previously described Triple-S method led to inflammatory-like reaction and/or opacification of the window over subsequent days. Cyanoacrylate or methyl-methacrylate (Metabond-equivalent) treatments, on the other hand, led to drying artifacts, occluding parts of the window. Therefore, these latter methods made awake bihemispheric imaging impractical. EDTA-NOA61 combination was then tested for documenting interhemispheric connectivity changes following optogenetic triggering of cortical spreading depolarizations.

Conclusions: We discussed the advantages and drawbacks of previous skull clearing methods and identified suitable methods for awake mesoscopic chronic imaging. These findings highlight the importance of minimally invasive skull optical clearing methods for widefield use in awake mice.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repository

Its files are read in the Code ↔ Paper reader above.

BUNPC/rsfcIOS

License: none: the authors keep all their rights
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: 80811b6453fb2a4ce3940541af046fb5a8ee9118, 9 June 2021
Languages: MATLAB (2)
Size: 7 files, 2 scripts
Software Heritage: not archived
Found in: “Code and Data Availability”
Holds: README
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
3 files

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 2 scripts, each with its path and the digest of its content;
  • no match between paragraphs and code yet;
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Code and Data Availability

The data sets generated and analyzed during the current study are available on FigShare repository (https://doi.org/10.6084/m9.figshare.c.7933739). For functional connectivity analysis, publicly available MATLAB code by Boston University Neurophotonics Center was used (https://github.com/BUNPC/rsfcIOS).

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 5 authors, 6 keywords, 71 references.

Cite

This paper

Solgun, B., Dönmez-Demir, B., Bahadır-Varol, A., Karataş, H., & Erdener, Ş. E. (2026). Choosing a skull clearing technique for chronic mesoscopic optical imaging in awake mice. Neurophotonics, 13(2), 025006. https://doi.org/10.1117/1.nph.13.2.025006

BibTeX

@article{solgun2026choosing,
author = {Solgun, Bengisu and Dönmez-Demir, Buket and Bahadır-Varol, Aslıhan and Karataş, Hülya and Erdener, Şefik Evren},
title = {{Choosing a skull clearing technique for chronic mesoscopic optical imaging in awake mice}},
journal = {Neurophotonics},
year = {2026},
month = mar,
volume = {13},
number = {2},
pages = {025006},
publisher = {Society of Photo-Optical Instrumentation Engineers},
issn = {2329-423X},
doi = {10.1117/1.nph.13.2.025006},
url = {https://doi.org/10.1117/1.nph.13.2.025006},
pmid = {41884118},
pmcid = {PMC13012183}
}

RIS

TY - JOUR
AU - Solgun, Bengisu
AU - Dönmez-Demir, Buket
AU - Bahadır-Varol, Aslıhan
AU - Karataş, Hülya
AU - Erdener, Şefik Evren
TI - Choosing a skull clearing technique for chronic mesoscopic optical imaging in awake mice
T2 - Neurophotonics
J2 - Neurophotonics
PY - 2026
DA - 2026/03/24
VL - 13
IS - 2
SP - 025006
SN - 2329-423X
PB - Society of Photo-Optical Instrumentation Engineers
DO - 10.1117/1.nph.13.2.025006
UR - https://doi.org/10.1117/1.nph.13.2.025006
LA - en
ER -

CSL-JSON

{
"id": "10.1117/1.nph.13.2.025006",
"type": "article-journal",
"title": "Choosing a skull clearing technique for chronic mesoscopic optical imaging in awake mice",
"container-title": "Neurophotonics",
"author": [
{
"family": "Solgun",
"given": "Bengisu"
},
{
"family": "Dönmez-Demir",
"given": "Buket"
},
{
"family": "Bahadır-Varol",
"given": "Aslıhan"
},
{
"family": "Karataş",
"given": "Hülya"
},
{
"family": "Erdener",
"given": "Şefik Evren"
}
],
"container-title-short": "Neurophotonics",
"volume": "13",
"issue": "2",
"page": "025006",
"DOI": "10.1117/1.nph.13.2.025006",
"PMID": "41884118",
"PMCID": "PMC13012183",
"ISSN": "2329-423X",
"publisher": "Society of Photo-Optical Instrumentation Engineers",
"URL": "https://doi.org/10.1117/1.nph.13.2.025006",
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
24
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41593-022-01245-9 [code]
Pyramidal cell types drive functionally distinct cortical activity patterns during decision-making.
Journal: Nature neuroscience
In common: 8 references
[2] doi:10.1038/s41467-025-62836-1
SeeThrough: a rationally designed skull clearing technique for in vivo brain imaging.
Journal: Nature communications
In common: mouse, 6 references
[3] doi:10.1117/1.nph.11.3.034310 [code]
Widefield &lt;i&gt;in vivo&lt;/i&gt; imaging system with two fluorescence and two reflectance channels, a single sCMOS detector, and shielded illumination.
Journal: Neurophotonics
In common: 7 references
[4] doi:10.1038/s41467-023-35824-6 [code]
Distributed context-dependent choice information in mouse posterior cortex.
Journal: Nature communications
In common: Signal Processing Toolbox, mouse, 6 references
[5] doi:10.1038/s42003-023-05630-3 [code]
Transcranial photobiomodulation improves insulin therapy in diabetic microglial reactivity and the brain drainage system.
Journal: Communications biology
In common: Signal Processing Toolbox, mouse, 4 references
[6] doi:10.1016/j.neuron.2022.07.017 [code]
Task specificity in mouse parietal cortex.
Journal: Neuron
In common: Signal Processing Toolbox, mouse, 5 references
[7] doi:10.1038/s41467-026-71074-y [code]
Cortex-wide characterization of decision-making neural dynamics during spatial navigation.
Journal: Nature communications
In common: mouse, 6 references
[8] doi:10.1523/eneuro.0096-23.2023 [code]
Meso-Py: Dual Brain Cortical Calcium Imaging in Mice during Head-Fixed Social Stimulus Presentation.
Journal: eNeuro
In common: Signal Processing Toolbox, mouse, 5 references
[9] doi:10.1016/j.neuron.2023.05.008 [code]
Mouse frontal cortex mediates additive multisensory decisions.
Journal: Neuron
In common: mouse, 6 references
[10] doi:10.1101/2024.02.12.579892 [code]
Zapit: Open Source Laser-Scanning Photostimulation For Neuroscience
Journal: bioRxiv (preprint)
In common: mouse, 5 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Add the badge to the code's README

OSCR: the badge of this paper

If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.

Markdown
<!-- oscr-badge:start -->
[![OSCR](https://openscicode.org/badge/doi/10.1117/1.nph.13.2.025006.svg)](https://openscicode.org/badge/doi/10.1117/1.nph.13.2.025006)
<!-- oscr-badge:end -->
reStructuredText
.. oscr-badge:start

.. image:: https://openscicode.org/badge/doi/10.1117/1.nph.13.2.025006.svg
   :target: https://openscicode.org/badge/doi/10.1117/1.nph.13.2.025006
   :alt: OSCR

.. oscr-badge:end
HTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1117/1.nph.13.2.025006"><img src="https://openscicode.org/badge/doi/10.1117/1.nph.13.2.025006.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->

On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".

If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.

Report a mismatch between the code and the paper · Report a code error (signed in)

Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.

Report a reproduction failure (signed in)

Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.