├── .gitignore
├── AutomatedAnalysis.m
├── LICENSE.md
├── README.md
├── SpectralPipeline.m
├── chronic
├── ChronicFindNonMatches.m
├── ChronicMatching.m
├── ChronicMatchingUpdate.m
├── ImageRegistrationApp
│ ├── ImageReg2P.prj
│ ├── README.md
│ ├── config
│ │ ├── createConfig.m
│ │ ├── default_config.mat
│ │ └── resetConfig.m
│ ├── dep
│ │ ├── CreateRGB2.m
│ │ ├── PyramidRegisterPair.m
│ │ ├── basicQueue.m
│ │ ├── cmapL.m
│ │ ├── fetchData.m
│ │ ├── fetchDir.m
│ │ ├── fetchFile.m
│ │ ├── getLargestImgRef.m
│ │ ├── mergeStructs.m
│ │ └── registerImgs.m
│ ├── finished_app
│ │ └── ImageReg2P.mlappinstall
│ ├── imgRegMain.mlapp
│ ├── res
│ │ ├── next-button.png
│ │ ├── save.png
│ │ └── upload.png
│ ├── tester.m
│ └── util
│ │ ├── getDate.m
│ │ ├── getIDName.m
│ │ ├── getImg.m
│ │ └── getMask.m
├── MoveLikeChronic.m
├── MoveLikeChronicFun.m
└── dep
│ ├── BImgOverlapScore.m
│ ├── ChronicViewer.m
│ ├── CutEmptyEdges.m
│ ├── CutEmptyEdgesImg.m
│ └── OverlapScore.m
├── docs
├── Figure_Analysis_Pipeline.png
├── Figure_spectral-Delier_20190916_002-1-Declutter.png
├── RoiManagerGUI_Manual_V4.pdf
└── Spectral-Segmentation_Manual.pdf
├── getSig
├── DeconvolveSignals.m
├── SbxSigPatches.m
├── SealSignals.m
├── autoRetrieveDecon.m
├── dep
│ ├── MLPest20210313.mat
│ ├── MLpest20180927.mat
│ ├── basecorrect.m
│ └── retrievesignals_parWB.m
└── retrievesignals.m
├── sbxConversions
├── Hdf52Sbx.m
├── Sbx2TiffStack.m
├── SbxCropTime.m
├── TiffImages2Sbx.m
├── TiffStack2OneSbx.m
├── TiffStack2Sbx.m
├── WriteSbx.m
└── mp4vid2Sbx.m
├── spectral
├── DecimateTrans.m
├── RoiManagerGUI.fig
├── RoiManagerGUI.m
├── SpectralColorImg.m
├── StackTranspose.m
├── dep
│ ├── PixelCor.m
│ ├── SpectParArm.fig
│ ├── SpectParArm.m
│ ├── Spectroiparm.m
│ ├── SummaryGetRois.m
│ ├── XYgetZ.m
│ ├── ZgetXY.m
│ ├── Zgetinfo.m
│ ├── Zorder.cpp
│ ├── Zorder.mexa64
│ ├── Zorder.mexmaci64
│ ├── Zorder.mexw64
│ ├── getCon.m
│ ├── getcontourlines.m
│ ├── getcorpow.m
│ ├── getcsdf.m
│ ├── getcsdfnd.m
│ ├── localmax.m
│ ├── perimarea.m
│ ├── roisfromlocalmax.m
│ ├── setminlevel.m
│ ├── smoothG.m
│ └── transmemap.m
├── getSpectrois.m
├── spectral.m
└── spectralOld.m
├── startup.m
└── util
├── BackgroundSubtractSbx.m
├── BackgroundSubtractSbxExampleFrame.m
├── EyeData2Avi.m
├── FluorescenceImgSbx.m
├── Mask3D_Flatten.m
├── PPModernize.m
├── PPfromMask.m
├── PPfromMaskFile.m
├── PrintBImg.m
├── PrintBImgs.m
├── RunPrintBImgs.m
├── SbxCropTimeTest.m
├── SbxZStack.m
├── ShiftLinesCheck.m
├── ShiftLinesSbx.m
├── Showsbx.m
├── SpatialCorrCalcRun.m
├── SpecProfileCalcRun.m
├── dep
├── AskDate.m
├── BufferMask.m
├── Colorbar2D.m
├── CorrRoiCorners.m
├── CreateRGB.m
├── CreateRGB2.m
├── CreateRGB2_mat.m
├── ETA.m
├── FindNNumInStr.m
├── GetCenteredFigPos.m
├── GetRoiCoM.m
├── GetRoiCorners.m
├── MidtoneBalance.m
├── PlotCon.m
├── PlotManyImgs.m
├── Register2Imgs.m
├── Register2ImgsNew.m
├── RemoveROIs.m
├── RotatePPCoordinates.m
├── SaveImg.m
├── SetLimits.m
├── ShiftLinesImg.m
├── Showsbx.html
├── SortROIsMask.m
├── SortROIsPP.m
├── SpatialCorrCalcFun.m
├── SpecProfileCalcFun.m
├── ViewVolumeRGB1.m
├── a.png
├── cmapL.m
├── cmapLimsAround0.m
├── figtitle.m
├── findjobj.m
├── getSystemMem.m
├── iconvideo.png
├── largestmemblock.m
├── license_xcorr2_ftt.txt
├── prctfilt.m
├── sbxread.m
├── sbxsigout.m
├── sbxsplit.m
├── subtightplot.m
├── sum.png
├── toolbar.PNG
└── xcorr2_fft.m
├── normcorreSpecSeg.m
├── sbx2ij.m
└── simonalign3.m
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | *.asv
3 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 2.0 Generic License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
2 |
--------------------------------------------------------------------------------
/SpectralPipeline.m:
--------------------------------------------------------------------------------
1 | %% Pipeline for spectral segmentation analysis
2 | %
3 | % Via this script all major steps of the spectral segmentation pipeline
4 | % for ROI selection and matching can be executed.
5 | % All of the functions can be called without input, the functions will
6 | % ask which file to analyse.
7 | % Be aware that your image sequence needs to be aligned in advance!
8 |
9 | % sbx data is required. TIFF can be converted to sbx
10 | %% Convert (multiple) tiff files that have multiple frames (full movie) to as many sbxfiles
11 | TiffStack2Sbx
12 |
13 | %% Convert multiple tiff files that have multiple frames to one sbx file
14 | TiffStack2OneSbx
15 |
16 | %% Convert a folder full of tiff files, each tif file consisting of 1 frame
17 | TiffImages2Sbx
18 |
19 | %% Convert H5 files to sbx
20 | Hdf52Sbx
21 |
22 |
23 | %% For 1 photon/ miniscope data background subtraction is necessary
24 | BackgroundSubtractSbx
25 |
26 |
27 | %% Correct for bidirectional scanning misalignment? uneven vs even lines shifted?
28 | % Also decreases really high values (>65500) to something low in the data!!
29 | trans = false; % false: Correct for horizontal lines. True: correct for vertical lines
30 | % Check for shift.
31 | ShiftLinesSbx([], trans, 1)
32 |
33 |
34 | %% Motion correct sbx data
35 | Showsbx
36 | % Press the A button for the Alignment/motion correction
37 | % Rightclick on main image to adjust color scale etc
38 |
39 | %% Transpose the motion corrected sbx file to improve reading speed
40 | % Creates _Trans.dat file
41 | StackTranspose
42 |
43 | %% Decimate the Trans.dat file to ~1 Hz, and convert data to double class
44 | % Creates _DecTrans.dat file
45 | DecimateTrans
46 |
47 | %% Calculate the cross spectral power for each pixel with 8 surrounding
48 | % pixels. Requires DecTrans.dat file to function
49 | % Creates _SPSIG.mat file
50 | spectral
51 |
52 | %% Create calcium fluorescence images (maximum and average projection)
53 | % Projections get saved into SPSIG file (and outputted into the workspace)
54 | FluorescenceImgSbx;
55 |
56 | %% Print pngs of fluorescence images & colored spectral (optional)
57 | % Uses images in the SPSIG file created by FLuorescenceImgSbx
58 | PrintBImgs
59 |
60 | %% ROI segmentation (neurons, or boutons)
61 | % ROIs, ROI properties and used spectral images get saved into SPSIG file
62 | getSpectrois
63 |
64 | %% Remove or add ROIS manually, display and compare roi sets
65 | % If save button is pressed, edits are made in the SPSIG file
66 | RoiManagerGUI
67 |
68 | %% Retrieve the signals associated with these rois from the aligned data
69 | % Signals get added to the _SPSIG file
70 | retrievesignals
71 |
72 | %% Create a fast Simple Estimate of Activity by Leander (SEAL)
73 | % Seal signal gets added to the _SPSIG file
74 | SealSignals
75 |
76 | %% deconvolve signals
77 | % MLspike spike estimation signals get added to the _SPSIG file
78 | DeconvolveSignals
79 |
80 | %% Match ROIs of multiple recordings together
81 | % Run this script step by step.
82 | ChronicMatching
83 |
84 |
--------------------------------------------------------------------------------
/chronic/ImageRegistrationApp/ImageReg2P.prj:
--------------------------------------------------------------------------------
1 |
Fixed | Moving |
---|---|
Image 1 | Image 2 |
Image 1 | Image 3 |
Image 1 | Image 4 |
Image 1 | Image 5 |
Fixed | Moving |
---|---|
Image 1 | Image 2 |
Image 2 | Image 3 |
Image 3 | Image 4 |
Image 4 | Image 5 |
10 |28 | 29 | 30 | -------------------------------------------------------------------------------- /util/dep/SortROIsMask.m: -------------------------------------------------------------------------------- 1 | function Mask = SortROIsMask(Mask, idx) 2 | % Re-Sort the ROIs in Mask and PP 3 | % [Mask, PP] = RemoveROIs(Mask, PP, badROIs) 4 | % 5 | % Input: 6 | % Mask - a 2D ROI Mask. 7 | % idx ([n x 1] double) - numbers indicating how to sort the ROIs 8 | % 9 | % Output: 10 | % Mask - Updated Mask. 11 | % 12 | % Leander de Kraker 13 | % 2023-9-6 14 | % 15 | 16 | 17 | maskNew = zeros(size(Mask)); 18 | for i = 1:length(idx) 19 | maskNew(Mask==i) = idx(i); 20 | end 21 | 22 | 23 | -------------------------------------------------------------------------------- /util/dep/SortROIsPP.m: -------------------------------------------------------------------------------- 1 | function PP = SortROIsPP(PP, idx) 2 | % Re-Sort the ROIs in Mask and PP 3 | % [Mask, PP] = RemoveROIs(Mask, PP, badROIs) 4 | % 5 | % Input: 6 | % PP - The standard ROI information struct from SpecSeg 7 | % idx ([n x 1] double) - numbers indicating how to sort the ROIs 8 | % 9 | % Output: 10 | % PP - Updated ROI information struct 11 | % 12 | % Leander de Kraker 13 | % 2023-9-6 14 | % 15 | 16 | 17 | PP.Con = PP.Con(idx); 18 | PP.A = PP.A(idx); 19 | PP.P = PP.P(:,idx); 20 | if isfield(PP, 'SpecProfile') 21 | PP.SpecProfile = PP.SpecProfile(idx); 22 | end 23 | if isfield(PP, 'peakFreq') 24 | PP.peakFreq = PP.peakFreq(idx); 25 | end 26 | if isfield(PP, 'peakVal') 27 | PP.peakVal = P.peakVal(idx); 28 | end 29 | if isfield(PP, 'Roundedness') 30 | PP.Roundedness = PP.Roundedness(idx); 31 | end 32 | if isfield(PP, 'Rvar') 33 | PP.Rvar = PP.Rvar(idx); 34 | end 35 | if isfield(PP, 'creationMethod') 36 | PP.creationMethod = PP.creationMethod(idx); 37 | end 38 | PP.Cnt = size(PP.P, 2); 39 | 40 | 41 | -------------------------------------------------------------------------------- /util/dep/SpatialCorrCalcFun.m: -------------------------------------------------------------------------------- 1 | function [cor, roiidx, r2] = SpatialCorrCalcFun(sbxt, freq, mask, roiNr, originPos, varargin) 2 | % [cor, roiidx, rvar] = SpatialCorrCalcFun(sbxt, freq, mask, roiNr, originPos, true) 3 | % Calculate the spatial corr of a ROI: correlation of the signal of 4 | % individual pixels with the signal of the median of 9 central ROI pixels 5 | % 6 | % Can also calculate the square of the correlation! 7 | % 8 | % inputs: 9 | % sbxt: transposed memorymapped sbxt from transmemap(transfile), 10 | % freq: 1x1 double, acuisition frequency of 2P data 11 | % mask: 2D double [height x width], the positions/ id's of ROIs 12 | % roiNr: which ROI to calculate the spatialcorr etc from 13 | % originPos: 1D vector [2 x 1] or 2D double [2 x nROIs] which x & y 14 | % coordinates are the 'origin position' 15 | % calcRvar (optional): boolean: true = return rvar 16 | % false = don't calculate rvar (default) 17 | % 18 | % outputs: 19 | % cor: 2D double, contains the correlation values, same size as mask 20 | % roiidx: the 1D indexes of where the ROI is located 21 | % rvar: variance of correlation values, after median filtering 22 | % 23 | % 24 | % Leander de Kraker 25 | % 2020-1-20 26 | % 27 | 28 | % Get whether to calculate rvar or not 29 | if nargin == 6 30 | calcR2 = varargin{1}; 31 | else 32 | calcR2 = false; 33 | end 34 | 35 | % Check if we got the actual coordinates for this ROI, or all coordinates 36 | if size(originPos, 1)>1 && size(originPos, 2)>1 37 | % Check if we need to transpose the coordinates... 38 | if size(originPos, 2)==2 && size(originPos, 1)>2 39 | originPos = originPos'; 40 | end 41 | originPos = originPos([1 2], roiNr); 42 | end 43 | 44 | % And round the coordinates to integers 45 | originPos = round(originPos); 46 | 47 | 48 | maskT = mask'; 49 | roiidx = find(maskT==roiNr); % The 2D indexes of the ROI, from transposed mask 50 | sigs = sbxt.Data.y(:,roiidx); % signal of all the pixels in the ROI 51 | 52 | % subsample the signal to ~1 sample / sec if the frequency is higher 53 | freq = floor(freq); 54 | if freq > 1.5 55 | sigSubsampled = zeros(ceil(size(sigs,1)/freq), size(sigs,2)); 56 | for q = 1:size(sigs,2) 57 | sigSubsampled(:,q) = decimate(double(sigs(:,q)), freq); 58 | end 59 | sigs = sigSubsampled; 60 | clearvars sigSubsampled 61 | end 62 | 63 | % Get the origin point of the ROI with 8 surrounding pixels: seedpixels 64 | seed = zeros(size(maskT), 'logical'); 65 | seedy = originPos(1)-1:originPos(1)+1; 66 | seedx = originPos(2)-1:originPos(2)+1; 67 | seedy(seedy<1 | seedy>size(maskT,1)) = []; % remove indexes that are outside mask 68 | seedx(seedx<1 | seedx>size(maskT,2)) = []; 69 | seed(seedy, seedx) = true; 70 | seedidx = find(seed); 71 | [~, seedidx] = intersect(roiidx, seedidx); % exlude pixels outside ROI 72 | 73 | % take median of signal seedpixels to reduce noise 74 | seedSig = median(sigs(:,seedidx), 2); 75 | 76 | % Fill the spatial correlation image with the correlation values 77 | cor = zeros(size(maskT)); 78 | cor(roiidx) = corr(seedSig, sigs, 'rows', 'pairwise'); 79 | 80 | 81 | % Calculate the mean R squared 82 | if calcR2 83 | thr = 0.5 * max(abs(cor(:))); 84 | if thr < 0.5 85 | %smooth with median filter, since with lower cutoff more variable 86 | %correlations are included leading to noisy contours 87 | m = floor((1-thr)*3)* 2 + 1; % let median filter depend on threshold height 88 | corFiltered = medfilt2(cor, [m m]); 89 | else 90 | corFiltered = cor; 91 | end 92 | r2 = mean(corFiltered(roiidx).^2); 93 | else 94 | r2 = nan; 95 | end 96 | 97 | % Transpose to the original size 98 | cor = cor'; 99 | roiidx = find(mask==roiNr); % The 2D indexes of the ROI 100 | 101 | -------------------------------------------------------------------------------- /util/dep/SpecProfileCalcFun.m: -------------------------------------------------------------------------------- 1 | function [specProfiles, peakFreq, peakVal] = SpecProfileCalcFun(spec, mask, rois, specAx) 2 | % specProfiles = SpecProfileCalcFun(spec, mask, specAx) calculates the 3 | % spectral profiles for all the ROIs in the mask. 4 | % [specProfiles, peakFreq] = SpecProfileCalcFun(spec, mask, specAx) also 5 | % returns the frequency which has the highest spectral power values for 6 | % each ROI in peakFreq 7 | % 8 | % This function can be executed via SpecProfileCalcRun.m 9 | % 10 | % inputs: 11 | % spec: spectral components: 3D matrix [width x height x frequency] 12 | % The 0Hz component should be removed to conform with standard way 13 | % mask: 2D double: with ROI IDs [height x width] 14 | % rois: 1D double: which rois to analyze? 15 | % specAx: spectral axis: 1D double with the frequency of each spectral 16 | % component (0 Hz should already be removed) 17 | % 18 | % outputs: 19 | % specProfiles: 2D double [frequency x ROIs], with the average spectral 20 | % power of each ROI for all the frequencies (except 0Hz). 21 | % peakFreq: 1D double [ROIs] with the frequency at which each the 22 | % spectral power was highest. 23 | % 24 | % 25 | % Leander de Kraker 26 | % 2020-1-21 27 | % Adapted , added smoothing 28 | % Chris van der togt 29 | % 2020-4-30 30 | 31 | % Does the spec need transposing (permuting)? 32 | if size(spec, 1) ~= size(mask, 1) 33 | if size(spec, 1) == size(mask, 2) 34 | fprintf('permuted spec to enable analysis\n') 35 | spec = permute(spec, [2 1 3]); 36 | else 37 | warning('sizes of spec and mask seem incompatible!') 38 | return 39 | end 40 | end 41 | 42 | nSpec = size(spec, 3); 43 | nRois = length(rois); 44 | 45 | if length(specAx) ~= nSpec 46 | warning('difference between spectral frequency axis and spec 3rd dimension!') 47 | end 48 | 49 | 50 | SP = reshape(spec, [], nSpec); 51 | % Retrieve the spectral profiles 52 | specProfiles = zeros(nSpec, nRois); 53 | for i = 1:nRois 54 | roii = mask == rois(i); 55 | roii = roii(:); 56 | spfl = SP(roii, :); 57 | specProfiles(:,i) = mean(spfl); 58 | end 59 | 60 | % Calculate which frequency had the highest spectral power values 61 | [peakVal, peakFreqidx] = max(smoothG(specProfiles,2)); 62 | peakFreq = specAx(peakFreqidx); 63 | 64 | 65 | -------------------------------------------------------------------------------- /util/dep/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leveltlab/SpectralSegmentation/145eac1dc90475f0d0b06456a9fe386d8ef9e227/util/dep/a.png -------------------------------------------------------------------------------- /util/dep/cmapLimsAround0.m: -------------------------------------------------------------------------------- 1 | function extend = cmapLimsAround0(img, n) 2 | % extend = cmapLimsAround0(img, n) 3 | % Get how many colors should be used for which color to center the colors 4 | % around the value 0 of the img 5 | % 6 | % input: 7 | % - img (xD double): data to base colormap around 8 | % - n (number of colors in colormap) 9 | % 10 | % Output: 11 | % - extend ([n-1 x 1] double): amount of colors to take for each 12 | % 13 | % Example: 14 | % img = randn(25,25)+2; 15 | % colors1 = [0 1 0; 0 0 0; 1 0 0]; 16 | % n1 = 3; 17 | % 18 | % n = cmapLimsAround0(img, n1); % Get how many colors to take for each color 19 | % colorsMap = cmapL(colors1, n); % Use that to get the colormap 20 | % imagesc(img) 21 | % colormap(colorsMap); 22 | % colorbar 23 | % % Another set of colors 24 | % colors1 = 'blue roast'; % italian roast has 7 colors 25 | % n1 = 7; 26 | % n = cmapLimsAround0(img, n1); % Get how many colors to take for each color 27 | % colorsMap = cmapL(colors1, n); 28 | % colormap(colorsMap) 29 | % 30 | % Leander de Kraker 31 | % 2024-4-23 32 | % 33 | 34 | extend = [max(img(:)), min(img(:))]; 35 | extend = abs(round(extend./abs(diff(extend)).*256)); 36 | if n > 3 37 | n = floor(n/2); 38 | extend = floor([repmat(extend(1), [1 n]), repmat(extend(2),[1 n])]./n); 39 | end -------------------------------------------------------------------------------- /util/dep/figtitle.m: -------------------------------------------------------------------------------- 1 | function [ fth ] = figtitle(titlestring,varargin) 2 | % FIGTITLE creates a title centered at the top of a figure. This may be used 3 | % to add a title to a figure with several subplots. 4 | % 5 | % 6 | %% Syntax 7 | % 8 | % figtitle('TitleString') 9 | % figtitle('TitleString','TextProperty','TextValue') 10 | % h = figtitle(...) 11 | % 12 | % 13 | %% Description 14 | % 15 | % figtitle('TitleString') centers a title at the top of a figure and sets 16 | % the figure name to TitleString. 17 | % 18 | % figtitle('TitleString','TextProperty',TextValue) formats the title with 19 | % property name value pairs (e.g., 'FontSize',20) 20 | % 21 | % h = figtitle(...) returns a handle of the newly-created title. 22 | % 23 | %% EXAMPLE 1: 24 | % 25 | % x = 1:.01:7; 26 | % y = sin(x); 27 | % 28 | % figure; 29 | % subplot(2,2,1) 30 | % plot(3*x,y) 31 | % title('Exp. 1') 32 | % 33 | % subplot(2,2,2) 34 | % plot(x,2*y+x) 35 | % title('Exp. 2') 36 | % 37 | % subplot(2,2,3) 38 | % plot(x,y) 39 | % title('Exp. 3') 40 | % 41 | % subplot(2,2,4) 42 | % plot(x,2*y) 43 | % title('Exp. 4') 44 | % 45 | % figtitle('My Experimental Results','fontweight','bold'); 46 | % 47 | %% EXAMPLE 2: A prettier example using ntitle: 48 | % 49 | % x = 1:.01:7; 50 | % y = sin(x); 51 | % 52 | % figure; 53 | % subplot(2,2,1) 54 | % plot(3*x,y) 55 | % ntitle('experiment 1','fontsize',12) 56 | % box off 57 | % 58 | % subplot(2,2,2) 59 | % plot(x,2*y+x) 60 | % ntitle('experiment 2','fontsize',12) 61 | % box off 62 | % 63 | % subplot(2,2,3) 64 | % plot(x,-y+5*x) 65 | % ntitle('experiment 3','fontsize',12) 66 | % box off 67 | % 68 | % subplot(2,2,4) 69 | % plot(x,2*y-3*x) 70 | % ntitle('experiment 4','fontsize',12); 71 | % box off 72 | % 73 | % figtitle(' My Experimental Results') 74 | % 75 | % * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % 76 | % 77 | % In many cases a figure title may overlap a subplot title 78 | % To reduce the possibility of a figure title overlapping subplot 79 | % titles, try pairing this function with the ntitle function, which 80 | % is available on the Mathworks File Exchange here: 81 | % http://www.mathworks.com/matlabcentral/fileexchange/42114-ntitle 82 | % 83 | % 84 | % * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % 85 | % Written by Chad A. Greene of the University of Texas at Austin 86 | % Institute for Geophysics, July 2013. 87 | % 88 | % Updated August 2014 to include support for invisible figures 89 | % and now also sets the figure name to the title string. 90 | % 91 | % * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % 92 | % 93 | % See also title, text, and ntitle. 94 | 95 | 96 | % Get the handle of the current axes and properties: 97 | hca = gca; 98 | fontsize = get(hca,'fontsize'); 99 | 100 | % Create a new set of axes the size of the entire figure: 101 | h = axes('position',[0 0 1 1],'units','normalized'); 102 | 103 | axes('Units','normalized',... 104 | 'Position',[0 0 1 1],... 105 | 'Visible','off',... 106 | 'XTick',[],... 107 | 'YTick',[],... 108 | 'Box','off'); 109 | 110 | % Make a title: 111 | fth = text(.5,1,titlestring,... 112 | 'units','normalized',... 113 | 'horizontalalignment','center',... 114 | 'verticalalignment','top',... 115 | 'fontsize',fontsize+2); 116 | 117 | % Set optional inputs: 118 | if nargin>1 119 | set(fth,varargin{:}); 120 | end 121 | 122 | % Now go back to from where we came: 123 | delete(h) 124 | 125 | set(gcf,'CurrentAxes',hca,'name',titlestring); 126 | 127 | % Return the title handle only if it is desired: 128 | if nargout==0 129 | clear fth; 130 | end 131 | 132 | end 133 | 134 | -------------------------------------------------------------------------------- /util/dep/getSystemMem.m: -------------------------------------------------------------------------------- 1 | function SysMem = getSystemMem() 2 | % get available memory 3 | 4 | SysMem = []; 5 | archstr = computer('arch'); 6 | %only for fwindows available 7 | if strcmp(archstr, 'win64') 8 | usr = memory(); 9 | SysMem = usr.MemAvailableAllArrays; 10 | 11 | elseif strcmp(archstr, 'glnxa64') 12 | [~, Memstr] = system("free -b | awk '/^Mem/ {print $4}'"); 13 | SysMem = str2double(Memstr); 14 | 15 | elseif strcmp(archstr, 'maci64') 16 | [~, Memstr] = system("sysctl hw.memsize | awk '{print $2}'"); 17 | SysMem = str2double(Memstr); 18 | end -------------------------------------------------------------------------------- /util/dep/iconvideo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leveltlab/SpectralSegmentation/145eac1dc90475f0d0b06456a9fe386d8ef9e227/util/dep/iconvideo.png -------------------------------------------------------------------------------- /util/dep/largestmemblock.m: -------------------------------------------------------------------------------- 1 | function largestmemblock(varargin) 2 | % LARGESETMEMBLOCK(VERBOSITY,PRECISION) 3 | % Finds (roughly) the largest memory block available by 4 | % trying to allocate successively larger contiguous blocks of memory. 5 | % Precise roughly to about 90% of the largest memory block available. 6 | % 7 | % Arguments: 8 | % VERBOSITY: '-v' flag. Specify all iterations tried 9 | % PRECISION: Fraction between [0.7, 0.9999]. 10 | % Value closer to 0.7 return a quicker result, but up to 70% precision 11 | % Value closer to 1 returns a more precise result, but takes much 12 | % longer to converge 13 | % Default is 0.95 14 | % 15 | % Not as accurate as feature('memstats'), but useful as an approximation 16 | % on 32-bit and 64-bit Mac and Linux distributions 17 | % 18 | % % No verbosity 19 | % >> largestmemblock 20 | % 21 | % % Verbose output 22 | % >> largestmemblock('-v') 23 | % 24 | % % More accurate estimate of largest memory block available, no verbosity 25 | % >> largestmemblock([],0.999) 26 | % 27 | % % More accurate value, longer execution time 28 | % 29 | % v1.0 - November 2009, Manu Raghavan 30 | 31 | if nargin>=1 && ~isempty(varargin{1}) 32 | verbosity = true; 33 | else 34 | verbosity = false; 35 | end 36 | 37 | precision = 0.95; 38 | if nargin==2 39 | precision = varargin{2}; 40 | if(precision>0.9999 || precision<0.7) 41 | error('Optional second argument PRECISION must range between 0.7 and 0.9999'); 42 | end 43 | end 44 | 45 | mexExtension = mexext; 46 | 47 | if (strcmp(mexExtension,'mexglx') || ... 48 | strcmp(mexExtension,'mexmaci') || ... 49 | strcmp(mexExtension,'mexw32')) 50 | % Initial size 51 | B = intmax('int32'); %2 Gigabytes 52 | end 53 | 54 | if (strcmp(mexExtension,'mexa64') || ... 55 | strcmp(mexExtension,'mexmaci64') || ... 56 | strcmp(mexExtension,'mexw64')) 57 | % Initial size 58 | %B = 8*2^40; %8 Terabytes 59 | B = 60*2^30; %8 Gigabytes 60 | end 61 | 62 | % Iterative memory allocation attempts 63 | while true 64 | try 65 | if(verbosity) 66 | fprintf(1,'Trying to allocate %d KB.', B/1024); 67 | end 68 | A = zeros(round(B), 1, 'uint8'); 69 | break; 70 | catch ME 71 | if(verbosity) 72 | fprintf(2,'\n Unsuccessful. Reducing block size and trying again...\n'); 73 | end 74 | % Rethrow any non-out-of-memory errors 75 | if ~strcmp(ME.identifier, 'MATLAB:nomem'); 76 | rethrow(ME); 77 | end 78 | end 79 | % Reduce by a factor of 10% and try again 80 | B = B*precision; 81 | end 82 | 83 | % Report the results 84 | fprintf(... 85 | '\nMaximum contiguous block is approximately:\n (Accurate to %2.2f %% of real memory value)\n %15.0f KB\n %15.0f MB\n', ... 86 | precision*100, B/1024, B/(1024^2)); 87 | 88 | % Clear the big variable 89 | clear A 90 | -------------------------------------------------------------------------------- /util/dep/license_xcorr2_ftt.txt: -------------------------------------------------------------------------------- 1 | Alessandro Masullo (2020). xcorr2_fft(a,b) (https://www.mathworks.com/matlabcentral/fileexchange/53570-xcorr2_fft-a-b), MATLAB Central File Exchange. Retrieved May 18, 2020. 2 | 3 | Copyright (c) 2015, Alessandro Masullo 4 | All rights reserved. 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution 14 | * Neither the name of the University of Bristol nor the names 15 | of its contributors may be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /util/dep/prctfilt.m: -------------------------------------------------------------------------------- 1 | function Y = prctfilt(X,p,window,shift,mode) 2 | 3 | % percentile filtering along the last dimension 4 | % INPUTS 5 | % X: input data 6 | % p: percentile 7 | % window: window over which to compute the percentile 8 | % shift: length of window shifting (default: window) 9 | % mode: if mode == 1 then returns Y - baseline, otherwise returns baseline 10 | 11 | % OUTPUT 12 | % Y: filtered version 13 | 14 | if nargin < 2 || isempty(p); p = 20; end 15 | if nargin < 3 || isempty(window); window = 200; end 16 | if nargin < 4 || isempty(shift); shift = 200; end 17 | if nargin < 5 || isempty(mode); mode = 1; end 18 | 19 | sizX = size(X); 20 | if ndims(X) == 1 21 | X = X(:)'; 22 | elseif ~ismatrix(X) 23 | X = reshape(X,[],sizX(end)); 24 | end 25 | 26 | window = min(window,sizX(end)); 27 | shift = min(shift,window); 28 | 29 | Xpad = [X(:,1:ceil((window-1)/2)),X,X(:,sizX(end) - (ceil((window-1)/2)-1:-1:0))]; 30 | 31 | blocks_end = window:shift:size(Xpad,2); 32 | blocks_start = 1:shift:size(Xpad,2); 33 | ln = length(blocks_end); 34 | blocks_start(ln+1:end) = []; 35 | 36 | Xpcs = zeros(size(Xpad,1),ln); 37 | for i = 1:ln 38 | Xpcs(:,i) = prctile(Xpad(:,blocks_start(i):blocks_end(i)),p,2); 39 | end 40 | 41 | dx = diff(Xpcs,1,2); 42 | 43 | Xf = kron(Xpcs(:,1:end-1),ones(1,shift)) + kron(dx,1/shift*(0:shift-1)); 44 | Xf = padarray(Xf,[0,size(X,2)-shift*(ln-1)],'post','symmetric'); 45 | if mode == 1 46 | Y = X - Xf; 47 | else 48 | Y = Xf; 49 | end 50 | Y = reshape(Y,sizX); -------------------------------------------------------------------------------- /util/dep/sbxread.m: -------------------------------------------------------------------------------- 1 | function x = sbxread(fname,k,N,varargin) 2 | 3 | % img = sbxread(fname,k,N,varargin) 4 | % 5 | % Reads from frame k to k+N-1 in file fname 6 | % 7 | % fname - the file name (e.g., 'xx0_000_001') 8 | % k - the index of the first frame to be read. The first index is 0. 9 | % N - the number of consecutive frames to read starting with k. 10 | % 11 | % If N>1 it returns a 4D array of size = [#pmt rows cols N] 12 | % If N=1 it returns a 3D array of size = [#pmt rows cols] 13 | % 14 | % gpu version [rows cols #pmt N] 15 | % 16 | % #pmts is the number of pmt channels being sampled (1 or 2) 17 | % rows is the number of lines in the image 18 | % cols is the number of pixels in each line 19 | % 20 | % 21 | % The function also creates a global 'info' variable with additional 22 | % informationi about the file 23 | 24 | global info 25 | 26 | persistent Perm Shape 27 | 28 | 29 | % check if already loaded... 30 | if isempty(info) || (~isempty(info) && ~strcmp(fname, info.strfp)) 31 | if ~isempty(info) 32 | try 33 | fclose(info.fid); 34 | catch 35 | end 36 | info = []; 37 | end 38 | 39 | load(fname); 40 | info.strfp = fname; 41 | 42 | % if(exist([fname ,'.align'])) % aligned? 43 | % info.aligned = load([fname ,'.align'],'-mat'); 44 | % else 45 | % info.aligned = []; 46 | % end 47 | 48 | if(~isfield(info,'sz')) 49 | info.sz = [512 796]; % it was only sz = .... 50 | end 51 | 52 | switch info.channels 53 | case 1 54 | info.nchan = 2; % both PMT0 & 1 55 | case 2 56 | info.nchan = 1; % PMT 0 57 | case 3 58 | info.nchan = 1; % PMT 1 59 | end 60 | 61 | 62 | if ~isfield(info,'Perm') 63 | Perm = [1 3 2 4]; %1st dim is channel 64 | Shape = [info.nchan info.sz(2) info.sz(1)]; 65 | if info.scanbox_version == 2.5 || isfield(info, 'simon') %gpu or processed 66 | Perm = [2 1 3 4]; %3rd dim is channel 67 | Shape = [info.sz(2) info.sz(1) info.nchan]; 68 | end 69 | info.Perm = Perm; 70 | info.Shape = Shape; 71 | else 72 | if length(info.Perm) == 3 %there is a bug somewhere! 73 | disp('info.Perm was incorrect!!') 74 | info.Perm = [info.Perm 4]; 75 | % save(fname, 'info'); 76 | end 77 | Perm = info.Perm; 78 | Shape = info.Shape; 79 | end 80 | 81 | info.fid = fopen([fname '.sbx']); 82 | d = dir([fname '.sbx']); 83 | info.max_idx = round(d.bytes/info.sz(2)/info.sz(1)/info.nchan/2); 84 | info.nsamples = (info.sz(2) * info.sz(1) * 2 * info.nchan); % bytes per frame 85 | 86 | elseif isempty(Perm) || isempty(Shape) 87 | Perm = info.Perm; 88 | Shape = info.Shape; 89 | end 90 | 91 | if(isfield(info,'fid') && info.fid ~= -1 && k + N > 0) 92 | 93 | % nsamples = info.postTriggerSamples * info.recordsPerBuffer; 94 | try 95 | fseek(info.fid,k*info.nsamples,'bof'); 96 | x = fread(info.fid,info.nsamples/2 * N,'uint16=>uint16'); 97 | %changed for gpu version 98 | x = reshape(x,[Shape N]); 99 | 100 | catch 101 | error('Cannot read frame. Index range likely outside of bounds.'); 102 | end 103 | %changed for gpu version 104 | if isfield(info, 'simon') 105 | x = permute(x,Perm); 106 | else 107 | x = intmax('uint16')-permute(x,Perm); 108 | end 109 | 110 | else 111 | x = []; 112 | end -------------------------------------------------------------------------------- /util/dep/sbxsigout.m: -------------------------------------------------------------------------------- 1 | function sbxsigout(~,~) 2 | 3 | global info 4 | persistent Sbx filenm 5 | 6 | h = imrect(); 7 | pos = round(wait(h)); 8 | x = pos(1):pos(1)+pos(3); 9 | y = pos(2):pos(2)+pos(4); 10 | 11 | dim = [info.Shape, info.max_idx]; 12 | 13 | disp('Memory mapping file.....') 14 | if isempty(Sbx) || ~strcmp(filenm, info.strfp) 15 | Sbx = memmapfile([info.strfp '.sbx'], 'Format',{'uint16', dim, 'Y'}, 'Writable', true); 16 | filenm = info.strfp; 17 | end 18 | 19 | disp('Retrieving data....') 20 | if dim(1) < 3 21 | Sig = squeeze(mean(mean(Sbx.Data.Y(:,x,y,:),3),2)); 22 | else 23 | Sig = squeeze(mean(mean(Sbx.Data.Y(x,y,:,:),2))); 24 | end 25 | 26 | if ~isfield(info, 'simon') 27 | Sig = double(intmax('uint16'))- Sig; 28 | end 29 | if size(Sig,1) < size(Sig,2) 30 | Sig = Sig'; %put signal on first dim 31 | end 32 | 33 | if info.bsplit 34 | disp('Splitting signals....') 35 | S = cell(info.Slices,1); 36 | for i = 1:info.Slices 37 | S{i} = Sig(i:info.Slices:end,:); 38 | end 39 | Sig = S; 40 | end 41 | disp('Done') 42 | 43 | % tic 44 | % Sig1 = zeros(info.max_idx,1); 45 | % for i = 0:info.max_idx-1 46 | % Img = sbxread(fn, i,1); 47 | % if dim(1) < 3 48 | % Sig1(i+1) = mean(mean(Img(:,y,x),3),2); 49 | % else 50 | % Sig1(i+1) = mean(mean(Img(y,x,:),2)); 51 | % end 52 | % end 53 | % toc 54 | 55 | assignin('base', 'Sig', Sig) 56 | 57 | delete(h) 58 | 59 | -------------------------------------------------------------------------------- /util/dep/sbxsplit.m: -------------------------------------------------------------------------------- 1 | function sbxsplit(~,~,info, fn) 2 | % Split an sbx file into multiple sbx files, for different depths 3 | 4 | %[fn, pn] = uigetfile('*.mat'); 5 | % sbxread(fn, 0, 1); %gets info and intializes other parameters 6 | 7 | def = {'2', num2str(info.max_idx)}; 8 | if isfield(info, 'otparam') 9 | try 10 | def{1} = num2str(info.otparam(3)); 11 | disp(['This stack contains ' num2str(info.otparam(3)) ' depth slices']) 12 | catch 13 | def{1} = '1'; 14 | end 15 | end 16 | prompt = {'Slices', 'Stacklength'}; 17 | dlg_title = 'Split Sbx file in slices:'; 18 | num_lines = [1 50]; 19 | 20 | answer = inputdlg(prompt,dlg_title,num_lines,def); 21 | if isempty(answer) 22 | return; %cancel button was pressed 23 | end 24 | 25 | nmslices = str2double(answer{1}); 26 | mxidx = str2double(answer{2}); 27 | 28 | 29 | stackln = floor(mxidx / nmslices); 30 | N = info.nchan; 31 | info.Slices = nmslices; 32 | 33 | savefl = zeros(nmslices,1); 34 | for i = 1:nmslices 35 | savefl(i) = fopen([fn '_split' num2str(i) '.sbx'], 'a'); 36 | end 37 | 38 | 39 | if(isfield(info,'fid') && info.fid ~= -1) 40 | strfn = strrep(fn, '\', '\\'); 41 | hl = waitbar(1/stackln, ['Slicing ' strfn]); 42 | for i = 1:stackln %the first image of the stack is always bad 43 | for j = 1:nmslices 44 | try %nsamples = number of bytes 45 | fseek(info.fid,(i*nmslices+j-1)*info.nsamples,'bof'); 46 | x = fread(info.fid,info.nsamples/2,'uint16=>uint16'); 47 | 48 | catch 49 | error('Cannot read frame. Index range likely outside of bounds.'); 50 | end 51 | 52 | fwrite(savefl(j), x, 'uint16'); 53 | end 54 | waitbar(i/stackln, hl); 55 | end 56 | end 57 | close(hl) 58 | 59 | info.max_idx = stackln-1; 60 | for i = 1:nmslices 61 | fclose(savefl(i)); 62 | info.Section = i; %which section was this 63 | save([fn '_split' num2str(i) ], 'info' ) 64 | end 65 | 66 | end 67 | 68 | -------------------------------------------------------------------------------- /util/dep/subtightplot.m: -------------------------------------------------------------------------------- 1 | function h=subtightplot(m,n,p,gap,marg_h,marg_w,varargin) 2 | %function h=subtightplot(m,n,p,gap,marg_h,marg_w,varargin) 3 | % 4 | % Functional purpose: A wrapper function for Matlab function subplot. Adds the ability to define the gap between 5 | % neighbouring subplots. Unfotrtunately Matlab subplot function lacks this functionality, and the gap between 6 | % subplots can reach 40% of figure area, which is pretty lavish. 7 | % 8 | % Input arguments (defaults exist): 9 | % gap- two elements vector [vertical,horizontal] defining the gap between neighbouring axes. Default value 10 | % is 0.01. Note this vale will cause titles legends and labels to collide with the subplots, while presenting 11 | % relatively large axis. 12 | % marg_h margins in height in normalized units (0...1) 13 | % or [lower uppper] for different lower and upper margins 14 | % marg_w margins in width in normalized units (0...1) 15 | % or [left right] for different left and right margins 16 | % 17 | % Output arguments: same as subplot- none, or axes handle according to function call. 18 | % 19 | % Issues & Comments: Note that if additional elements are used in order to be passed to subplot, gap parameter must 20 | % be defined. For default gap value use empty element- []. 21 | % 22 | % Usage example: h=subtightplot((2,3,1:2,[0.5,0.2]) 23 | 24 | if (nargin<4) || isempty(gap), gap=0.01; end 25 | if (nargin<5) || isempty(marg_h), marg_h=0.05; end 26 | if (nargin<5) || isempty(marg_w), marg_w=marg_h; end 27 | if isscalar(gap), gap(2)=gap; end 28 | if isscalar(marg_h), marg_h(2)=marg_h; end 29 | if isscalar(marg_w), marg_w(2)=marg_w; end 30 | gap_vert = gap(1); 31 | gap_horz = gap(2); 32 | marg_lower = marg_h(1); 33 | marg_upper = marg_h(2); 34 | marg_left = marg_w(1); 35 | marg_right = marg_w(2); 36 | 37 | %note n and m are switched as Matlab indexing is column-wise, while subplot indexing is row-wise :( 38 | [subplot_col,subplot_row]=ind2sub([n,m],p); 39 | 40 | % note subplot suppors vector p inputs- so a merged subplot of higher dimentions will be created 41 | subplot_cols=1+max(subplot_col)-min(subplot_col); % number of column elements in merged subplot 42 | subplot_rows=1+max(subplot_row)-min(subplot_row); % number of row elements in merged subplot 43 | 44 | % single subplot dimensions: 45 | %height=(1-(m+1)*gap_vert)/m; 46 | %axh = (1-sum(marg_h)-(Nh-1)*gap(1))/Nh; 47 | height=(1-(marg_lower+marg_upper)-(m-1)*gap_vert)/m; 48 | %width =(1-(n+1)*gap_horz)/n; 49 | %axw = (1-sum(marg_w)-(Nw-1)*gap(2))/Nw; 50 | width =(1-(marg_left+marg_right)-(n-1)*gap_horz)/n; 51 | 52 | % merged subplot dimensions: 53 | merged_height=subplot_rows*( height+gap_vert )- gap_vert; 54 | merged_width= subplot_cols*( width +gap_horz )- gap_horz; 55 | 56 | % merged subplot position: 57 | merged_bottom=(m-max(subplot_row))*(height+gap_vert) +marg_lower; 58 | merged_left=(min(subplot_col)-1)*(width+gap_horz) +marg_left; 59 | pos_vec=[merged_left merged_bottom merged_width merged_height]; 60 | 61 | % h_subplot=subplot(m,n,p,varargin{:},'Position',pos_vec); 62 | % Above line doesn't work as subplot tends to ignore 'position' when same mnp is utilized 63 | h=subplot('Position',pos_vec,varargin{:}); 64 | 65 | if (nargout < 1), clear h; end 66 | 67 | end 68 | -------------------------------------------------------------------------------- /util/dep/sum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leveltlab/SpectralSegmentation/145eac1dc90475f0d0b06456a9fe386d8ef9e227/util/dep/sum.png -------------------------------------------------------------------------------- /util/dep/toolbar.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leveltlab/SpectralSegmentation/145eac1dc90475f0d0b06456a9fe386d8ef9e227/util/dep/toolbar.PNG -------------------------------------------------------------------------------- /util/dep/xcorr2_fft.m: -------------------------------------------------------------------------------- 1 | function c = xcorr2_fft(a,b) 2 | %XCORR2_FFT Two-dimensional cross-correlation evaluated with FFT algorithm. 3 | % XCORR2_FFT(A,B) computes the cross-correlation of matrices A and B. 4 | % XCORR2(A) is the autocorrelation function. 5 | % 6 | % When matrices A and B are real, XCORR2_FFT is numerically equivalent to 7 | % XCORR2 but much faster. 8 | % 9 | % % Example: 10 | % a = rand(122); b=rand(332); 11 | % a = a-mean(a(:)); 12 | % b = b-mean(b(:)); 13 | % 14 | % tic,cl = xcorr2(a,b);toc 15 | % Elapsed time is 0.223502 seconds. 16 | % tic,cf = xcorr2_fft(a,b);toc 17 | % Elapsed time is 0.030935 seconds. 18 | % 19 | % max(abs(cf(:)-cl(:))) 20 | % ans = 4.1922e-13 21 | % 22 | % Author: Alessandro Masullo, 2015 23 | % Version 1.2 24 | % 25 | % See also CONV2, XCORR, XCORR2 and FILTER2. 26 | 27 | if nargin == 1 28 | b = a; 29 | end 30 | 31 | % Matrix dimensions 32 | adim = size(a); 33 | bdim = size(b); 34 | % Cross-correlation dimension 35 | cdim = adim+bdim-1; 36 | 37 | bpad = zeros(cdim); 38 | apad = zeros(cdim); 39 | 40 | apad(1:adim(1),1:adim(2)) = a; 41 | bpad(1:bdim(1),1:bdim(2)) = b(end:-1:1,end:-1:1); 42 | ffta = fft2(apad); 43 | fftb = fft2(bpad); 44 | c = real(ifft2(ffta.*fftb)); -------------------------------------------------------------------------------- /util/sbx2ij.m: -------------------------------------------------------------------------------- 1 | % Chris van der Togt, 2017, 2 | % Netherlands Institute for Neuroscience 3 | 4 | %Miji 5 | %IJ = ij.IJ; 6 | 7 | [fn , pn] = uigetfile('*.sbx'); 8 | filename = strsplit(fn, '.'); 9 | strfp = [pn filename{1}]; 10 | sbxread(strfp, 0,1); 11 | global info 12 | 13 | d = dir([strfp '.sbx']); 14 | lngth = d.bytes/info.sz(2)/info.sz(1)/info.nchan/2; 15 | if isfield(info, 'Shape') && info.scanbox_version == 2 && info.nchan == 1 && ~isfield(info, 'simon') 16 | dim = info.Shape([3 2]); 17 | elseif isfield(info, 'Shape') 18 | dim = info.Shape([1 2]); 19 | else 20 | dim = info.sz; 21 | end 22 | 23 | if isfield(info, 'simon') %values have been subracted from maxint6 24 | IJ.run('Raw...', ['open=' strfp '.sbx image=[16-bit Unsigned] width=' num2str(dim(1)) ' height=' num2str(dim(2)) ' number=' num2str(lngth*info.nchan) ' little-endian use']); 25 | elseif info.scanbox_version== 2.5 26 | IJ.run('Raw...', ['open=' strfp '.sbx image=[16-bit Unsigned] width=' num2str(dim(1)) ' height=' num2str(dim(2)) ' number=' num2str(lngth*info.nchan) ' white little-endian use']); 27 | else 28 | IJ.run('Raw...', ['open=' strfp '.sbx image=[16-bit Unsigned] width=' num2str(dim(2)) ' height=' num2str(dim(1)) ' number=' num2str(lngth*info.nchan) ' white little-endian use']); 29 | end 30 | 31 | 32 | %has to be transposed for ImageJ 33 | % IStack = ij.ImageStack(info.sz(2), info.sz(1)); 34 | % 35 | % for i = 0:lngth 36 | % pixels = sbxread(strfp,i,1); 37 | % if info.nchan == 2 38 | % pixels = pixels(:,:,1); 39 | % end 40 | % pixels = pixels'; %transpose 41 | % ImageProc = ij.process.ShortProcessor( info.sz(2), info.sz(1)); 42 | % ImageProc.setPixels(pixels(:)); 43 | % 44 | % IStack.addSlice(num2str(i),ImageProc); 45 | % end 46 | % 47 | % IP = ij.ImagePlus('new', IStack); 48 | % IP.show() 49 | --------------------------------------------------------------------------------Showsbx 11 |
12 |Showsbx is used to display image sequences recorded with a neurolabware 2 photon microscoop. Sbx files contain image data in a continuous binary format and to open and display the images, the program needs to import parameters form an accompanying mat file with the same file name.
13 |Showsbx can display individual images at any position or as a movie if you press the run button. It also can display different channels if you press the chan button in the lower right corner. However only one channel can be displayed at the same time.
14 |If the mmage data contains several depth sections, it will try to import the the neccessary parameters to slice the data appropriately, and you are given the choice to select one depth.
15 |Pressing the right mouse button on the image area opens a context menu giving you two menu choices.
16 |The first gives you the possibility to delete the frame presently diplayed (Deleting a frame involves rewriting the whole file exluding the selected frame which can take a lot of time!!).
17 |With the second item you can change the data value range that is diplayed (effectively changing brightness and contrast of the images).
18 |Below the menu bar is a series of tools for cropping, averging, splitting, aligning, exporting the signal from a selected region and to export an mp4 movie.
19 |20 |
The cropping tool allows you to select a square region within the images. This has no immediate effect, but the values saved will be used to crop each image when aligning the images.
21 |22 |
The averging tool allows you to average a selected number of images beginning at the image displayed.
The splitting tool is used to split the image sequences in separate files for each imaging depth (this has become obsolete because a selected depth can be directly exported to Normcorre).
23 |24 |
The align tool calls Normcorre, developed by the Simons foundation, to align the images after selecting a depth and defining the optimal crop.
The export ROI signal tool is used to export the signal of a selected region to the matlab work space. After pressing this button an area selector is shown that can be used to select a desired region. After clicking in this region the signal is exported.
25 |26 |
The movie button simply converts the image sequence at the selected depth, cropped and with the contrast and brightness presently selected to an mp4 movie file.
27 |