├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ChangeLog.m ├── DiameterCalculator.mlapp ├── ExampleData ├── CtBP2_smallstack.tif └── readme.txt ├── ImarisXTensions ├── ConvertSpots2ObjectFinder.asv ├── ConvertSpots2ObjectFinder.m ├── ObjectFinderFilamentExport2matlab.m ├── ObjectFinderFilamentExport2matlabV10.m ├── ObjectFinderMaskChannelWithFilament.m ├── ObjectFinderPassingSpotsToMATLAB.m ├── ObjectFinderSaveFilamentAsMask.m ├── ObjectFinderSaveFilamentAsMaskNoSoma.m └── saveastiff.m ├── License.txt ├── NewExperiment.mlapp ├── Object Finder.mlappinstall ├── Object Finder.prj ├── Object Finder_resources ├── 48px-Add-Folder.png ├── 48px-Angler-Fish.png ├── 48px-Bananas.png ├── 48px-BarPlot.png ├── 48px-Blow-Fish.png ├── 48px-Bones.png ├── 48px-CalcDensity.png ├── 48px-Cancel.png ├── 48px-Crab.png ├── 48px-Delete.png ├── 48px-Edit-clear.png ├── 48px-Edit-copy.png ├── 48px-Edit-delete-2.png ├── 48px-Edit.png ├── 48px-Filter.png ├── 48px-FindObjects.png ├── 48px-Fish-Bone.png ├── 48px-Fruit-2cherries-cross.png ├── 48px-Fruit-3cherries.png ├── 48px-Fruit-3cherriesCheck.png ├── 48px-Fruit-cherries.png ├── 48px-Fruit-recherries.png ├── 48px-Go-bottom.png ├── 48px-Go-down.png ├── 48px-Go-top.png ├── 48px-Go-up.png ├── 48px-Heatmap.png ├── 48px-Histogram.png ├── 48px-HomeFolder.png ├── 48px-Image_upload.png ├── 48px-Inspect.png ├── 48px-LinePlot.png ├── 48px-Link_Image.png ├── 48px-List-add.png ├── 48px-List-remove.png ├── 48px-Location.png ├── 48px-MIP.png ├── 48px-Manual.png ├── 48px-Map-Treaure.png ├── 48px-Masks.png ├── 48px-MasksColored.png ├── 48px-Measure.png ├── 48px-OpenImages.png ├── 48px-PacMan.png ├── 48px-Paint-Mask.png ├── 48px-Sholl.png ├── 48px-Tentacle.png ├── 48px-Text-x-generic_with_pencil.png ├── 48px-Training-set.png ├── 48px-View-refresh.png ├── 48px-Whale-Small-Fish.png ├── 48px-Whale-Tail.png ├── 48px-Whale.png ├── 48px-Zoom-fit.png ├── 48px-Zoom-in.png ├── 48px-Zoom-out.png ├── 48px-calculator.png ├── 48px-center.png ├── 48px-copy.png ├── 48px-database.png ├── 48px-dice-add.png ├── 48px-dice-remove.png ├── 48px-dice.png ├── 48px-down.png ├── 48px-export.png ├── 48px-floppy.png ├── 48px-folder-save.png ├── 48px-image.png ├── 48px-import.png ├── 48px-info.png ├── 48px-left.png ├── 48px-monkey.png ├── 48px-new.png ├── 48px-objects.png ├── 48px-reject.png ├── 48px-render.png ├── 48px-right.png ├── 48px-save.png ├── 48px-scales.png ├── 48px-screenshot.png ├── 48px-settings.png ├── 48px-stop-hand.png ├── 48px-switch.png ├── 48px-trash.png ├── 48px-unblock-granted.png ├── 48px-up.png ├── 48px-validate.png ├── 48px-web-browser.png ├── 72px-Batch-process.png ├── Add-Folder.svg ├── Angler-Fish.svg ├── Bananas.svg ├── BarPlot.svg ├── Bones.svg ├── Center2.svg ├── Coloc-enclose.svg ├── Crab.svg ├── Database.svg ├── Edit-redo.svg ├── Fish-Bone.svg ├── Folder-save.svg ├── Fruit-2cherries-check.png ├── Fruit-2cherries-check.svg ├── Fruit-2cherries-cross.svg ├── Fruit-3cherries.svg ├── Fruit-3cherriesChecked.svg ├── Fruit-cherries.svg ├── Fruit-recherries.svg ├── Go-jump.svg ├── Heatmap.svg ├── Histogram.svg ├── Image_upload-tango.svg ├── LinePlot.svg ├── List-add.svg ├── Location.svg ├── Manual.svg ├── Map-Treasure.svg ├── Masks.svg ├── MasksColored.svg ├── Measure.svg ├── ObjectFinder.png ├── ObjectFinder.svg ├── PacMan.svg ├── Paint Mask.svg ├── Paint.svg ├── Sholl.svg ├── Tentacle.svg ├── TrainingSet.svg ├── Whale-Small-Fish.svg ├── Whale-Tail.svg ├── Whale.svg ├── Zoom-in.svg ├── Zoom-out.svg ├── app_icon_big.png ├── app_icon_small.png ├── blowfish.svg ├── bug.png ├── center.svg ├── dice-add.svg ├── dice-remove.svg ├── dice.svg ├── icon_16.png ├── icon_24.png ├── icon_48.png ├── monkey.svg ├── save.svg └── web-browser.svg ├── ObjectFinder.mlapp ├── ObjectFinder.prj ├── ObjectFinder_1.prj ├── SimpleSettings.mlapp ├── SlicedVolumeInspector.mlapp ├── SlicedVolumeInspector.prj ├── calcDensity.m ├── calcDensityFiner.m ├── calcDotDensityAlongY.m ├── calcDotDensityAlongZ.m ├── calcPathLengthStats.m ├── calcSkelDistToSoma.m ├── calcSkelPathLength.m ├── colocAutoEngulf.m ├── colocAutoMask.m ├── colocAutoNN.m ├── colocDotStackCutter.m ├── colocManual.m ├── colocManualCheckDouble.m ├── colocManualCheckNotColoc.m ├── colocVideoFig.m ├── convertObjectFinderDataV3toV4.m ├── convertObjectFinderDataV4toV5.m ├── convertObjectFinderDataV5toV7.m ├── convertObjectFinderDataV7toV8.m ├── convertObjectFinderDataV8toV10.m ├── convertSkelSNT2ml.m ├── deleteNetwork.m ├── distDotsToCellBody.m ├── distDotsToSkel.m ├── docs ├── images │ ├── MATLAB.png │ ├── MATLAB.svg │ ├── Screenshot_GUI.png │ ├── Screenshot_ImageSelection.png │ ├── Screenshot_MatlabApps.png │ ├── Screenshot_NeuralNet.png │ ├── Screenshot_colocalization.png │ ├── Screenshot_excel.png │ ├── Screenshot_folder.png │ ├── Screenshot_heatmap.png │ ├── Screenshot_imaris.png │ ├── Screenshot_inspector.png │ ├── Screenshot_timer.png │ ├── Screenshot_toolbar.png │ ├── app_icon_big.png │ ├── blacktocat.svg │ ├── bug.png │ ├── download.svg │ ├── linux.png │ ├── linux.svg │ ├── mac.png │ ├── mac.svg │ ├── question.png │ ├── sourcecode.png │ ├── sourcecode.svg │ ├── speed.png │ ├── windows.png │ └── windows.svg ├── index.html ├── stylesheets │ ├── normalize.css │ ├── pygment_trac.css │ └── stylesheet.css └── wiki_images │ ├── GUI_about.png │ ├── GUI_automate.png │ ├── GUI_colocalize_mask.png │ ├── GUI_colocalize_objects.png │ ├── GUI_detect _tools.png │ ├── GUI_detect.png │ ├── GUI_detect_settings.png │ ├── GUI_detect_validation.png │ ├── GUI_neuralnet.png │ ├── GUI_new_project.png │ ├── GUI_report.png │ ├── GUI_simulate.png │ ├── Installation_install.png │ ├── Installation_update.png │ └── Installation_version.png ├── editStruct.m ├── exportObjectsToImaris7.m ├── exportObjectsToImaris8.m ├── filterObjects.m ├── findObjects.m ├── findObjectsSimple.m ├── findObjectsUIDfromName.m ├── fitSphere.m ├── generateFinerSkel.m ├── generateUID.m ├── getFilteredObjects.m ├── inpoly2.m ├── inpolygon_fast.m ├── inspectVolume2D.asv ├── inspectVolume2D.m ├── inspectVolume3D.m ├── listImages.m ├── listNetwork.m ├── listObjects.m ├── listPresets.m ├── listSimulations.m ├── listSkels.m ├── loadImage.m ├── loadNetwork.m ├── loadObjects.m ├── loadPreset.m ├── loadSettings.m ├── loadSimulation.m ├── loadSkel.m ├── saveNetwork.m ├── saveObjects.m ├── savePreset.m ├── saveSettings.m ├── saveSimulation.m ├── saveSkel.m ├── saveastiff.m ├── shollAnalysis.m ├── shollAnalysisSegments.m ├── skeletonizeMask.m └── validateObjectWithNeuralNet.m /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at luca.dellasantina@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to ObjectFinder 2 | 3 | Thanks for your interest in ObjectFinder. Our goal is to bring fast, open-source large-scale synapse quantification using deep learning to all MATLAB-based computer vision communities. 4 | 5 | ## Getting Started 6 | 7 | ObjectFinder's [open issues are here](https://github.com/lucadellasantina/ObjectFinder/issues). In time, we'll tag issues that would make a good first pull request for new contributors. An easy way to get started helping the project is to *file an issue*. You can do that on the Deeplearning4j issues page by clicking on the green button at the right. Issues can include bugs to fix, features to add, or documentation that looks outdated. 8 | 9 | For some tips on contributing to open source, this [post is helpful](http://blog.smartbear.com/programming/14-ways-to-contribute-to-open-source-without-being-a-programming-genius-or-a-rock-star/). 10 | 11 | ## Contributions 12 | 13 | ObjectFinder welcomes contributions from everyone. 14 | 15 | Contributions to ObjectFinder should be made in the form of GitHub pull requests. Each pull request will 16 | be reviewed by a core contributor (someone with permission to land patches) and either landed in the 17 | main tree or given feedback for changes that would be required. 18 | 19 | ## Pull Request Checklist 20 | 21 | - Branch from the master branch and, if needed, rebase to the current master 22 | branch before submitting your pull request. If it doesn't merge cleanly with 23 | master you may be asked to rebase your changes. 24 | 25 | - Commits should be as small as possible, while ensuring that each commit is 26 | correct independently (i.e., each commit should compile and pass tests). 27 | 28 | - Don't put submodule updates in your pull request unless they are to landed 29 | commits. 30 | 31 | - If your patch is not getting reviewed or you need a specific person to review 32 | it, you can @-reply a reviewer asking for a review in the pull request or a 33 | comment. 34 | 35 | - Add tests relevant to the fixed bug or new feature. 36 | 37 | ## Conduct 38 | 39 | We follow the [Code of Conduct](https://github.com/lucadellasantina/ObjectFinder/blob/master/CODE_OF_CONDUCT.md). 40 | 41 | All code in this repository is under the Gnu Pulic License version 3.0. 42 | -------------------------------------------------------------------------------- /DiameterCalculator.mlapp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/DiameterCalculator.mlapp -------------------------------------------------------------------------------- /ExampleData/CtBP2_smallstack.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/ExampleData/CtBP2_smallstack.tif -------------------------------------------------------------------------------- /ExampleData/readme.txt: -------------------------------------------------------------------------------- 1 | This folder contains example data to use with ObjectFinder 2 | -------------------------------------------------------------------------------- /ImarisXTensions/ConvertSpots2ObjectFinder.asv: -------------------------------------------------------------------------------- 1 | %% Instructions 2 | % 3 | % Save Spots as ObjectFinder's set of objects 4 | % 5 | % Installation: 6 | % 7 | % - Copy this file into the XTensions folder in the Imaris installation directory 8 | % - You will find this function in the Image Processing menu 9 | % 10 | % 11 | % 12 | % 13 | % 14 | % Matlab::ConvertSpots2ObjectFinder(%i) 15 | % 16 | % 17 | % 18 | % 19 | % 20 | % 21 | % Matlab::ConvertSpots2ObjectFinder(%i) 22 | % 23 | % 24 | % 25 | % 26 | % Matlab::ConvertSpots2ObjectFinder(%i) 27 | % 28 | % 29 | % 30 | % 31 | % 32 | % 33 | % Description: 34 | % 35 | % The User chooses which spots to export, coordinates of spots are 36 | % represented as rows of the SpotXYZ matrix, [X,Y,Z] 37 | % Coordinates are expressed in pixel 38 | % 39 | %% Connect to Imaris Com interface 40 | function ConvertSpots2ObjectFinder(aImarisApplicationID) 41 | 42 | if ~isa(aImarisApplicationID, 'COM.Imaris_Application') 43 | vImarisServer = actxserver('ImarisServer.Server'); 44 | vImarisApplication = vImarisServer.GetObject(aImarisApplicationID); 45 | else 46 | vImarisApplication = aImarisApplicationID; 47 | end 48 | %% Start Imaris from matlab and make it visible (comment before saving) 49 | % vImarisApplication=actxserver('Imaris.Application'); 50 | % vImarisApplication.mVisible=true; 51 | 52 | 53 | %% the user has to create a scene 54 | vSurpassScene = vImarisApplication.mSurpassScene; 55 | if isequal(vSurpassScene, []) 56 | msgbox('Please create a Surpass scene!'); 57 | return; 58 | end 59 | 60 | %% get image size and pixel resolution 61 | tmpDataset = vImarisApplication.mDataset; %get the dataset to retrieve size/resolution 62 | xs = tmpDataset.mSizeX; %X size in pixel 63 | ys = tmpDataset.mSizeY; %Y size in pixel 64 | zs = tmpDataset.mSizeZ; %Z size in pixel 65 | xsReal = tmpDataset.mExtendMaxX - tmpDataset.mExtendMinX; %X size in micron 66 | ysReal = tmpDataset.mExtendMaxY - tmpDataset.mExtendMinY; %Y size in micron 67 | zsReal = tmpDataset.mExtendMaxZ - tmpDataset.mExtendMinZ; %Z size in micron 68 | xr = xsReal/xs; %X pixel resolution (usually micron per pixel) 69 | yr = ysReal/ys; %Y pixel resolution (usually micron per pixel) 70 | zr = zsReal/zs; %Z pixel resolution (usually micron per pixel) 71 | 72 | %% make directory of Spots in surpass scene 73 | cnt = 0; 74 | for vChildIndex = 1:vSurpassScene.GetNumberOfChildren 75 | if vImarisApplication.mFactory.IsSpots(vSurpassScene.GetChild(vChildIndex - 1)) 76 | cnt = cnt+1; 77 | vSpots{cnt} = vSurpassScene.GetChild(vChildIndex - 1); 78 | end 79 | end 80 | 81 | %% choose passing spots 82 | vSpotsCnt = length(vSpots); 83 | for n= 1:vSpotsCnt 84 | vSpotsName{n} = vSpots{n}.mName; 85 | end 86 | cellstr = cell2struct(vSpotsName,{'names'},vSpotsCnt+2); 87 | str = {cellstr.names}; 88 | [vAnswer_iPass,~] = listdlg('ListSize',[200 160], ... 89 | 'PromptString','Chose spots to export',... 90 | 'SelectionMode','multiple',... 91 | 'ListString',str); 92 | 93 | %% Create an ObjectFinder set if ibjects 94 | 95 | Objs = struct; 96 | Objs.Name = vAnswer_iPass; 97 | 98 | tmp = java.util.UUID.randomUUID; 99 | tmpStr = tmp.toString; 100 | Objs.UID = tmpStr.toCharArray'; 101 | Objs.Shape = struct; 102 | Objs.Density = struct; % Density measurements 103 | Objs.NN = struct; % Nearest neighbor measurements 104 | Objs.Coloc = struct; % Colocalization measurements 105 | Objs.Skel = struct; % Skeleton measurements (e.g distance to cell body) 106 | 107 | Objs.Settings.Version = 10.0; 108 | Objs.Settings.debug = 0; 109 | Objs.ImInfo.DenCh = 0; 110 | Objs.ImInfo.PostCh = 0; 111 | Objs.ImInfo.ColoCh = 0; 112 | Objs.ImInfo.xyum = xr; 113 | Objs.ImInfo.zum = zr; 114 | Objs.ImInfo.xNumVox = xs; 115 | Objs.ImInfo.yNumVox = ys; 116 | Objs.ImInfo.zNumVox = zs; 117 | Objs.ImInfo.PostNameCh = ''; 118 | Objs.ImInfo.CBpos = [1 1 1]; 119 | Objs.ImInfo.MedFilt = 0; 120 | Objs.ImInfo.MedFiltKern = 0; 121 | 122 | Objs.Settings.objfinder.blockSize = 90; 123 | Objs.Settings.objfinder.blockBuffer = 15; 124 | Objs.Settings.objfinder.thresholdStep = 2; 125 | Objs.Settings.objfinder.maxDotSize = 2; 126 | Objs.Settings.objfinder.minDotSize = 1; 127 | Objs.Settings.objfinder.itMin = 1; 128 | Objs.Settings.objfinder.minFinalDotSize = 1; 129 | Objs.Settings.objfinder.watershed = 0; 130 | Objs.Settings.objfinder.blockSearch = 0; 131 | Objs.Settings.objfinder.sphericity = 0; 132 | Objs.Settings.objfinder.minIntensity = 1; 133 | 134 | % Add coordinates of each spot, size will be one voxel 135 | for i = 1:numel(vAnswer_iPass) 136 | iPassSpots = vSpots{vAnswer_iPass(i)}; 137 | [SpotsXYZ,~,~] = iPassSpots.Get; 138 | SpotsXYZ(:,1) = ceil(SpotsXYZ(:,1)./xr); %convert coordinates to pixel 139 | SpotsXYZ(:,2) = ceil(SpotsXYZ(:,2)./yr); %convert coordinates to pixel 140 | SpotsXYZ(:,3) = ceil(SpotsXYZ(:,3)./zr); %convert coordinates to pixel 141 | end 142 | Objs.Pos = SpotsXYZ; 143 | Objs.Vol = ones(1,size(Objs.Pos, 1), 'double'); 144 | Objs.ITMax = ones(1,size(Objs.Pos, 1), 'uint8'); 145 | Objs.ITSum = ones(1,size(Objs.Pos, 1), 'double'); 146 | Objs.MeanBright = ones(1,size(Objs.Pos, 1), 'single'); 147 | 148 | % populate the Vox field 149 | for i = 1:size(Objs.Pos, 1) 150 | Objs.Vox(i).Pos = Objs.Pos(1,:); 151 | 152 | end 153 | 154 | %% Save objects set to disk 155 | 156 | TPN = uigetdir; 157 | folder = [TPN filesep 'objects']; 158 | FileName = [folder filesep Dots.UID '.mat']; 159 | if ~isfolder(folder), mkdir(folder); end 160 | save(FileName, '-struct', 'Dots', '-v7'); 161 | 162 | fprintf('Spots converted!') 163 | 164 | -------------------------------------------------------------------------------- /ImarisXTensions/ObjectFinderFilamentExport2matlab.m: -------------------------------------------------------------------------------- 1 | %% Instructions 2 | % Select Filament and send to Matlab as Skel.mat files 3 | % 4 | % Installation: 5 | % 6 | % - Copy this file into the XTensions folder in the Imaris installation directory 7 | % - You will find this function in the Image Processing menu 8 | % 9 | % 10 | % 11 | % 12 | % 13 | % Matlab::ObjectFinderFilamentExport2matlab(%i) 14 | % 15 | % 16 | % 17 | % 18 | % 19 | % 20 | % Matlab::ObjectFinderFilamentExport2matlab(%i) 21 | % 22 | % 23 | % 24 | % 25 | % 26 | % Description: User selects a filament that will be exported as .mat 27 | % Matlab file to be processed by ObjectFinder. 28 | 29 | 30 | %% connect to Imaris Com interface 31 | function ObjectFinderFilamentExport2matlab(aImarisApplicationID) 32 | 33 | if ~isa(aImarisApplicationID, 'COM.Imaris_Application') 34 | vImarisServer = actxserver('ImarisServer.Server'); 35 | vImarisApplication = vImarisServer.GetObject(aImarisApplicationID); 36 | else 37 | vImarisApplication = aImarisApplicationID; 38 | end 39 | 40 | %% if testing from matlab (comment when running from Imaris) 41 | %vImarisApplication = actxserver('Imaris.Application'); 42 | %vImarisApplication.mVisible = true; 43 | 44 | %% the user has to create a scene with some spots and surface 45 | 46 | vSurpassScene = vImarisApplication.mSurpassScene; 47 | if isequal(vSurpassScene, []) 48 | msgbox('Please create Surpass scene!'); 49 | return 50 | end 51 | 52 | %% make directory of Filaments in surpass scene 53 | cnt = 0; 54 | for vChildIndex = 1:vSurpassScene.GetNumberOfChildren 55 | if vImarisApplication.mFactory.IsFilament(vSurpassScene.GetChild(vChildIndex - 1)) 56 | cnt = cnt + 1; 57 | vFilaments{cnt} = vSurpassScene.GetChild(vChildIndex - 1); %#ok 58 | end 59 | end 60 | 61 | %% Choose which Filaments object to export 62 | vFilamentsCnt = length(vFilaments); 63 | for n = vFilamentsCnt:-1:1 64 | vFilamentsName{n} = vFilaments{n}.mName; 65 | end 66 | cellstr = cell2struct(vFilamentsName,{'names'},vFilamentsCnt+2); 67 | str = {cellstr.names}; 68 | 69 | [vAnswer_yes,~] = listdlg('ListSize',[200 160], 'PromptString','Choose Filament:', 'SelectionMode','single','ListString',str); 70 | aFilament = vFilaments{vAnswer_yes}; 71 | 72 | aXYZ = aFilament.GetPositionsXYZ; 73 | aRad = aFilament.GetRadii; 74 | aEdges = aFilament.GetEdges; 75 | 76 | %% Export the position of soma 1/5/2010 HO 77 | SomaPtID = aFilament.GetRootVertexIndex; %this tells the index of dendrite beginning point, which is typically set to soma, and tyically zero if you didn't change it after Autopath 78 | if SomaPtID ~= -1 %if dendrite beginning point is not set, Imaris spits out -1. 79 | SomaPtXYZ = aXYZ(SomaPtID+1,:); 80 | else 81 | msgbox('Warning: Soma pt (beginning pt) not set. Using posizion with lower Z value') 82 | aFilament.SetRootVertexIndex(find(aXYZ(:,3) == min(aXYZ(:,3)))+1); 83 | SomaPtXYZ = aXYZ(find(aXYZ(:,3) == min(aXYZ(:,3)))+1,:); 84 | end 85 | 86 | %% Convert to jm Skel format (segment mean position and length) 87 | Edges = aEdges+1; 88 | Seg = cat(3,aXYZ(Edges(:,1),:),aXYZ(Edges(:,2),:)); 89 | Lengths = sqrt((Seg(:,1,1)-Seg(:,1,2)).^2 + (Seg(:,2,1)-Seg(:,2,2)).^2 + (Seg(:,3,1)-Seg(:,3,2)).^2); 90 | 91 | Skel.FilStats.aXYZ = aXYZ; 92 | Skel.FilStats.aRad = aRad; 93 | Skel.FilStats.aEdges= aEdges; 94 | 95 | %If dendrite beginning point is not set, Imaris returns -1 96 | if SomaPtID ~= -1 97 | Skel.FilStats.SomaPtID = SomaPtID; 98 | Skel.FilStats.SomaPtXYZ = SomaPtXYZ; 99 | end 100 | Skel.SegStats.Seg=Seg; 101 | Skel.SegStats.Lengths=Lengths; 102 | Skel.Name = aFilament.mName; 103 | 104 | % Generate an unique identifier using Java's UUID generator 105 | tmp = java.util.UUID.randomUUID; 106 | tmpStr = tmp.toString; 107 | Skel.UID = tmpStr.toCharArray'; 108 | 109 | %% Save skeleton into the skeletons folder of the project 110 | TPN = uigetdir; 111 | if ~exist([TPN filesep 'skeletons'], 'dir') 112 | mkdir([TPN filesep 'skeletons']); 113 | end 114 | 115 | FileName = [TPN filesep 'skeletons' filesep Skel.UID '.mat']; 116 | save(FileName, '-struct', 'Skel'); 117 | disp('Skeleton exported successfully!'); 118 | end 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /ImarisXTensions/ObjectFinderFilamentExport2matlabV10.m: -------------------------------------------------------------------------------- 1 | %% Instructions 2 | % Select Filament and send to Matlab as Skel.mat files 3 | % 4 | % Installation: 5 | % 6 | % - Copy this file into the XTensions folder in the Imaris installation directory 7 | % - You will find this function in the Image Processing menu 8 | % 9 | % 10 | % 11 | % 12 | % 13 | % Matlab::ObjectFinderFilamentExport2matlabV10(%i) 14 | % 15 | % 16 | % 17 | % 18 | % 19 | % 20 | % Matlab::ObjectFinderFilamentExport2matlabV10(%i) 21 | % 22 | % 23 | % 24 | % 25 | % 26 | % Description: User selects a filament that will be exported as .mat 27 | % Matlab file to be processed by ObjectFinder. 28 | 29 | 30 | %% connect to Imaris Com interface 31 | function ObjectFinderFilamentExport2matlabV10(aImarisApplicationID) 32 | 33 | % connect to Imaris interface 34 | if ~isa(aImarisApplicationID, 'Imaris.IApplicationPrxHelper') 35 | javaaddpath ImarisLib.jar 36 | vImarisLib = ImarisLib; 37 | if ischar(aImarisApplicationID) 38 | aImarisApplicationID = round(str2double(aImarisApplicationID)); 39 | end 40 | vImarisApplication = vImarisLib.GetApplication(aImarisApplicationID); 41 | else 42 | vImarisApplication = aImarisApplicationID; 43 | end 44 | 45 | % get the filament 46 | vFactory = vImarisApplication.GetFactory; 47 | vFilaments = vFactory.ToFilaments(vImarisApplication.GetSurpassSelection); 48 | 49 | % search the filament if not previously selected 50 | vSurpassScene = vImarisApplication.GetSurpassScene; 51 | if ~vFactory.IsFilaments(vFilaments) 52 | for vChildIndex = 1:vSurpassScene.GetNumberOfChildren 53 | vDataItem = vSurpassScene.GetChild(vChildIndex - 1); 54 | if vFactory.IsFilaments(vDataItem) 55 | vFilaments = vFactory.ToFilaments(vDataItem); 56 | break; 57 | end 58 | end 59 | % did we find the filament? 60 | if isequal(vFilaments, []) 61 | msgbox('Please create some filament!'); 62 | return; 63 | end 64 | end 65 | 66 | aXYZ = vFilaments.GetPositionsXYZ(0); 67 | aRad = vFilaments.GetRadii(0); 68 | aEdges = vFilaments.GetEdges(0); 69 | 70 | %% Export the position of soma 1/5/2010 HO 71 | SomaPtID = vFilament.GetRootVertexIndex(0); %this tells the index of dendrite beginning point, which is typically set to soma, and tyically zero if you didn't change it after Autopath 72 | if SomaPtID ~= -1 %if dendrite beginning point is not set, Imaris spits out -1. 73 | SomaPtXYZ = aXYZ(SomaPtID+1,:); 74 | else 75 | msgbox('Warning: Soma pt (beginning pt) not set. Using posizion with lower Z value') 76 | vFilament(0).SetRootVertexIndex(find(aXYZ(:,3) == min(aXYZ(:,3)))+1); 77 | SomaPtXYZ = aXYZ(find(aXYZ(:,3) == min(aXYZ(:,3)))+1,:); 78 | end 79 | 80 | %% Convert to jm Skel format (segment mean position and length) 81 | Edges = aEdges+1; 82 | Seg = cat(3,aXYZ(Edges(:,1),:),aXYZ(Edges(:,2),:)); 83 | Lengths = sqrt((Seg(:,1,1)-Seg(:,1,2)).^2 + (Seg(:,2,1)-Seg(:,2,2)).^2 + (Seg(:,3,1)-Seg(:,3,2)).^2); 84 | 85 | Skel.FilStats.aXYZ = aXYZ; 86 | Skel.FilStats.aRad = aRad; 87 | Skel.FilStats.aEdges= aEdges; 88 | 89 | %If dendrite beginning point is not set, Imaris returns -1 90 | if SomaPtID ~= -1 91 | Skel.FilStats.SomaPtID = SomaPtID; 92 | Skel.FilStats.SomaPtXYZ = SomaPtXYZ; 93 | end 94 | Skel.SegStats.Seg=Seg; 95 | Skel.SegStats.Lengths=Lengths; 96 | Skel.Name = aFilament.mName; 97 | 98 | % Generate an unique identifier using Java's UUID generator 99 | tmp = java.util.UUID.randomUUID; 100 | tmpStr = tmp.toString; 101 | Skel.UID = tmpStr.toCharArray'; 102 | 103 | %% Save skeleton into the skeletons folder of the project 104 | TPN = uigetdir; 105 | if ~exist([TPN filesep 'skeletons'], 'dir') 106 | mkdir([TPN filesep 'skeletons']); 107 | end 108 | 109 | FileName = [TPN filesep 'skeletons' filesep Skel.UID '.mat']; 110 | save(FileName, '-struct', 'Skel'); 111 | disp('Skeleton exported successfully!'); 112 | end 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /NewExperiment.mlapp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/NewExperiment.mlapp -------------------------------------------------------------------------------- /Object Finder.mlappinstall: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder.mlappinstall -------------------------------------------------------------------------------- /Object Finder_resources/48px-Add-Folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Add-Folder.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Angler-Fish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Angler-Fish.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Bananas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Bananas.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-BarPlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-BarPlot.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Blow-Fish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Blow-Fish.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Bones.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Bones.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-CalcDensity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-CalcDensity.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Cancel.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Crab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Crab.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Delete.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Edit-clear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Edit-clear.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Edit-copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Edit-copy.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Edit-delete-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Edit-delete-2.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Edit.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Filter.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-FindObjects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-FindObjects.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Fish-Bone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Fish-Bone.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Fruit-2cherries-cross.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Fruit-2cherries-cross.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Fruit-3cherries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Fruit-3cherries.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Fruit-3cherriesCheck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Fruit-3cherriesCheck.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Fruit-cherries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Fruit-cherries.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Fruit-recherries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Fruit-recherries.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Go-bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Go-bottom.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Go-down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Go-down.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Go-top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Go-top.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Go-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Go-up.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Heatmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Heatmap.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Histogram.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-HomeFolder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-HomeFolder.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Image_upload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Image_upload.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Inspect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Inspect.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-LinePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-LinePlot.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Link_Image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Link_Image.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-List-add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-List-add.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-List-remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-List-remove.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Location.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-MIP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-MIP.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Manual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Manual.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Map-Treaure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Map-Treaure.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Masks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Masks.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-MasksColored.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-MasksColored.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Measure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Measure.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-OpenImages.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-OpenImages.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-PacMan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-PacMan.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Paint-Mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Paint-Mask.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Sholl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Sholl.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Tentacle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Tentacle.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Text-x-generic_with_pencil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Text-x-generic_with_pencil.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Training-set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Training-set.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-View-refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-View-refresh.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Whale-Small-Fish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Whale-Small-Fish.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Whale-Tail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Whale-Tail.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Whale.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Whale.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Zoom-fit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Zoom-fit.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Zoom-in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Zoom-in.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-Zoom-out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-Zoom-out.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-calculator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-calculator.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-center.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-copy.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-database.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-dice-add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-dice-add.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-dice-remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-dice-remove.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-dice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-dice.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-down.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-export.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-floppy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-floppy.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-folder-save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-folder-save.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-image.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-import.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-import.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-info.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-left.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-monkey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-monkey.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-new.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-objects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-objects.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-reject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-reject.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-render.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-render.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-right.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-save.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-scales.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-scales.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-screenshot.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-settings.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-stop-hand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-stop-hand.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-switch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-switch.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-trash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-trash.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-unblock-granted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-unblock-granted.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-up.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-validate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-validate.png -------------------------------------------------------------------------------- /Object Finder_resources/48px-web-browser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/48px-web-browser.png -------------------------------------------------------------------------------- /Object Finder_resources/72px-Batch-process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/72px-Batch-process.png -------------------------------------------------------------------------------- /Object Finder_resources/Fruit-2cherries-check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/Fruit-2cherries-check.png -------------------------------------------------------------------------------- /Object Finder_resources/Fruit-recherries.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Object Finder_resources/Heatmap.svg: -------------------------------------------------------------------------------- 1 | 2 | 21 | 23 | 24 | 26 | image/svg+xml 27 | 29 | 30 | 31 | 32 | 33 | 35 | 46 | 49 | 53 | 57 | 58 | 59 | 83 | 89 | 94 | 101 | 102 | -------------------------------------------------------------------------------- /Object Finder_resources/ObjectFinder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/ObjectFinder.png -------------------------------------------------------------------------------- /Object Finder_resources/Whale-Tail.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | image/svg+xml 44 | 47 | 52 | 57 | 58 | 62 | 64 | 68 | 69 | -------------------------------------------------------------------------------- /Object Finder_resources/app_icon_big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/app_icon_big.png -------------------------------------------------------------------------------- /Object Finder_resources/app_icon_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/app_icon_small.png -------------------------------------------------------------------------------- /Object Finder_resources/bug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/bug.png -------------------------------------------------------------------------------- /Object Finder_resources/icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/icon_16.png -------------------------------------------------------------------------------- /Object Finder_resources/icon_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/icon_24.png -------------------------------------------------------------------------------- /Object Finder_resources/icon_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/Object Finder_resources/icon_48.png -------------------------------------------------------------------------------- /ObjectFinder.mlapp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/ObjectFinder.mlapp -------------------------------------------------------------------------------- /SimpleSettings.mlapp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/SimpleSettings.mlapp -------------------------------------------------------------------------------- /SlicedVolumeInspector.mlapp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/SlicedVolumeInspector.mlapp -------------------------------------------------------------------------------- /SlicedVolumeInspector.prj: -------------------------------------------------------------------------------- 1 | 2 | 3 | SlicedVolumeInspector 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 1.0 13 | 14 | 15 | 16 | 17 | ${PROJECT_ROOT} 18 | 1660240c-66b5-4fa1-ba15-4c5d85cc4249 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | ${PROJECT_ROOT}/SlicedVolumeInspector.mlapp 37 | 38 | 39 | ${PROJECT_ROOT}/Object Finder_resources/48px-Zoom-fit.png 40 | ${PROJECT_ROOT}/Object Finder_resources/48px-Zoom-in.png 41 | ${PROJECT_ROOT}/Object Finder_resources/48px-Zoom-out.png 42 | ${PROJECT_ROOT}/Object Finder_resources/48px-center.png 43 | ${PROJECT_ROOT}/Object Finder_resources/48px-down.png 44 | ${PROJECT_ROOT}/Object Finder_resources/48px-left.png 45 | ${PROJECT_ROOT}/Object Finder_resources/48px-right.png 46 | ${PROJECT_ROOT}/Object Finder_resources/48px-up.png 47 | ${PROJECT_ROOT}/loadImage.m 48 | ${PROJECT_ROOT}/loadObjects.m 49 | 50 | 51 | 52 | 53 | /home/luca/Dropbox/MATLAB scripts/ObjectFinder 54 | 55 | 56 | 57 | /home/luca/MATLAB/R2023b 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | true 66 | 67 | 68 | 69 | 70 | true 71 | 72 | 73 | 74 | 75 | true 76 | 77 | 78 | 79 | 80 | true 81 | false 82 | false 83 | false 84 | false 85 | false 86 | true 87 | false 88 | 6.6.6-76060606-generic 89 | false 90 | true 91 | glnxa64 92 | true 93 | 94 | 95 | -------------------------------------------------------------------------------- /calcDotDensityAlongY.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function D = calcDotDensityAlongY(Settings, Objs, Mask, BinsNum, showPlot) 20 | %% Accumulate passing dots coordinates (xyz) into dPosPassF 21 | D.yStart = 1; % Analyze the entire volume 22 | D.yEnd = Settings.ImInfo.yNumVox; % Analyze the entire volume 23 | D.binSize = (D.yEnd - D.yStart)/BinsNum; % binning densities every 1 percent of Z-depth 24 | D.binNum = BinsNum; 25 | VoxelVolume = Objs.Settings.ImInfo.xyum * Objs.Settings.ImInfo.xyum * Objs.Settings.ImInfo.zum; 26 | 27 | if D.yEnd == D.yStart 28 | % 2D image (single Z plane) 29 | D.density = size(Objs.Pos, 1); 30 | D.densityPerc = zeros(1, BinsNum); 31 | for i = 1:BinsNum 32 | D.densityPerc(i) = Density; 33 | end 34 | 35 | else 36 | % 3D image (multiple Z planes) 37 | D.density = zeros(1, (D.yEnd - D.yStart +1)); 38 | D.densityPerc = zeros(1, BinsNum); 39 | D.densityPercMask = zeros(1, BinsNum); 40 | D.volume = zeros(1, (D.yEnd - D.yStart +1)); 41 | D.volumePerc = zeros(1, BinsNum); 42 | D.volumePercMask = zeros(1, BinsNum); 43 | 44 | for i = D.yStart: D.yEnd -1 45 | D.density(i) = numel(find(Objs.Pos(:,1) == i)); 46 | D.volume(i) = mean(Objs.Vol(Objs.Pos(:,1) == i))*VoxelVolume; 47 | end 48 | 49 | PosPerc = Objs.Pos; 50 | for i = 1:size(PosPerc,1) 51 | PosPerc(i,1) = (PosPerc(i,1)-D.yStart) / (D.yEnd-D.yStart); 52 | PosPerc(i,1) = ceil(PosPerc(i,1)*BinsNum); 53 | end 54 | 55 | for i = 1:BinsNum 56 | D.densityPerc(i) = numel(find(PosPerc(:,1) == i)); 57 | D.volumePerc(i) = mean(Objs.Vol(PosPerc(:,1) == i))*VoxelVolume; 58 | end 59 | 60 | if isempty(Mask) || isempty(find(Mask.I(:), 1)) 61 | return 62 | end 63 | 64 | PosPerc = Objs.Pos; 65 | for i = 1:size(PosPerc,1) 66 | % Skip if current object is outside of the mask 67 | if Mask.I(sub2ind(size(Mask.I), PosPerc(i,1), PosPerc(i,2), PosPerc(i,3))) == 0 68 | PosPerc(i,1) = -1; 69 | continue 70 | end 71 | 72 | % Calculate Z position of each object as % within the masked volume 73 | yMask = squeeze(Mask.I(:, PosPerc(i,2), PosPerc(i,3))); 74 | yStart = find(yMask, 1); 75 | yEnd = find(yMask, 1, 'last'); 76 | PosPerc(i,1) = (PosPerc(i,1)-yStart) / (yEnd-yStart); 77 | PosPerc(i,1) = ceil(PosPerc(i,1)*BinsNum); 78 | end 79 | 80 | % Cound how many dots in each % bin 81 | for i = 1:BinsNum 82 | D.densityPercMask(i) = numel(find(PosPerc(:,1) == i)); 83 | D.volumePercMask(i) = mean(Objs.Vol(PosPerc(:,1) == i))*VoxelVolume; 84 | end 85 | end 86 | 87 | %% Plot dot density distribution as a function of Volume depth. 88 | if showPlot 89 | tmpH = figure('Name', 'Grouped distribution along Z'); 90 | set(tmpH, 'Position', [100 200 1200 500]); 91 | set(gcf, 'DefaultAxesFontName', 'Arial', 'DefaultAxesFontSize', 12); 92 | set(gcf, 'DefaultTextFontName', 'Arial', 'DefaultTextFontSize', 12); 93 | 94 | tiledlayout(1,2); 95 | nexttile; 96 | hold on; 97 | tmpY = D.densityPerc; 98 | tmpX = (1:BinsNum)*100/BinsNum; 99 | plot(tmpX, tmpY, 'k', 'MarkerSize', 8); 100 | plot(tmpX, D.densityPercMask, 'r', 'MarkerSize', 8); 101 | box off; 102 | set(gca, 'color', 'none', 'TickDir','out'); 103 | ylabel('Number of objects'); 104 | xlabel(['Depth percentage (' num2str(100/BinsNum) '% bin size: ' num2str(Settings.ImInfo.xyum * D.binSize, 2) 'um)']); 105 | 106 | nexttile; 107 | hold on; 108 | sizeBin = Settings.ImInfo.xyum * Settings.ImInfo.xNumVox... 109 | *Settings.ImInfo.xyum * D.binSize... 110 | *Settings.ImInfo.zum * Settings.ImInfo.zNumVox; 111 | tmpY = D.densityPerc / sizeBin; 112 | tmpX = (1:BinsNum)*100/BinsNum; 113 | plot(tmpX, tmpY, 'k', 'MarkerSize', 8); 114 | 115 | if ~isempty(Mask) 116 | MaskedVoxN = numel(find(Mask.I)); 117 | MaskBinVolume = Settings.ImInfo.xyum *Settings.ImInfo.xyum *Settings.ImInfo.zum * MaskedVoxN / BinsNum; 118 | plot(tmpX, D.densityPercMask / MaskBinVolume, 'r', 'MarkerSize', 8); 119 | end 120 | 121 | box off; 122 | set(gca, 'color', 'none', 'TickDir','out'); 123 | ylabel('Density (objects / um^3)'); 124 | legend({'Full volume', 'Masked volume'}); 125 | xlabel(['Depth percentage (' num2str(100/BinsNum) '% bin size: ' num2str(Settings.ImInfo.xyum * D.binSize, 2) 'um)']); 126 | 127 | clear tmp* plot_variance sizeBin; 128 | end 129 | end 130 | -------------------------------------------------------------------------------- /calcDotDensityAlongZ.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function D = calcDotDensityAlongZ(Settings, Objs, Mask, BinsNum, showPlot) 20 | %% Accumulate passing dots coordinates (xyz) into dPosPassF 21 | D.zStart = 1; % Analyze the entire volume 22 | D.zEnd = Settings.ImInfo.zNumVox; % Analyze the entire volume 23 | D.binSize = (D.zEnd - D.zStart)/BinsNum; % binning densities every 1 percent of Z-depth 24 | D.binNum = BinsNum; 25 | VoxelVolume = Objs.Settings.ImInfo.xyum * Objs.Settings.ImInfo.xyum * Objs.Settings.ImInfo.zum; 26 | 27 | if D.zEnd == D.zStart 28 | % 2D image (single Z plane) 29 | D.density = size(Objs.Pos, 1); 30 | D.densityPerc = zeros(1, BinsNum); 31 | for i = 1:BinsNum 32 | D.densityPerc(i) = numel(Objs.Pos(:,1)); 33 | end 34 | 35 | else 36 | % 3D image (multiple Z planes) 37 | D.density = zeros(1, (D.zEnd - D.zStart +1)); 38 | D.densityPerc = zeros(1, BinsNum); 39 | D.densityPercMask = zeros(1, BinsNum); 40 | D.volume = zeros(1, (D.zEnd - D.zStart +1)); 41 | D.volumePerc = zeros(1, BinsNum); 42 | D.volumePercMask = zeros(1, BinsNum); 43 | 44 | for i = D.zStart: D.zEnd -1 45 | D.density(i) = numel(find(Objs.Pos(:,3) == i)); 46 | D.volume(i) = mean(Objs.Vol(Objs.Pos(:,3) == i))*VoxelVolume; 47 | end 48 | 49 | PosPerc = Objs.Pos; 50 | for i = 1:size(PosPerc,1) 51 | PosPerc(i,3) = (PosPerc(i,3)-D.zStart) / (D.zEnd-D.zStart); 52 | PosPerc(i,3) = ceil(PosPerc(i,3)*BinsNum); 53 | end 54 | 55 | for i = 1:BinsNum 56 | D.densityPerc(i) = numel(find(PosPerc(:,3) == i)); 57 | D.volumePerc(i) = mean(Objs.Vol(PosPerc(:,3) == i))*VoxelVolume; 58 | end 59 | 60 | if isempty(Mask) || isempty(find(Mask.I(:), 1)) 61 | return 62 | end 63 | 64 | PosPerc = Objs.Pos; 65 | for i = 1:size(PosPerc,1) 66 | % Skip if current object is outside of the mask 67 | if Mask.I(sub2ind(size(Mask.I), PosPerc(i,1), PosPerc(i,2), PosPerc(i,3))) == 0 68 | PosPerc(i,3) = -1; 69 | continue 70 | end 71 | 72 | % Calculate Z position of each object as % within the masked volume 73 | zMask = squeeze(Mask.I(PosPerc(i,1), PosPerc(i,2),:)); 74 | zStart = find(zMask, 1); 75 | zEnd = find(zMask, 1, 'last'); 76 | PosPerc(i,3) = (PosPerc(i,3)-zStart) / (zEnd-zStart); 77 | PosPerc(i,3) = ceil(PosPerc(i,3)*BinsNum); 78 | end 79 | 80 | % Cound how many dots in each % bin 81 | for i = 1:BinsNum 82 | D.densityPercMask(i) = numel(find(PosPerc(:,3) == i)); 83 | D.volumePercMask(i) = mean(Objs.Vol(PosPerc(:,3) == i))*VoxelVolume; 84 | end 85 | end 86 | 87 | %% Plot dot density distribution as a function of Volume depth. 88 | if showPlot 89 | tmpH = figure('Name', 'Grouped distribution along Z'); 90 | set(tmpH, 'Position', [100 200 1200 500]); 91 | set(gcf, 'DefaultAxesFontName', 'Arial', 'DefaultAxesFontSize', 12); 92 | set(gcf, 'DefaultTextFontName', 'Arial', 'DefaultTextFontSize', 12); 93 | 94 | tiledlayout(1,2); 95 | nexttile; 96 | hold on; 97 | tmpY = D.densityPerc; 98 | tmpX = (1:BinsNum)*100/BinsNum; 99 | plot(tmpX, tmpY, 'k', 'MarkerSize', 8); 100 | plot(tmpX, D.densityPercMask, 'r', 'MarkerSize', 8); 101 | box off; 102 | set(gca, 'color', 'none', 'TickDir','out'); 103 | ylabel('Number of objects'); 104 | xlabel(['Volume depth % (bin: ' num2str(Settings.ImInfo.zum * D.binSize, 2) 'um)']); 105 | 106 | nexttile; 107 | hold on; 108 | sizeBin = Settings.ImInfo.xyum * Settings.ImInfo.xNumVox... 109 | *Settings.ImInfo.xyum * Settings.ImInfo.yNumVox... 110 | *Settings.ImInfo.zum * D.binSize; 111 | tmpY = D.densityPerc / sizeBin; 112 | tmpX = (1:BinsNum)*100/BinsNum; 113 | plot(tmpX, tmpY, 'k', 'MarkerSize', 8); 114 | 115 | if ~isempty(Mask) 116 | MaskedVoxN = numel(find(Mask.I)); 117 | MaskBinVolume = Settings.ImInfo.xyum *Settings.ImInfo.xyum *Settings.ImInfo.zum * MaskedVoxN / BinsNum; 118 | plot(tmpX, D.densityPercMask / MaskBinVolume, 'r', 'MarkerSize', 8); 119 | end 120 | 121 | box off; 122 | set(gca, 'color', 'none', 'TickDir','out'); 123 | ylabel('Density (objects / um^3)'); 124 | legend({'Full volume', 'Masked volume'}); 125 | xlabel(['Volume depth % (bin: ' num2str(Settings.ImInfo.zum * D.binSize, 2) 'um)']); 126 | 127 | clear tmp* plot_variance sizeBin; 128 | end 129 | end 130 | -------------------------------------------------------------------------------- /calcPathLengthStats.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function PathLengthStats = calcPathLengthStats(Dots, Skel, showPlot) 20 | %% 21 | Dots = getFilteredObjects(Dots, Dots.Filter); % work only on validated objects 22 | 23 | DotPathLengthList = Skel.FilStats.SkelPathLength2Soma(Dots.Skel.ClosestSkelIDs); 24 | EdgePathLengthList = Skel.FilStats.EdgePathLength2Soma; 25 | EdgeLengthList = Skel.SegStats.Lengths; 26 | 27 | EdgePathLengthMax = ceil(max(EdgePathLengthList)); 28 | 29 | DistBin = 10; %Bin distance is 10 micron by default 30 | DistFromSoma = 5:1:EdgePathLengthMax; 31 | NumDots = zeros(1, length(DistFromSoma)); 32 | EdgeLengths = zeros(1, length(DistFromSoma)); 33 | for i = 1 : length(DistFromSoma) 34 | NumDots(i) = length(find((DotPathLengthList>DistFromSoma(i)-DistBin/2) & (DotPathLengthList<=DistFromSoma(i)+DistBin/2))); 35 | EdgeLengths(i) = sum(EdgeLengthList((EdgePathLengthList>DistFromSoma(i)-DistBin/2) & (EdgePathLengthList<=DistFromSoma(i)+DistBin/2))); 36 | end 37 | 38 | PathLengthStats.PathLengthBin = DistBin; 39 | PathLengthStats.PathLength2CB = DistFromSoma; 40 | PathLengthStats.PvsPathLength = NumDots; 41 | PathLengthStats.DvsPathLength = EdgeLengths; 42 | PathLengthStats.PoverDvsPathLength = NumDots./EdgeLengths; 43 | 44 | if showPlot 45 | width = 20; 46 | height = 20; 47 | set(0,'units','centimeters'); 48 | scrsz = get(0,'screensize'); 49 | position= [scrsz(3)/2-width/2 scrsz(4)/2-height/2 width height]; 50 | h = figure; 51 | set(h,'units','centimeters'); 52 | set(h,'position',position); 53 | set(h,'paperpositionmode','auto'); 54 | set(0,'units','pixel'); 55 | set(h,'units','pixel'); 56 | set(gcf, 'Color', [0 0 0]); 57 | 58 | subplot(3,1,1, 'Color', [0 0 0]), hold on; 59 | plot(DistFromSoma, NumDots, 'w', 'LineWidth', 2); 60 | axis([0 EdgePathLengthMax 0 250]); 61 | set(gca, 'XColor', [1 1 1]); set(gca, 'YColor', [1 1 1]); 62 | title('bin=10um'); 63 | xlabel('Path length from cell body (�m)'); 64 | ylabel('Total number of dots in the bin'); 65 | 66 | subplot(3,1,2, 'Color', [0 0 0]), hold on; 67 | plot(DistFromSoma, EdgeLengths, 'w', 'LineWidth', 2); 68 | axis([0 EdgePathLengthMax 0 400]); 69 | set(gca, 'XColor', [1 1 1]); set(gca, 'YColor', [1 1 1]); 70 | title('bin=10um'); 71 | xlabel('Path length from cell body (�m)'); 72 | ylabel('Total lengths of dendrites in the bin'); 73 | 74 | subplot(3,1,3, 'Color', [0 0 0]), hold on; 75 | plot(DistFromSoma, PoverD, 'w', 'LineWidth', 2); 76 | axis([0 EdgePathLengthMax 0 max(1, max(PoverD))]); 77 | set(gca, 'XColor', [1 1 1]); set(gca, 'YColor', [1 1 1]); 78 | title('bin=10um'); 79 | xlabel('Path length from cell body (�m)'); 80 | ylabel('#puncta/�m dendrite'); 81 | 82 | set(gcf,'inverthardcopy','off'); %this will prevent color change back to default upon saving or printing 83 | %saveas(gcf, [pwd filesep 'images' filesep 'DotDend_vs_PathLengthStats'], 'tif'); 84 | end 85 | end -------------------------------------------------------------------------------- /calcSkelDistToSoma.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function Skel = calcSkelDistToSoma(Skel) 20 | %% Calculates the distance of each point to soma following skeleton's path 21 | % This program takes in Skel, march from soma to connected skels while 22 | % registering the path length from soma for each skel point. Then put the 23 | % calculated path length from soma under Skel.FilStats and return. 24 | 25 | % Collect cumulative distance from soma to beginning of each branch 26 | DistToBranch = zeros(1, numel(Skel.branches)); 27 | for i = 1:numel(Skel.branches) 28 | posParent = find([Skel.branches.id] == Skel.branches(i).idParent); 29 | while posParent > 0 30 | DistToBranch(i) = DistToBranch(i) + Skel.branches(posParent).length; 31 | posParent = find([Skel.branches.id] == Skel.branches(posParent).idParent); 32 | end 33 | end 34 | 35 | %% 36 | % Calculate distance from soma to each point of current branch 37 | pos = 1; % Counter of current position in DistToSoma 38 | DistToSoma = zeros(1, sum( arrayfun(@(x) size(x.points,1), Skel.branches) )); 39 | for i = 1:numel(Skel.branches) 40 | for p = 1:size(Skel.branches(i).points,1) 41 | if p == 1 42 | DistToSoma(pos) = DistToBranch(i); 43 | elseif size(Skel.branches(i).points,2) == 3 44 | DistToSoma(pos) = DistToSoma(pos-1) + pdist(Skel.branches(i).points(p-1:p,1:3)); 45 | else 46 | DistToSoma(pos) = DistToSoma(pos-1) + pdist(Skel.branches(i).points(p-1:p,4:6)); 47 | end 48 | pos = pos+1; 49 | end 50 | end 51 | 52 | % Calculated path length of edges by taking the mean of skels 53 | EdgeDistToSoma = zeros(1,size(Skel.FilStats.aEdges,1)); 54 | for i = 1:length(EdgeDistToSoma) 55 | EdgeDistToSoma(i) = mean([DistToSoma(Skel.FilStats.aEdges(i,1)), DistToSoma(Skel.FilStats.aEdges(i,2))]); 56 | end 57 | 58 | % Store the results under Skel.FilStats 59 | Skel.FilStats.SkelPathLength2Soma = DistToSoma; 60 | Skel.FilStats.EdgePathLength2Soma = EdgeDistToSoma; 61 | 62 | clear i idParent p pos DistToBranch DistToSoma EdgeDistToSoma; 63 | end -------------------------------------------------------------------------------- /calcSkelPathLength.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function Skel = calcSkelPathLength(Skel, ReportStats) 20 | %% This program was modified from HOSkelFinerGenerator.mat. 21 | %This program takes in Skel, march from soma to connected skels while 22 | %registering the path length from soma for each skel point. Then put the 23 | %calculated path length from soma under Skel.FilStats and return. 24 | 25 | SkelIDsPool = 1:1:size(Skel.FilStats.aXYZ,1); 26 | SkelIDsConnectivityPool = Skel.FilStats.aEdges; 27 | SkelSegLengthsPool = Skel.SegStats.Lengths; 28 | 29 | SomaPtID = Skel.FilStats.SomaPtID+1; 30 | SourceSkelIDs = SomaPtID; % start from soma. 31 | SkelIDsPool(SomaPtID) = []; % deplete the soma point. 32 | 33 | SkelPathLength2Soma = zeros(1,size(Skel.FilStats.aXYZ,1)); 34 | 35 | % March from the soma 36 | fprintf('Marching through current skeleton to calculate lengths ... '); 37 | while ~isempty(SkelIDsPool) 38 | % length(SkelIDsPool) % how many more skel to process 39 | if isempty(SourceSkelIDs) % if the previous skel was the dead end, resume from the first entry within the remaining pool. 40 | SourceSkelIDs = SkelIDsPool(1); 41 | SkelIDsPool(1) = []; % deplete the newly grabbed skel. 42 | end 43 | 44 | NextSkelIDs = []; 45 | for j=1:length(SourceSkelIDs) 46 | SourceSkelID = SourceSkelIDs(j); 47 | [SourceSkelRows, SourceSkelCols] = find(SkelIDsConnectivityPool == SourceSkelID); 48 | if ~isempty(SourceSkelCols) %if the source skel is not dead end, find the connected partner skel 49 | NextSkelCols = SourceSkelCols*(-1)+3; %to reverse 1 and 2 to get the partner skel. 50 | for i=1:length(NextSkelCols) 51 | SourceSkelRow = SourceSkelRows(i); 52 | SourceSkelCol = SourceSkelCols(i); 53 | NextSkelCol = NextSkelCols(i); 54 | NextSkelID = SkelIDsConnectivityPool(SourceSkelRow, NextSkelCol); 55 | Lengths2NextSkel = SkelSegLengthsPool(SourceSkelRow); 56 | 57 | SkelPathLength2Soma(NextSkelID) = SkelPathLength2Soma(SourceSkelID) + Lengths2NextSkel; 58 | 59 | NextSkelIDs = [NextSkelIDs, NextSkelID]; 60 | end 61 | SkelIDsConnectivityPool(SourceSkelRows,:) = []; % deplete the found connectivity from the pool. 62 | SkelSegLengthsPool(SourceSkelRows) = []; % also deplete seg lengths 63 | end 64 | end 65 | 66 | if ~isempty(NextSkelIDs) 67 | for id=1:length(NextSkelIDs) 68 | SkelIDsPool(SkelIDsPool==NextSkelIDs(id)) = []; %deplete the next grabbed skel. 69 | end 70 | end 71 | SourceSkelIDs = NextSkelIDs; %switch next to source for the next loop. 72 | end 73 | fprintf('DONE \n'); 74 | 75 | if ReportStats 76 | disp(['Farthest skel path distance is: ' max(SkelPathLength2Soma)]); 77 | disp(['Soma point ID is (Imaris soma pt ID + 1): ' num2str(SomaPtID)]); 78 | disp(['Skel IDs of zero path distance are (only soma point should have zero path distance): ' num2str(find(SkelPathLength2Soma==0))]); 79 | end 80 | 81 | % Calculated path length of edges by taking the mean of skels 82 | EdgePathLength2Soma = zeros(1,size(Skel.FilStats.aEdges,1)); 83 | for i = 1:length(EdgePathLength2Soma) 84 | EdgePathLength2Soma(i) = mean([SkelPathLength2Soma(Skel.FilStats.aEdges(i,1)), SkelPathLength2Soma(Skel.FilStats.aEdges(i,2))]); 85 | end 86 | 87 | % Store the results under Skel.FilStats 88 | Skel.FilStats.SkelPathLength2Soma = SkelPathLength2Soma; 89 | Skel.FilStats.EdgePathLength2Soma = EdgePathLength2Soma; 90 | end -------------------------------------------------------------------------------- /colocAutoEngulf.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | % *Colocalization - Automatic overlap analysis between engulfing/engilfed* 20 | % Required parameters 21 | % srcDots = Reference engulfing objects 22 | % dstDots = Destination objects engulfed by srcDots 23 | % NumVoxOverlap = Number of overlapping voxels between each objet and 24 | % the binary mask to consider the object as colocalized 25 | % NumPercOverlap = Number of overlapping voxels between each objet and 26 | % the binary mask expressed as percentage of Dots size 27 | % to consider the object as colocalized 28 | 29 | function ColocAuto = colocAutoEngulf(srcDots, dstDots, NumVoxOverlap, NumPercOverlap, WithinDist, CenterMustOverlap) 30 | %% 31 | ColocAuto.Ref = srcDots.Name; 32 | ColocAuto.Dst = dstDots.Name; 33 | ColocAuto.Flag = zeros([1,numel(srcDots.Vox)], 'uint8'); 34 | 35 | ColocAuto.Settings.Method = 'AutoEngulf'; 36 | ColocAuto.Settings.NumVoxOverlap = NumVoxOverlap; 37 | ColocAuto.Settings.NumPercOverlap = NumPercOverlap; 38 | ColocAuto.Settings.DistanceWithin = WithinDist; 39 | ColocAuto.Settings.CentroidOverlap = CenterMustOverlap; 40 | ColocAuto.Settings.RotationAngle = 0; 41 | 42 | % Trasverse each reference object and count how many objects are engulfed 43 | % *IMPORTANT*: Flag here stores the absolute number of dstDots that 44 | % each srcDot is engulfing (after verifying overlap is more than threshold) 45 | 46 | xyum = srcDots.Settings.ImInfo.xyum; 47 | zum = srcDots.Settings.ImInfo.zum; 48 | 49 | for idx_src = 1:numel(srcDots.Vox) 50 | if ~srcDots.Filter.passF(idx_src) 51 | ColocAuto.Flag(idx_src) = -1; % Invalid dot 52 | continue 53 | end 54 | 55 | for idx_dst = 1:numel(dstDots.Vox) 56 | if ~dstDots.Filter.passF(idx_dst) 57 | continue 58 | end 59 | 60 | if CenterMustOverlap 61 | % Calculate brightness peak position because dstDots.Pos(i,:) might not 62 | % be any of the actual pixels listed in dstDots.Vox(i).Pos 63 | BrightPeakPos = dstDots.Vox(idx_dst).Ind(dstDots.Vox(idx_dst).RawBright == max(dstDots.Vox(idx_dst).RawBright)); 64 | if size(BrightPeakPos,1) > 1 65 | BrightPeakPos = BrightPeakPos(1,:); 66 | end 67 | 68 | % Check whether the center voxel of dstDot is among the voxels belonging to srcDot 69 | if isempty(find(srcDots.Vox(idx_src).Ind == BrightPeakPos, 1)) 70 | continue 71 | end 72 | end 73 | 74 | VoxOverlap = numel(intersect(srcDots.Vox(idx_src).Ind, dstDots.Vox(idx_dst).Ind)); 75 | VoxOverlapPerc = 100 * VoxOverlap / dstDots.Vol(idx_dst); % Store voxel overlap as percent of engulfed object volume 76 | PeakDistxy = hypot( (srcDots.Pos(idx_src,1)-dstDots.Pos(idx_dst,1))*xyum, (srcDots.Pos(idx_src,2)-dstDots.Pos(idx_dst,2))*xyum); 77 | PeakDistxyz = hypot( PeakDistxy, (srcDots.Pos(idx_src,3)-dstDots.Pos(idx_dst,3))*zum); % calculate separately along Z because this dimension has different pixel size 78 | 79 | if (VoxOverlap >= NumVoxOverlap) && (VoxOverlapPerc >= NumPercOverlap) && (PeakDistxyz <= WithinDist) 80 | ColocAuto.Flag(idx_src) = ColocAuto.Flag(idx_src) + 1; % Add one more engulfed 81 | end 82 | end 83 | end 84 | 85 | ColocAuto.Results.NumColoc = length(find(ColocAuto.Flag > 0)); 86 | ColocAuto.Results.NumNonColoc = length(find(ColocAuto.Flag == 0)); 87 | ColocAuto.Results.NumFalse = length(find(ColocAuto.Flag < 0)); 88 | ColocAuto.Results.ColocRate = ColocAuto.Results.NumColoc/(ColocAuto.Results.NumColoc+ColocAuto.Results.NumNonColoc); 89 | ColocAuto.Results.FalseRate = ColocAuto.Results.NumFalse/(ColocAuto.Results.NumColoc+ColocAuto.Results.NumNonColoc+ColocAuto.Results.NumFalse); 90 | end -------------------------------------------------------------------------------- /colocAutoMask.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | % *Colocalization - Automatic analysis of overlap against a binary mask* 20 | % Required parameters 21 | % Dots = list of recognized objects 22 | % Filter = boolean list of which objects in Dots are validated 23 | % Colo = XYZ matrix of the colocalizing binary mask 24 | % FileName = Name of the colocalizing binary mask file 25 | % NumVoxOverlap = Number of overlapping voxels between each objet and 26 | % the binary mask to consider the object as colocalized 27 | % 28 | 29 | function ColocAuto = colocAutoMask(srcDots, Colo, FileName, NumVoxOverlap, NumPercOverlap, CenterMustOverlap) 30 | %% 31 | [~, fName, ~] = fileparts(FileName); 32 | ColocAuto.Ref = srcDots.Name; 33 | ColocAuto.Dst = fName; 34 | ColocAuto.Flag = zeros([1,numel(srcDots.Vox)], 'uint8'); 35 | 36 | ColocAuto.Settings.Method = 'AutoMask'; 37 | ColocAuto.Settings.NumVoxOverlap = NumVoxOverlap; 38 | ColocAuto.Settings.NumPercOverlap = NumPercOverlap; 39 | ColocAuto.Settings.DistanceWithin = inf; 40 | ColocAuto.Settings.CentroidOverlap = CenterMustOverlap; 41 | ColocAuto.Settings.RotationAngle = 0; 42 | 43 | for i= 1:numel(srcDots.Vox) 44 | if ~srcDots.Filter.passF(i) 45 | ColocAuto.Flag(i) = 3; % Invalid dot (filter==0) 46 | continue 47 | end 48 | 49 | if CenterMustOverlap 50 | % Calculate brightness peak position because srcDots.Pos(i,:) might not 51 | % be any of the actual pixels listed in srcDots.Vox(i).Pos 52 | BrightPeakPos = srcDots.Vox(i).Ind(srcDots.Vox(i).RawBright == max(srcDots.Vox(i).RawBright)); 53 | if size(BrightPeakPos,1) > 1 54 | BrightPeakPos = BrightPeakPos(1,:); 55 | end 56 | 57 | if ~Colo(BrightPeakPos) 58 | ColocAuto.Flag(i) = 2; % Not Colocalized 59 | continue 60 | end 61 | end 62 | 63 | % Trasverse each valid objects and check if the mask is overlapping 64 | VoxOverlap = numel(find(Colo(srcDots.Vox(i).Ind))); %one liner using indexes 65 | 66 | % Define also overlap as percent of total object size 67 | PercOverlap = 100 * VoxOverlap / srcDots.Vol(i); 68 | 69 | if (VoxOverlap >= NumVoxOverlap) && (PercOverlap >= NumPercOverlap) 70 | ColocAuto.Flag(i) = 1; % Colocalized 71 | else 72 | ColocAuto.Flag(i) = 2; % Not Colocalized 73 | end 74 | end 75 | 76 | ColocAuto.Results.NumColoc = length(find(ColocAuto.Flag == 1)); 77 | ColocAuto.Results.NumNonColoc = length(find(ColocAuto.Flag == 2)); 78 | ColocAuto.Results.NumFalse = length(find(ColocAuto.Flag == 3)); 79 | ColocAuto.Results.ColocRate = ColocAuto.Results.NumColoc/(ColocAuto.Results.NumColoc+ColocAuto.Results.NumNonColoc); 80 | ColocAuto.Results.FalseRate = ColocAuto.Results.NumFalse/(ColocAuto.Results.NumColoc+ColocAuto.Results.NumNonColoc+ColocAuto.Results.NumFalse); 81 | 82 | end -------------------------------------------------------------------------------- /colocAutoNN.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | % *Colocalization - Automatic overlap analysis between nearest neighbors* 20 | % Required parameters 21 | % srcDots = list of recognized objects 22 | % NN = Nearest neighbors of srcDots to analyze 23 | % NumVoxOverlap = Number of overlapping voxels between each objet and 24 | % the binary mask to consider the object as colocalized 25 | % NumPercOverlap = Number of overlapping voxels between each objet and 26 | % the binary mask expressed as percentage of srcDots size 27 | % to consider the object as colocalized 28 | 29 | function ColocAuto = colocAutoNN(srcDots, dstDots, NN, NumVoxOverlap, NumPercOverlap, WithinDist, CenterMustOverlap) 30 | %% 31 | ColocAuto.Ref = srcDots.Name; 32 | ColocAuto.Dst = NN.Name; 33 | ColocAuto.Flag = zeros([1,numel(srcDots.Vox)], 'uint8'); 34 | 35 | ColocAuto.Settings.Method = 'AutoNN'; 36 | ColocAuto.Settings.NumVoxOverlap = NumVoxOverlap; 37 | ColocAuto.Settings.NumPercOverlap = NumPercOverlap; 38 | ColocAuto.Settings.DistanceWithin = WithinDist; 39 | ColocAuto.Settings.CentroidOverlap = CenterMustOverlap; 40 | ColocAuto.Settings.RotationAngle = 0; 41 | 42 | % Trasverse each valid object and check if Nearest Neighbor is 43 | % overlappedthe above the voxel and percent thresholds 44 | for i = 1:numel(srcDots.Vox) 45 | if ~srcDots.Filter.passF(i) 46 | ColocAuto.Flag(i) = 3; % Invalid dot (filter==0) 47 | continue 48 | end 49 | 50 | if CenterMustOverlap 51 | % Calculate brightness peak position because srcDots.Pos(i,:) might not 52 | % be any of the actual pixels listed in srcDots.Vox(i).Pos 53 | idx_dst = NN.NeighborIdx(i); 54 | BrightPeakPos = dstDots.Vox(idx_dst).Ind(dstDots.Vox(idx_dst).RawBright == max(dstDots.Vox(idx_dst).RawBright)); 55 | if size(BrightPeakPos,1) > 1 56 | BrightPeakPos = BrightPeakPos(1,:); 57 | end 58 | 59 | % Check whether center of NN dstDot is among the voxels of srcDot 60 | if isempty(find(srcDots.Vox(i).Ind == BrightPeakPos, 1)) 61 | ColocAuto.Flag(i) = 2; % Not Colocalized 62 | continue 63 | end 64 | end 65 | 66 | % Assign colocalization to objects overlapping more than thresholds 67 | if (NN.VoxOverlap(i) >= NumVoxOverlap) && (NN.VoxOverlapPerc(i) >= NumPercOverlap) && (NN.Dist(i) <= WithinDist) 68 | ColocAuto.Flag(i) = 1; % Colocalized 69 | else 70 | ColocAuto.Flag(i) = 2; % Not Colocalized 71 | end 72 | end 73 | 74 | ColocAuto.Results.NumColoc = length(find(ColocAuto.Flag == 1)); 75 | ColocAuto.Results.NumNonColoc = length(find(ColocAuto.Flag == 2)); 76 | ColocAuto.Results.NumFalse = length(find(ColocAuto.Flag == 3)); 77 | ColocAuto.Results.ColocRate = ColocAuto.Results.NumColoc/(ColocAuto.Results.NumColoc+ColocAuto.Results.NumNonColoc); 78 | ColocAuto.Results.FalseRate = ColocAuto.Results.NumFalse/(ColocAuto.Results.NumColoc+ColocAuto.Results.NumNonColoc+ColocAuto.Results.NumFalse); 79 | end -------------------------------------------------------------------------------- /colocDotStackCutter.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function ImStkCut = colocDotStackCutter(ImStk, Dots, DotNum, NumMargins, NumVoxs) 20 | 21 | VoxPos = []; 22 | for dot = 1:length(DotNum) %you can enter multiple dots, useful when you want to see the grouping of two dots, or colocalization of two dots. 23 | VoxPos = [VoxPos; Dots.Vox(DotNum(dot)).Pos]; 24 | end 25 | 26 | VoxPosYMin = min(VoxPos(:,1)); 27 | VoxPosYMax = max(VoxPos(:,1)); 28 | VoxPosYMid = round((VoxPosYMin+VoxPosYMax)/2); 29 | VoxPosXMin = min(VoxPos(:,2)); 30 | VoxPosXMax = max(VoxPos(:,2)); 31 | VoxPosXMid = round((VoxPosXMin+VoxPosXMax)/2); 32 | VoxPosZMin = min(VoxPos(:,3)); 33 | VoxPosZMax = max(VoxPos(:,3)); 34 | VoxPosZMid = round((VoxPosZMin+VoxPosZMax)/2); 35 | 36 | ImSize = size(ImStk); 37 | 38 | %you can cut image stack (ImStk) around the dot(s) using Margins around the 39 | %dot contour (NumMargins must be 3-element vector with y, x and z margins. 40 | %If this way is not used, NumMargins must be []. Or, use simply the number 41 | %of voxels to be cut (NumVoxs must be 3-element vector with y, x and z vox 42 | %num. If this way is not used, NumVoxs must be []). 43 | if ~isempty(NumMargins) 44 | ImStkCuty1 = max(VoxPosYMin-NumMargins(1), 1); 45 | ImStkCuty2 = min(VoxPosYMax+NumMargins(1), ImSize(1)); 46 | ImStkCutx1 = max(VoxPosXMin-NumMargins(2), 1); 47 | ImStkCutx2 = min(VoxPosXMax+NumMargins(2), ImSize(2)); 48 | ImStkCutz1 = max(VoxPosZMin-NumMargins(3), 1); 49 | ImStkCutz2 = min(VoxPosZMax+NumMargins(3), ImSize(3)); 50 | elseif ~isempty(NumVoxs) 51 | ImStkCuty1 = max(VoxPosYMid-round(NumVoxs(1)/2), 1); 52 | ImStkCuty2 = min(VoxPosYMid-round(NumVoxs(1)/2)+NumVoxs(1)-1, ImSize(1)); 53 | ImStkCutx1 = max(VoxPosXMid-round(NumVoxs(2)/2), 1); 54 | ImStkCutx2 = min(VoxPosXMid-round(NumVoxs(2)/2)+NumVoxs(2)-1, ImSize(2)); 55 | ImStkCutz1 = max(VoxPosZMid-round(NumVoxs(3)/2), 1); 56 | ImStkCutz2 = min(VoxPosZMid-round(NumVoxs(3)/2)+NumVoxs(3)-1, ImSize(3)); 57 | else 58 | disp('Provide NumMargins or NumVoxs'); 59 | end 60 | 61 | ImStkCut = ImStk(ImStkCuty1:ImStkCuty2, ImStkCutx1:ImStkCutx2, ImStkCutz1:ImStkCutz2); 62 | -------------------------------------------------------------------------------- /colocManual.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | % *Colocalization - Manual analysis* 20 | % *This scripts allows to analyze whether each object found by ObjectFinder 21 | % is co-localized to another signal of interest (loaded as image stack) 22 | % The user is asked to review each object and judge whether is co-localized 23 | % or non-colocalized to the signal of interest* 24 | % 25 | % Originally written for the colocalization of postsynaptic PSD95 puncta 26 | % and presynaptic CtBP2 puncta. 27 | % 28 | % depends on: colocDotStackCutter.m colocVideoFig.m 29 | % ------------------------------------------------------------------------- 30 | 31 | function Coloc = colocManual(Dots, Post, Colo, FileName, Colo2, FileName2) 32 | %% 33 | [~, fName, ~] = fileparts(FileName); 34 | if exist([pwd filesep 'ColocManual.mat'],'file') 35 | load([pwd filesep 'ColocManual.mat'], 'ColocManual'); % Load a previously unfinished analysis 36 | if exist([pwd filesep 'ColocManual2.mat'],'file') 37 | load([pwd filesep 'ColocManual2.mat'], 'ColocManual2'); % Load a previously unfinished analysis 38 | else 39 | ColocManual2 = struct; 40 | end 41 | else 42 | if isempty(Colo2) 43 | ColocManual.Ref = Dots.Name; 44 | ColocManual.Dst = fName; 45 | ColocManual.Flag = zeros([1,numel(Dots.Filter.passF)], 'uint8'); 46 | ColocManual.Flag(find(Dots.Filter.passF == 0)) = 3; % Mark invalid dots as 3 = non-dot 47 | 48 | ColocManual.Settings.Method = 'Manual'; 49 | ColocManual.Settings.NumVoxOverlap = 0; 50 | ColocManual.Settings.NumPercOverlap = 0; 51 | ColocManual.Settings.DistanceWithin = inf; 52 | ColocManual.Settings.CentroidOverlap = false; 53 | ColocManual.Settings.RotationAngle = 0; 54 | 55 | ColocManual2 = struct; 56 | else 57 | [~, fName2, ~] = fileparts(FileName2); 58 | 59 | ColocManual.Ref = Dots.Name; 60 | ColocManual.Dst = fName; 61 | ColocManual.Flag = zeros([1,numel(Dots.Filter.passF)], 'uint8'); 62 | ColocManual.Flag(find(Dots.Filter.passF == 0)) = 3; % Mark invalid objects as 3 = false object 63 | 64 | ColocManual.Settings.Method = 'Manual'; 65 | ColocManual.Settings.NumVoxOverlap = 0; 66 | ColocManual.Settings.NumPercOverlap = 0; 67 | ColocManual.Settings.DistanceWithin = inf; 68 | ColocManual.Settings.CentroidOverlap = false; 69 | ColocManual.Settings.RotationAngle = 0; 70 | 71 | ColocManual2 = ColocManual; 72 | ColocManual2.Dst = fName2; 73 | end 74 | end 75 | 76 | Coloc = colocVideoFig(ColocManual, Dots, Post, Colo, Colo2, ColocManual2); 77 | end 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /colocManualCheckDouble.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | % *Colocalization - Manual analysis* 20 | % *This scripts allows to analyze whether each object found by ObjectFinder 21 | % is co-localized to another signal of interest (loaded as image stack) 22 | % The user is asked to review each object and judge whether is co-localized 23 | % or non-colocalized to the signal of interest* 24 | % 25 | % Originally written for the colocalization of postsynaptic PSD95 puncta 26 | % and presynaptic CtBP2 puncta. 27 | % 28 | % depends on: colocDotStackCutter.m colocVideoFig.m 29 | % ------------------------------------------------------------------------- 30 | 31 | function Coloc = colocManualCheckDouble(Dots, Filter, Post, Colo, ColocManual, Colo2, ColocManual2) 32 | if isempty(Colo2) % Single channel, check only colocalized objects 33 | % Find objects that are colocalized with both channels 34 | Coloc1 = find(ColocManual.Flag==1); % Numbers of colocalized dots analyzed 35 | 36 | % Flag as 0 (redo) those objects in order to re-analyze them 37 | ColocManual.Flag(Coloc1) = 0; 38 | ColocManual.Results.NumColoc = ColocManual.Results.NumColoc - numel(Coloc1); 39 | 40 | % Re-annalyze only double colocalized objects 41 | %Grouped = getFilteredObjects(Dots, Filter); 42 | Coloc = colocVideoFig(ColocManual, Dots, Post, Colo, Colo2, ColocManual2); 43 | else % 2 Colocalizing channels, check only double-colocalized objects 44 | % Find objects that are colocalized with both channels 45 | Coloc1 = find(ColocManual.Flag==1); % Numbers of colocalized dots analyzed 46 | Coloc2 = find(ColocManual2.Flag==1); % Numbers of colocalized dots analyzed 47 | Coloc12 = intersect(Coloc1, Coloc2); 48 | 49 | % Flag those objects off in order to re-analyze them 50 | ColocManual.Flag(Coloc12) = 0; 51 | ColocManual.Results.NumColoc = ColocManual.Results.NumColoc - numel(Coloc12); 52 | 53 | ColocManual2.Flag(Coloc12) = 0; 54 | ColocManual2.Results.NumColoc = ColocManual2.Results.NumColoc - numel(Coloc12); 55 | 56 | % Re-annalyze only double colocalized objects 57 | %Grouped = getFilteredObjects(Dots, Filter); 58 | Coloc = colocVideoFig(ColocManual, Dots, Post, Colo, Colo2, ColocManual2); 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /colocManualCheckNotColoc.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | % *Colocalization - Manual analysis* 20 | % *This scripts allows to analyze whether each object found by ObjectFinder 21 | % is co-localized to another signal of interest (loaded as image stack) 22 | % The user is asked to review each object and judge whether is co-localized 23 | % or non-colocalized to the signal of interest* 24 | % 25 | % Ask user to check only objects that were flagged as NOT colocalized 26 | % 27 | % Originally written for the colocalization of postsynaptic PSD95 puncta 28 | % and presynaptic CtBP2 puncta. 29 | % 30 | % depends on: colocDotStackCutter.m colocVideoFig.m 31 | % ------------------------------------------------------------------------- 32 | 33 | function Coloc = colocManualCheckNotColoc(Dots, Filter, Post, Colo, ColocManual, Colo2, ColocManual2) 34 | if isempty(Colo2) % Single channel, check only colocalized objects 35 | % Find objects that are colocalized with both channels 36 | Coloc1 = find(ColocManual.Flag==2); % Numbers of colocalized dots analyzed 37 | 38 | % Flag as 0 (redo) those objects in order to re-analyze them 39 | ColocManual.ColocFlag(Coloc1) = 0; 40 | ColocManual.Results.NumColoc = ColocManual.Results.NumColoc - numel(Coloc1); 41 | 42 | % Re-annalyze only double colocalized objects 43 | Grouped = getFilteredObjects(Dots, Filter); 44 | Coloc = colocVideoFig(ColocManual, Grouped, Post, Colo, Colo2, ColocManual2); 45 | else % 2 Colocalizing channels, check only double-colocalized objects 46 | % Find objects that are colocalized with both channels 47 | Coloc1 = find(ColocManual.Flag==2); % Numbers of colocalized dots analyzed 48 | Coloc2 = find(ColocManual2.Flag==2); % Numbers of colocalized dots analyzed 49 | Coloc12 = intersect(Coloc1, Coloc2); 50 | 51 | % Flag those objects off in order to re-analyze them 52 | ColocManual.Flag(Coloc12) = 0; 53 | ColocManual.Results.NumColoc = ColocManual.Results.NumColoc - numel(Coloc12); 54 | 55 | ColocManual2.Flag(Coloc12) = 0; 56 | ColocManual2.Results.NumColoc = ColocManual2.Results.NumColoc - numel(Coloc12); 57 | 58 | % Re-annalyze only double colocalized objects 59 | Grouped = getFilteredObjects(Dots, Filter); 60 | Coloc = colocVideoFig(ColocManual, Grouped, Post, Colo, Colo2, ColocManual2); 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /convertObjectFinderDataV3toV4.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function convertObjectFinderDataV3toV4 21 | %% Convert objectfinder 3.x data format to 4.x data format 22 | 23 | % Create Mask from D.mat 24 | if exist('D.mat','file') 25 | load('D.mat'); 26 | Mask = D; 27 | save('Mask.mat', 'Mask'); 28 | clear D Mask 29 | end 30 | 31 | % Create Filter properties from SG.mat 32 | if exist('find', 'dir') 33 | load([pwd filesep 'find' filesep 'SG.mat']) 34 | if isfield(SG, 'passI') 35 | Filter.passF = SG.passI; 36 | elseif isfield(SG, 'passF') 37 | Filter.passF = SG.passF; 38 | end 39 | Filter.FilterOpts.EdgeDotCut = SG.SGOptions.EdgeDotCut; 40 | Filter.FilterOpts.SingleZDotCut = SG.SGOptions.SingleZDotCut; 41 | Filter.FilterOpts.xyStableDots = SG.SGOptions.xyStableDots; 42 | Filter.FilterOpts.Thresholds.ITMax = 0; 43 | Filter.FilterOpts.Thresholds.ITMaxDir = 1; 44 | Filter.FilterOpts.Thresholds.Vol = 0; 45 | Filter.FilterOpts.Thresholds.VolDir = 1; 46 | Filter.FilterOpts.Thresholds.MeanBright = 0; 47 | Filter.FilterOpts.Thresholds.MeanBrightDir = 1; 48 | save('Filter.mat','Filter'); 49 | clear SG Filter 50 | rmdir('find', 's'); 51 | end 52 | 53 | % Convert Dots.mat 54 | load('Dots.mat'); 55 | if isfield(Dots, 'TotalNumOverlapDots') 56 | Dots = rmfield(Dots,'TotalNumOverlapDots'); 57 | Dots = rmfield(Dots,'TotalNumOverlapVoxs'); 58 | end 59 | if isfield(Dots, 'Ratio') 60 | Dots = rmfield(Dots,'Ratio'); 61 | end 62 | if isfield(Dots, 'DF') 63 | Dots = rmfield(Dots,'DF'); 64 | Dots = rmfield(Dots,'DFOf'); 65 | Dots = rmfield(Dots,'DFOfTopHalf'); 66 | end 67 | if isfield(Dots, 'Im') && isfield(Dots.Im, 'CBpos') 68 | Dots.ImInfo.CBpos = Dots.Im.CBpos; 69 | Dots = rmfield(Dots,'Im'); 70 | end 71 | save('Dots.mat', 'Dots'); 72 | clear Dots 73 | 74 | % Convert Settings.mat 75 | load('Settings.mat'); 76 | Settings.objfinder.blockSize = Settings.dotfinder.blockSize; 77 | Settings.objfinder.blockBuffer = Settings.dotfinder.blockBuffer; 78 | Settings.objfinder.thresholdStep = Settings.dotfinder.thresholdStep; 79 | Settings.objfinder.maxDotSize = ceil(Settings.dotfinder.maxDotSize); 80 | Settings.objfinder.minDotSize = ceil(Settings.dotfinder.minFinalDotSize); 81 | Settings.objfinder.itMin = Settings.dotfinder.itMin; 82 | Settings.objfinder.minFinalDotSize = Settings.dotfinder.minFinalDotSize; 83 | Settings.objfinder.watershed = 1; 84 | Settings.debug = 0; 85 | Settings = rmfield(Settings,'dotfinder'); 86 | save('Settings.mat', 'Settings'); 87 | clear Settings 88 | 89 | delete('D.mat'); 90 | delete('CA.mat'); 91 | delete('Grad.mat'); 92 | delete('GradAll.mat'); 93 | delete('GradI.mat'); 94 | delete('Grouped.mat'); 95 | delete('TPN.mat'); 96 | delete('Use.mat'); 97 | if isfolder('temp') 98 | rmdir('temp', 's'); 99 | end 100 | end -------------------------------------------------------------------------------- /convertObjectFinderDataV4toV5.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function convertObjectFinderDataV4toV5 21 | %% Convert objectfinder 4.x data format to 5.x data format 22 | 23 | load('Dots.mat', 'Dots'); 24 | load('Filter.mat', 'Filter'); 25 | load('Settings.mat', 'Settings'); 26 | 27 | Dots.Name = 'PSD95'; 28 | Dots.Settings = Settings; 29 | if isfield(Dots.Settings, 'dotfinder') 30 | Dots.Settings.objfinder = Dots.Settings.dotfinder; 31 | Dots.Settings = rmfield(Dots.Settings, 'dotfinder'); 32 | end 33 | 34 | Dots.Settings.objfinder.blockSearch = true; 35 | Dots.Settings.objfinder.sphericity = true; 36 | Dots.Settings.objfinder.watershed = true; 37 | Dots.Settings.objfinder.minIntensity = 2; 38 | Dots.Settings.ImInfo.PostChName = 'PSD95.tif'; 39 | Dots.Filter = Filter; 40 | Dots.Settings.Filter = Dots.Filter.FilterOpts; 41 | 42 | if isfield(Dots, 'Round') 43 | Dots = rmfield(Dots,'Round'); 44 | Dots.Shape = struct; 45 | Dots = fitSphere(Dots, Dots.Settings); 46 | else 47 | Dots.Shape = struct; 48 | Dots = fitSphere(Dots, Dots.Settings); 49 | end 50 | 51 | Dots.Density = struct; 52 | if exist('Density.mat', 'file') 53 | load('Density.mat', 'Density'); 54 | Dots.Density = Density; 55 | end 56 | 57 | if exist('PathLengthStats.mat', 'file') 58 | load('PathLengthStats.mat', 'PathLengthStats'); 59 | Dots.Density.PathLengthStats = PathLengthStats; 60 | end 61 | 62 | Dots.Skel = struct; 63 | if isfield(Dots, 'Dist2CB') 64 | Dots.Skel.Dist2CB = Dots.Dist2CB; 65 | Dots = rmfield(Dots,'Dist2CB'); 66 | 67 | Dots.Settings.ImInfo.CBpos = Dots.ImInfo.CBpos; 68 | Dots = rmfield(Dots,'ImInfo'); 69 | end 70 | 71 | if isfield(Dots, 'ClosestSkelIDs') 72 | Dots.Skel.ClosestSkelIDs = Dots.ClosestSkelIDs; 73 | Dots.Skel.ClosestSkelDist = Dots.ClosestSkelDist; 74 | Dots = rmfield(Dots,'ClosestSkelIDs'); 75 | Dots = rmfield(Dots,'ClosestSkelDist');Dist2CB 76 | end 77 | 78 | Dots.Coloc = struct; 79 | if exist('Coloc.mat', 'file') 80 | load('Coloc.mat', 'Coloc'); 81 | Dots.Coloc = Coloc; 82 | end 83 | 84 | Dots.NN = struct; 85 | save('Dots.mat', 'Dots'); 86 | 87 | 88 | clear Density Filter PathLengthStats Settings Coloc 89 | delete('Dend.mat'); 90 | delete('Post.mat'); 91 | delete('Filter.mat'); 92 | delete('Density.mat'); 93 | delete('PathLengthStats.mat'); 94 | end -------------------------------------------------------------------------------- /convertObjectFinderDataV5toV7.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function convertObjectFinderDataV5toV7 21 | %% Convert objectfinder 5.x or 6.x data format to 7.x data format 22 | 23 | if ~exist('objects','dir') 24 | mkdir('objects'); 25 | end 26 | 27 | load('Dots.mat', 'Dots'); 28 | 29 | % Ensure Dots structure has a field for shape 30 | if ~isfield(Dots, 'Shape') 31 | Dots.Shape = struct; 32 | Dots.Settings.objfinder.sphericity = false; 33 | end 34 | 35 | % Ensure Colocalization has fields for Method, NumVoxOverlap, NumPercOverlap 36 | for idx_dot = 1:numel(Dots) 37 | if isfield(Dots(idx_dot), 'Coloc') && ~isempty(fieldnames(Dots(idx_dot).Coloc)) 38 | for idx_coloc = 1:numel(Dots(idx_dot).Coloc) 39 | if ~isfield(Dots(idx_dot).Coloc(idx_coloc), 'Method') || isempty(Dots(idx_dot).Coloc(idx_coloc).Method) 40 | Dots(idx_dot).Coloc(idx_coloc).Method = 'Unknown'; 41 | Dots(idx_dot).Coloc(idx_coloc).NumVoxOverlap = 0; 42 | Dots(idx_dot).Coloc(idx_coloc).NumPercOverlap = 0; 43 | end 44 | end 45 | end 46 | end 47 | 48 | for i = 1:numel(Dots) 49 | saveObjects(Dots(i)); 50 | end 51 | 52 | delete('Dots.mat'); % Dots are now stored inside /objects/ folder 53 | delete('Colo.mat'); % No more need to store colo image, done in memory 54 | end -------------------------------------------------------------------------------- /convertObjectFinderDataV7toV8.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function convertObjectFinderDataV7toV8 21 | %% Convert objectfinder 7.x data format to 8.x data format 22 | 23 | % Create a skeleton folder and move in there any existing skeleton 24 | if ~exist('skeletons','dir') 25 | mkdir('objects'); 26 | end 27 | 28 | if exist('Skel.mat', 'file') 29 | Skel = load('Skel.mat', 'Skel'); 30 | saveSkel(Skel.Skel); 31 | delete('Skel.mat'); % Skeleton is now stored inside ./skeletons/ 32 | delete('SkelFiner.mat'); % Skeleton is now stored inside ./skeletons/ 33 | end 34 | 35 | 36 | % Remove 'data' and 'images' folders as no more needed 37 | if exist([pwd filesep 'data'],'dir') 38 | rmdir([pwd filesep 'data'], 's'); 39 | end 40 | if exist([pwd filesep 'images'],'dir') 41 | rmdir([pwd filesep 'images'], 's'); 42 | end 43 | 44 | end -------------------------------------------------------------------------------- /convertObjectFinderDataV8toV10.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function convertObjectFinderDataV8toV10 21 | %% Convert objectfinder 8.x data format to 10.x data format 22 | disp('Converting Project from Objectfinder 8.x to 10.x format'); 23 | 24 | % Add version of ObjectFinder used to generate project to Settings 25 | Settings = load('Settings.mat'); 26 | Settings.Version = '10.0'; 27 | save('Settings.mat', '-struct', 'Settings'); 28 | 29 | % Convert colocalization info to new format 30 | [Objs, UIDs] = listObjects; 31 | 32 | for i= 1:numel(UIDs) 33 | disp([' |- Converting ' Objs{i}]); 34 | Obj = loadObjects(UIDs{i}); 35 | if isempty(fieldnames(Obj.Coloc)) 36 | continue 37 | end 38 | 39 | ColocList = struct; 40 | for c = 1:numel(Obj.Coloc) 41 | ColocOld = Obj.Coloc(c); 42 | 43 | ColocNew = struct; 44 | ColocNew.Ref = ColocOld.Source; 45 | ColocNew.Dst = ColocOld.Fish1; 46 | ColocNew.Flag = ColocOld.ColocFlag; 47 | 48 | ColocNew.Settings.Method = ColocOld.Method; 49 | ColocNew.Settings.NumVoxOverlap = ColocOld.NumVoxOverlap; 50 | ColocNew.Settings.NumPercOverlap = ColocOld.NumPercOverlap; 51 | ColocNew.Settings.DistanceWithin = inf; 52 | ColocNew.Settings.CentroidOverlap = false; 53 | ColocNew.Settings.RotationAngle = 0; 54 | 55 | ColocNew.Results.ColocNum = ColocOld.NumDotsColoc; 56 | ColocNew.Results.NonColocNum = ColocOld.NumDotsNonColoc; 57 | ColocNew.Results.FalseNum = ColocOld.NumFalseDots; 58 | ColocNew.Results.ColocRate = ColocOld.ColocRate; 59 | ColocNew.Results.FalseRate = ColocOld.FalseDotRate; 60 | 61 | if isempty(fieldnames(ColocList)) 62 | ColocList = ColocNew; 63 | else 64 | ColocList(end+1) = ColocNew; %#ok 65 | end 66 | end 67 | 68 | Obj.Coloc = ColocList; 69 | saveObjects(Obj); 70 | end 71 | 72 | disp(' |- DONE'); 73 | end -------------------------------------------------------------------------------- /deleteNetwork.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function deleteNetwork(UID) 21 | %% Remove saved training matching the passed unique identifier string UID 22 | NetFolder = [userpath filesep 'ObjectFinder' filesep 'NeuralNets']; 23 | 24 | if exist([NetFolder filesep UID '.mat'],'file') 25 | delete([NetFolder filesep UID '.mat']); 26 | end 27 | end -------------------------------------------------------------------------------- /distDotsToCellBody.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function[Dots] = distDotsToCellBody(Dots, Skel, Settings) 20 | %% This program calculate the position of the center of cell body as mean of 21 | % all voxels assigned as a cell body region in Amira (assigned as 2). 22 | % Then, calculate distance from this cell body center to individual dots. 23 | 24 | % New version will assume the center of cell body as a starting point of 25 | % marching during Imaris filament skeletonization whose location is stored 26 | % in Skel.FilStats.SomaPtXYZ. HO 1/10/2010 27 | 28 | %Find cell body 29 | xyum = Settings.ImInfo.xyum; 30 | zum = Settings.ImInfo.zum; 31 | CBpos = [ceil(Skel.FilStats.SomaPtXYZ(2)/xyum) ceil(Skel.FilStats.SomaPtXYZ(1)/xyum) ceil(Skel.FilStats.SomaPtXYZ(3)/zum)]; 32 | Dots.Settings.ImInfo.CBpos = CBpos; 33 | 34 | CBpos = Dots.Settings.ImInfo.CBpos; 35 | CBpos(1:2) = CBpos(1:2)*xyum; CBpos(3)=CBpos(3)*zum; 36 | Dpos = Dots.Pos; Dpos(:,1:2)=Dpos(:,1:2)*xyum; Dpos(:,3)=Dpos(:,3)*zum; 37 | 38 | Dots.Skel.Dist2CB = dist(Dpos,CBpos); 39 | end 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /distDotsToSkel.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function Dots = distDotsToSkel(Dots, Skel, Settings) 20 | SkelYXZ = [Skel.FilStats.aXYZ(:,2), Skel.FilStats.aXYZ(:,1), Skel.FilStats.aXYZ(:,3)]; 21 | 22 | xyum = Settings.ImInfo.xyum; 23 | zum = Settings.ImInfo.zum; 24 | DotPosYXZ = [Dots.Pos(:,1)*xyum, Dots.Pos(:,2)*xyum, Dots.Pos(:,3)*zum]; 25 | minDot2SkelDist = zeros(1, Dots.Num); 26 | minDot2SkelIDs = zeros(1, Dots.Num); 27 | 28 | for i = 1:Dots.Num 29 | Dist = dist2(SkelYXZ,DotPosYXZ(i,:)); 30 | [minDot2SkelDist(i), minDot2SkelIDs(i)] = min(Dist); 31 | end 32 | 33 | Dots.Skel.ClosestSkelIDs = minDot2SkelIDs; 34 | Dots.Skel.ClosestSkelDist = minDot2SkelDist; 35 | end 36 | 37 | function[d]=dist2(A,B) 38 | %finds distance between two vectors in form A (n,3,n) and B (1,3) 39 | A2 = zeros(size(A,1),3,size(A,3)); 40 | B2 = zeros(size(B,1),3); 41 | A2(:,1:size(A,2),:) = A; 42 | B2(:,1:size(B,2)) = B; 43 | A = A2; 44 | B = B2; 45 | d = sqrt((A(:,1,:)-B(1)).^2 + (A(:,2,:)-B(2)).^2 + (A(:,3,:)-B(3)).^2); 46 | end -------------------------------------------------------------------------------- /docs/images/MATLAB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/MATLAB.png -------------------------------------------------------------------------------- /docs/images/Screenshot_GUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_GUI.png -------------------------------------------------------------------------------- /docs/images/Screenshot_ImageSelection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_ImageSelection.png -------------------------------------------------------------------------------- /docs/images/Screenshot_MatlabApps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_MatlabApps.png -------------------------------------------------------------------------------- /docs/images/Screenshot_NeuralNet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_NeuralNet.png -------------------------------------------------------------------------------- /docs/images/Screenshot_colocalization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_colocalization.png -------------------------------------------------------------------------------- /docs/images/Screenshot_excel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_excel.png -------------------------------------------------------------------------------- /docs/images/Screenshot_folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_folder.png -------------------------------------------------------------------------------- /docs/images/Screenshot_heatmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_heatmap.png -------------------------------------------------------------------------------- /docs/images/Screenshot_imaris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_imaris.png -------------------------------------------------------------------------------- /docs/images/Screenshot_inspector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_inspector.png -------------------------------------------------------------------------------- /docs/images/Screenshot_timer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_timer.png -------------------------------------------------------------------------------- /docs/images/Screenshot_toolbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/Screenshot_toolbar.png -------------------------------------------------------------------------------- /docs/images/app_icon_big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/app_icon_big.png -------------------------------------------------------------------------------- /docs/images/blacktocat.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 11 | 12 | 18 | 19 | 20 | 24 | 25 | 26 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /docs/images/bug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/bug.png -------------------------------------------------------------------------------- /docs/images/download.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 9 | 11 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /docs/images/linux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/linux.png -------------------------------------------------------------------------------- /docs/images/mac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/mac.png -------------------------------------------------------------------------------- /docs/images/mac.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | image/svg+xml 44 | 49 | 51 | 55 | 59 | 64 | -------------------------------------------------------------------------------- /docs/images/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/question.png -------------------------------------------------------------------------------- /docs/images/sourcecode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/sourcecode.png -------------------------------------------------------------------------------- /docs/images/speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/speed.png -------------------------------------------------------------------------------- /docs/images/windows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/images/windows.png -------------------------------------------------------------------------------- /docs/images/windows.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | image/svg+xml 44 | 49 | 51 | 55 | 59 | 64 | -------------------------------------------------------------------------------- /docs/stylesheets/pygment_trac.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #f0f3f3; } 3 | .highlight .c { color: #0099FF; font-style: italic } /* Comment */ 4 | .highlight .err { color: #AA0000; background-color: #FFAAAA } /* Error */ 5 | .highlight .k { color: #006699; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #555555 } /* Operator */ 7 | .highlight .cm { color: #0099FF; font-style: italic } /* Comment.Multiline */ 8 | .highlight .cp { color: #009999 } /* Comment.Preproc */ 9 | .highlight .c1 { color: #0099FF; font-style: italic } /* Comment.Single */ 10 | .highlight .cs { color: #0099FF; font-weight: bold; font-style: italic } /* Comment.Special */ 11 | .highlight .gd { background-color: #FFCCCC; border: 1px solid #CC0000 } /* Generic.Deleted */ 12 | .highlight .ge { font-style: italic } /* Generic.Emph */ 13 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 14 | .highlight .gh { color: #003300; font-weight: bold } /* Generic.Heading */ 15 | .highlight .gi { background-color: #CCFFCC; border: 1px solid #00CC00 } /* Generic.Inserted */ 16 | .highlight .go { color: #AAAAAA } /* Generic.Output */ 17 | .highlight .gp { color: #000099; font-weight: bold } /* Generic.Prompt */ 18 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 19 | .highlight .gu { color: #003300; font-weight: bold } /* Generic.Subheading */ 20 | .highlight .gt { color: #99CC66 } /* Generic.Traceback */ 21 | .highlight .kc { color: #006699; font-weight: bold } /* Keyword.Constant */ 22 | .highlight .kd { color: #006699; font-weight: bold } /* Keyword.Declaration */ 23 | .highlight .kn { color: #006699; font-weight: bold } /* Keyword.Namespace */ 24 | .highlight .kp { color: #006699 } /* Keyword.Pseudo */ 25 | .highlight .kr { color: #006699; font-weight: bold } /* Keyword.Reserved */ 26 | .highlight .kt { color: #007788; font-weight: bold } /* Keyword.Type */ 27 | .highlight .m { color: #FF6600 } /* Literal.Number */ 28 | .highlight .s { color: #CC3300 } /* Literal.String */ 29 | .highlight .na { color: #330099 } /* Name.Attribute */ 30 | .highlight .nb { color: #336666 } /* Name.Builtin */ 31 | .highlight .nc { color: #00AA88; font-weight: bold } /* Name.Class */ 32 | .highlight .no { color: #336600 } /* Name.Constant */ 33 | .highlight .nd { color: #9999FF } /* Name.Decorator */ 34 | .highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */ 35 | .highlight .ne { color: #CC0000; font-weight: bold } /* Name.Exception */ 36 | .highlight .nf { color: #CC00FF } /* Name.Function */ 37 | .highlight .nl { color: #9999FF } /* Name.Label */ 38 | .highlight .nn { color: #00CCFF; font-weight: bold } /* Name.Namespace */ 39 | .highlight .nt { color: #330099; font-weight: bold } /* Name.Tag */ 40 | .highlight .nv { color: #003333 } /* Name.Variable */ 41 | .highlight .ow { color: #000000; font-weight: bold } /* Operator.Word */ 42 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 43 | .highlight .mf { color: #FF6600 } /* Literal.Number.Float */ 44 | .highlight .mh { color: #FF6600 } /* Literal.Number.Hex */ 45 | .highlight .mi { color: #FF6600 } /* Literal.Number.Integer */ 46 | .highlight .mo { color: #FF6600 } /* Literal.Number.Oct */ 47 | .highlight .sb { color: #CC3300 } /* Literal.String.Backtick */ 48 | .highlight .sc { color: #CC3300 } /* Literal.String.Char */ 49 | .highlight .sd { color: #CC3300; font-style: italic } /* Literal.String.Doc */ 50 | .highlight .s2 { color: #CC3300 } /* Literal.String.Double */ 51 | .highlight .se { color: #CC3300; font-weight: bold } /* Literal.String.Escape */ 52 | .highlight .sh { color: #CC3300 } /* Literal.String.Heredoc */ 53 | .highlight .si { color: #AA0000 } /* Literal.String.Interpol */ 54 | .highlight .sx { color: #CC3300 } /* Literal.String.Other */ 55 | .highlight .sr { color: #33AAAA } /* Literal.String.Regex */ 56 | .highlight .s1 { color: #CC3300 } /* Literal.String.Single */ 57 | .highlight .ss { color: #FFCC33 } /* Literal.String.Symbol */ 58 | .highlight .bp { color: #336666 } /* Name.Builtin.Pseudo */ 59 | .highlight .vc { color: #003333 } /* Name.Variable.Class */ 60 | .highlight .vg { color: #003333 } /* Name.Variable.Global */ 61 | .highlight .vi { color: #003333 } /* Name.Variable.Instance */ 62 | .highlight .il { color: #FF6600 } /* Literal.Number.Integer.Long */ 63 | 64 | .type-csharp .highlight .k { color: #0000FF } 65 | .type-csharp .highlight .kt { color: #0000FF } 66 | .type-csharp .highlight .nf { color: #000000; font-weight: normal } 67 | .type-csharp .highlight .nc { color: #2B91AF } 68 | .type-csharp .highlight .nn { color: #000000 } 69 | .type-csharp .highlight .s { color: #A31515 } 70 | .type-csharp .highlight .sc { color: #A31515 } 71 | -------------------------------------------------------------------------------- /docs/wiki_images/GUI_about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_about.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_automate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_automate.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_colocalize_mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_colocalize_mask.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_colocalize_objects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_colocalize_objects.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_detect _tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_detect _tools.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_detect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_detect.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_detect_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_detect_settings.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_detect_validation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_detect_validation.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_neuralnet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_neuralnet.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_new_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_new_project.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_report.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_report.png -------------------------------------------------------------------------------- /docs/wiki_images/GUI_simulate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/GUI_simulate.png -------------------------------------------------------------------------------- /docs/wiki_images/Installation_install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/Installation_install.png -------------------------------------------------------------------------------- /docs/wiki_images/Installation_update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/Installation_update.png -------------------------------------------------------------------------------- /docs/wiki_images/Installation_version.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucadellasantina/ObjectFinder/8e28f4128f6c318b419c02e9bfc4e7e1932de67e/docs/wiki_images/Installation_version.png -------------------------------------------------------------------------------- /editStruct.m: -------------------------------------------------------------------------------- 1 | %% Clarinet: Electrophysiology time series analysis 2 | % Copyright (C) 2018-2024 Luca Della Santina 3 | % 4 | % This file is part of Clarinet 5 | % 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % This software is released under the terms of the GPL v3 software license 19 | % 20 | 21 | function structOut = editStruct(structIn, title, prompt) 22 | %% Edit structure using a dynamically generated GUII 23 | % Enter the Structure first. optionally enter title, and then prompts 24 | % Data type (num or string) should be preserved 25 | 26 | fnames = fieldnames(structIn); 27 | if nargin < 3 28 | prompt = fnames; 29 | end 30 | if nargin < 2 31 | title = 'Settings'; 32 | end 33 | 34 | nLines = 1; 35 | for i = 1:length(fnames) 36 | var = structIn.(fnames{i}); 37 | if ischar(var) 38 | notstr(i) = 0; 39 | gVars{i} = var; 40 | else 41 | gVars{i} = num2str(var); 42 | notstr(i) = 1; 43 | end 44 | end 45 | 46 | gVars = inputdlg(prompt,title,nLines,gVars); 47 | if numel(gVars) == 0 48 | structOut = []; 49 | return 50 | else 51 | 52 | pause(0.1); 53 | 54 | structOut = struct; 55 | for i = 1:length(fnames) 56 | if notstr(i) 57 | structOut.(fnames{i}) = str2double(gVars{i}); 58 | else 59 | structOut.(fnames{i}) = gVars{i}; 60 | end 61 | end 62 | end -------------------------------------------------------------------------------- /findObjectsUIDfromName.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | % *Retrieve Objects UID from their name looking into the /Objects folder* 20 | 21 | function UID = findObjectsUIDfromName(ObjName) 22 | UID = []; 23 | 24 | files = dir('objects'); % List the content of /Objects folder 25 | files = files(~[files.isdir]); % Keep only files, discard subfolders 26 | 27 | for d = 1:numel(files) 28 | load([pwd filesep 'objects' filesep files(d).name],'Name'); 29 | if strcmp(Name, ObjName) 30 | [~, UID, ~] = fileparts(files(d).name); 31 | return; 32 | end 33 | end 34 | end -------------------------------------------------------------------------------- /fitSphere.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function Dots = fitSphere(Dots, Settings) 20 | %% Find mean number of faces for perfect reference sphere 21 | % changed from 11*11*11 to 31*31*31 because I do 0.025um xy 0.2um z for the 22 | % finest image of CtBP2 puncta (so 24 times more possible dot volume 23 | % compared to 0.103um xy 0.3um z) 6/25/2010 24 | 25 | tic; 26 | fprintf('Calculating sphericity of each object ... '); 27 | 28 | % Calculate shape properties for each object 29 | for i = 1:Dots.Num 30 | % Step-1: Calculate reference distances of each dot along longest axes 31 | Zscaling= Settings.ImInfo.zum / Settings.ImInfo.xyum; 32 | Cent = Dots.Pos(i,:); % Position of the dot's center 33 | Vox = Dots.Vox(i).Pos; % Position of each voxel of this dot 34 | Dist = dist2(Vox,Cent,Zscaling); % Distance of each voxel from center 35 | MeanD = max(1,mean(Dist)); % Average distance from center 36 | VoxN = Vox/MeanD; % Distance of each voxel from center 37 | 38 | if size(Vox,1) < 4 39 | % If volume < 4 voxels, PCA cannot calculate 3 variance components 40 | 41 | Dots.Shape.Var(i,:) = [0;0;0]; % Variance (voxel distance) along three PCA axes 42 | Dots.Shape.SumVar(i) = 0; % Sum of distances along the three main axis 43 | Dots.Shape.Oblong(i) = 0; % Ratio of variances between 2nd longest and longest axes, =1 if perfectly round, <1 if not round 44 | else 45 | [~, ~, latent] = pca(VoxN); % PCA analysis on normalized distances 46 | Dots.Shape.Var(i,:) = latent; % Longest distance from center along the three axis 47 | Dots.Shape.SumVar(i) = sum(latent); % Sum of distances along three axis 48 | Dots.Shape.Oblong(i) = mean([latent(2)/latent(1), latent(3)/latent(1)]); % Average longest distance on the 2nd and 3rd longest axis compared to the longest distance == 1 if perfectly spherical or cubic 49 | end 50 | end 51 | 52 | % Calculate 3D principal axis length of the fitting ellipsoid to objects 53 | Dots.Shape.PrincipalAxisLen = zeros(size(Dots.Pos)); 54 | for i= 1:Dots.Num 55 | VoxPos = Dots.Vox(i).Pos; 56 | 57 | % Move the coordinates origin of current object voxels back to (1,1,1) 58 | VoxPosYMin = min(VoxPos(:,1)); 59 | VoxPosYMax = max(VoxPos(:,1)); 60 | VoxPosXMin = min(VoxPos(:,2)); 61 | VoxPosXMax = max(VoxPos(:,2)); 62 | VoxPosZMin = min(VoxPos(:,3)); 63 | VoxPosZMax = max(VoxPos(:,3)); 64 | 65 | VoxPos(:,1) = VoxPos(:,1) - VoxPosYMin +1; 66 | VoxPos(:,2) = VoxPos(:,2) - VoxPosXMin +1; 67 | VoxPos(:,3) = VoxPos(:,3) - VoxPosZMin +1; 68 | 69 | VoxPosYMax = VoxPosYMax - VoxPosYMin +1; 70 | VoxPosXMax = VoxPosXMax - VoxPosXMin +1; 71 | VoxPosZMax = VoxPosZMax - VoxPosZMin +1; 72 | 73 | % Create a binary mask of current object 74 | Iobject = zeros(VoxPosYMax, VoxPosXMax, VoxPosZMax, 'logical'); 75 | for j = 1:size(VoxPos, 1) 76 | Iobject(VoxPos(j,1), VoxPos(j,2), VoxPos(j,3)) = 1; 77 | end 78 | 79 | PrincipalAxisLength = table2array(regionprops3(Iobject, 'PrincipalAxisLength')); 80 | Dots.Shape.PrincipalAxisLen(i,:) = PrincipalAxisLength(1,:); 81 | end 82 | fprintf(['DONE in ' num2str(toc) ' seconds \n']); 83 | end 84 | 85 | function[d] = dist2(A, B, Zscaling) 86 | % Finds distance between two vectors in form A (n,3,n) and B (1,3) 87 | % 88 | % Zscaling: multiplication factor if Z resolution different than XY 89 | % Zscaling =1 if same XYZ resolution 90 | % Zscaling = 2 if Z voxel size = twice XY voxels size 91 | 92 | A2 = zeros(size(A,1),3,size(A,3)); 93 | B2 = zeros(size(B,1),3); 94 | A2(:,1:size(A,2),:) = A; 95 | B2(:,1:size(B,2)) = B; 96 | A = A2; 97 | B = B2; 98 | d = sqrt((A(:,1,:)-B(1)).^2 + (A(:,2,:)-B(2)).^2 + ((A(:,3,:)-B(3)) * Zscaling).^2); 99 | end -------------------------------------------------------------------------------- /generateUID.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function UID = generateUID 21 | % Generate an unique identifier using Java's UUID generator 22 | tmp = java.util.UUID.randomUUID; 23 | tmpStr = tmp.toString; 24 | UID = tmpStr.toCharArray'; 25 | end -------------------------------------------------------------------------------- /getFilteredObjects.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function[Passing] = getFilteredObjects(Objects, Filter) 20 | 21 | % Ensure that filter is a binary mask 22 | Filter.passF = logical(Filter.passF); 23 | 24 | Passing.UID = Objects.UID; 25 | Passing.Name = Objects.Name; 26 | if isfield(Objects, 'ImSize') 27 | Passing.ImSize = Objects.ImSize; 28 | end 29 | Passing.Settings = Objects.Settings; 30 | Passing.Pos = Objects.Pos(Filter.passF, :); 31 | Passing.Vox = Objects.Vox(Filter.passF); 32 | Passing.Vol = Objects.Vol(Filter.passF); 33 | Passing.ITMax = Objects.ITMax(Filter.passF); 34 | Passing.ItSum = Objects.ItSum(Filter.passF); 35 | Passing.MeanBright = Objects.MeanBright(Filter.passF); 36 | Passing.Density = Objects.Density; 37 | Passing.NN = Objects.NN; 38 | Passing.Coloc = Objects.Coloc; 39 | Passing.Skel = Objects.Skel; 40 | Passing.Shape = Objects.Shape; 41 | 42 | if isfield(Objects.Shape,'Oblong') 43 | Passing.Shape.Oblong = Objects.Shape.Oblong(Filter.passF); 44 | end 45 | if isfield(Objects.Shape,'PrincipalAxisLen') 46 | Passing.Shape.PrincipalAxisLen = Objects.Shape.PrincipalAxisLen(Filter.passF,:); 47 | end 48 | if isfield(Objects.Skel,'Dist2CB') 49 | Passing.Skel.Dist2CB = Objects.Skel.Dist2CB(Filter.passF,:); 50 | end 51 | if isfield(Objects.Skel,'ClosestSkelIDs') 52 | Passing.Skel.ClosestSkelIDs = Objects.Skel.ClosestSkelIDs(Filter.passF); 53 | end 54 | if isfield(Objects.Skel,'ClosestSkelDist') 55 | Passing.Skel.ClosestSkelDist = Objects.Skel.ClosestSkelDist(Filter.passF); 56 | end 57 | 58 | Passing.Filter = Filter; 59 | Passing.Filter.passF = ones(numel(find(Filter.passF)),1); 60 | Passing.Num = numel(Passing.Filter.passF); 61 | 62 | end -------------------------------------------------------------------------------- /inpolygon_fast.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | %% Wrapper to use inpoly2 with the same syntax as MATLAB's inpolygon 21 | % https://github.com/dengwirda/inpoly 22 | function in = inpolygon_fast(x,y,xv,yv,varargin) 23 | 24 | in = reshape(inpoly2([x(:) y(:)],[xv(:) yv(:)],varargin{:}),size(x)); 25 | end -------------------------------------------------------------------------------- /listImages.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function SortedImgNames = listImages(folder) 21 | %% List available object names and UIDs 22 | switch nargin 23 | case 0, folder = pwd; 24 | end 25 | 26 | files = dir([folder filesep 'I' filesep '*.tif']); % List TIF images in ./I folder 27 | ImgNames = []; 28 | for f = numel(files):-1:1 29 | ImgNames{f} = files(f).name; 30 | end 31 | 32 | if isempty(ImgNames) 33 | SortedImgNames = []; 34 | else 35 | SortedImgNames = sort(ImgNames); 36 | end 37 | end -------------------------------------------------------------------------------- /listNetwork.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function tblN = listNetwork 21 | %% List available object names and UIDs 22 | NetFolder = [userpath filesep 'ObjectFinder' filesep 'NeuralNets']; 23 | files = dir([NetFolder filesep '*.mat']); 24 | 25 | tblN = repmat(table({'Empty'}, {'Empty'}, {'Empty'}, {'Empty'}, false, {'Empty'}),numel(files),1); 26 | for d = 1:numel(files) 27 | N = load([NetFolder filesep files(d).name], 'Name', 'Target', 'Type', 'Model', 'Trained', 'UID'); 28 | tblN(d,:) = table({N.Name}, {N.Target}, {N.Type}, {N.Model}, N.Trained, {N.UID}); 29 | end 30 | 31 | tblN = sortrows(tblN,1); % Sort table by neural net name 32 | end -------------------------------------------------------------------------------- /listObjects.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function [SortedObjNames, SortedObjUIDs] = listObjects(folder) 21 | %% List available object names and UIDs 22 | switch nargin 23 | case 0, folder = pwd; 24 | end 25 | 26 | ObjNames = {}; 27 | ObjUIDs = {}; 28 | 29 | files = dir([folder filesep 'objects' filesep '*.mat']); 30 | for d = 1:numel(files) 31 | load([folder filesep 'objects' filesep files(d).name],'Name', 'UID'); 32 | if isempty(ObjNames) 33 | ObjNames = {Name}; 34 | ObjUIDs = {UID}; 35 | else 36 | ObjNames{end+1} = Name; %#ok 37 | ObjUIDs{end+1} = UID; %#ok 38 | end 39 | end 40 | 41 | [SortedObjNames, idx] = sort(ObjNames); 42 | SortedObjUIDs = ObjUIDs(idx); 43 | end -------------------------------------------------------------------------------- /listPresets.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function [SortedNames, SortedUIDs] = listPresets(folder) 21 | %% List available skeleton names and UIDs 22 | switch nargin 23 | case 0, folder = [userpath filesep 'ObjectFinder' filesep 'Presets']; 24 | end 25 | 26 | Names = {}; 27 | UIDs = {}; 28 | 29 | files = dir(folder); % List the content of /Objects folder 30 | files = files(~[files.isdir]); % Keep only files, discard subfolders 31 | for f = 1:numel(files) 32 | load([folder filesep files(f).name], 'Name', 'UID'); 33 | if isempty(Names) 34 | Names = {Name}; 35 | UIDs = {UID}; 36 | else 37 | Names{end+1} = Name; %#ok 38 | UIDs{end+1} = UID; %#ok 39 | end 40 | end 41 | 42 | [SortedNames, idx] = sort(Names); 43 | SortedUIDs = UIDs(idx); 44 | end -------------------------------------------------------------------------------- /listSimulations.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function [SortedSimNames, SortedSimUIDs] = listSimulations(folder) 21 | %% List available simulations 22 | switch nargin 23 | case 0, folder = pwd; 24 | end 25 | SimNames = {}; 26 | SimUIDs = {}; 27 | 28 | files = dir([folder filesep 'simulations' filesep '*.mat']); 29 | for f = 1:numel(files) 30 | load([pwd filesep 'simulations' filesep files(f).name],'Name', 'UID'); 31 | if isempty(SimNames) 32 | SimNames = {Name}; 33 | SimUIDs = {UID}; 34 | else 35 | SimNames{end+1} = Name; %#ok 36 | SimUIDs{end+1} = UID; %#ok 37 | end 38 | end 39 | 40 | [SortedSimNames, idx] = sort(SimNames); 41 | SortedSimUIDs = SimUIDs(idx); 42 | end -------------------------------------------------------------------------------- /listSkels.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function [SortedSkelNames, SortedSkelUIDs] = listSkels(folder) 21 | %% List available skeleton names and UIDs 22 | switch nargin 23 | case 0, folder = pwd; 24 | end 25 | 26 | SkelNames = {}; 27 | SkelUIDs = {}; 28 | 29 | files = dir([folder filesep 'skeletons' filesep '*.mat']); 30 | for f = 1:numel(files) 31 | load([folder filesep 'skeletons' filesep files(f).name],'Name', 'UID'); 32 | 33 | if isnumeric(Name) 34 | % Matlab names cannot start with a number 35 | Name = ['Filament ' num2str(Name)]; 36 | elseif isa(Name, 'java.lang.String') 37 | % Convert to string if name is a Java char array 38 | Name = Name.toCharArray'; 39 | end 40 | 41 | if isempty(SkelNames) 42 | SkelNames = {Name}; 43 | SkelUIDs = {UID}; 44 | else 45 | SkelNames{end+1} = Name; %#ok 46 | SkelUIDs{end+1} = UID; %#ok 47 | end 48 | end 49 | 50 | [SortedSkelNames, idx] = sort(SkelNames); 51 | SortedSkelUIDs = SkelUIDs(idx); 52 | end -------------------------------------------------------------------------------- /loadImage.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function [Image, ImInfo, MIP, ImRes] = loadImage(FileName) 21 | %% 22 | PathName = [pwd filesep 'I' filesep]; 23 | if ~isempty(FileName) 24 | fileInfo = dir([PathName FileName]); 25 | if isempty(fileInfo) 26 | return 27 | end 28 | 29 | if fileInfo.bytes > 4e+9 30 | % Image file is bigger than 4Gb using custom imread function 31 | ImInfo = imfinfo([PathName FileName]); 32 | Image = uint8(imread_big([PathName FileName])); 33 | else 34 | ImInfo = imfinfo([PathName FileName]); 35 | % Image = zeros(ImInfo(1).Height, ImInfo(1).Width, length(ImInfo)); 36 | % for j = 1:length(ImInfo) 37 | % Image(:,:,j)=imread([PathName FileName], j); 38 | % end 39 | Image = tiffreadVolume([PathName FileName]); 40 | Image = uint8(Image); 41 | end 42 | 43 | % Retrieve image calibration from TIF file descriptor 44 | try 45 | tmpXYres = num2str(1/ImInfo(1).XResolution); 46 | if contains(ImInfo(1).ImageDescription, 'spacing=') 47 | tmpPos = strfind(ImInfo(1).ImageDescription,'spacing='); 48 | tmpZres = ImInfo(1).ImageDescription(tmpPos+8:end); 49 | tmpZres = regexp(tmpZres,'\n','split'); 50 | tmpZres = tmpZres{1}; 51 | else 52 | tmpZres = '1'; % for 2D images which have no spacing field default is 1 in ImageJ 53 | end 54 | catch 55 | tmpXYres = '1'; % default values 56 | tmpZres = '1'; % default values 57 | end 58 | ImRes = [str2double(tmpXYres), str2double(tmpXYres), str2double(tmpZres)]; 59 | 60 | % Compute maximum intensity projection 61 | MIP = squeeze(max(Image,[],3)); % Create a MIP of each image to display 62 | end 63 | end 64 | 65 | function stack_out = imread_big(stack_name) 66 | % Get data block size 67 | ImInfo = imfinfo(stack_name); 68 | stripOffset = ImInfo(1).StripOffsets; 69 | stripByteCounts = ImInfo(1).StripByteCounts; 70 | 71 | % Get image size 72 | sz_x = ImInfo(1).Width; 73 | sz_y = ImInfo(1).Height; 74 | if length(ImInfo)<2 75 | Nframes=floor(ImInfo(1).FileSize/stripByteCounts); 76 | else 77 | Nframes=length(ImInfo); 78 | end 79 | 80 | fID = fopen (stack_name, 'r'); 81 | 82 | if ImInfo(1).BitDepth==16 83 | stack_out = zeros([sz_y sz_x Nframes],'uint16'); 84 | else 85 | stack_out = zeros([sz_y sz_x Nframes],'uint8'); 86 | end 87 | 88 | start_point = stripOffset(1) + (0:1:(Nframes-1)).*stripByteCounts; 89 | 90 | for i = 1:Nframes 91 | %fprintf ('loading image ... %d\n', i); 92 | fseek (fID, start_point(i)+1, 'bof'); 93 | 94 | if ImInfo(1).BitDepth==16 95 | A = fread (fID, [sz_x sz_y], 'uint16=>uint16'); 96 | else 97 | A = fread (fID, [sz_x sz_y], 'uint8=>uint8'); 98 | end 99 | 100 | stack_out(:,:,i) = A'; 101 | end 102 | end -------------------------------------------------------------------------------- /loadNetwork.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function Net = loadNetwork(RequestedUID, FieldNames) 21 | %% Load objects matching ObjName 22 | NetFolder = [userpath filesep 'ObjectFinder' filesep 'NeuralNets']; 23 | 24 | if nargin <2 25 | FieldNames = {}; 26 | end 27 | 28 | files = dir(NetFolder); % List the content of /Objects folder 29 | files = files(~[files.isdir]); % Keep only files, discard subfolders 30 | 31 | for d = 1:numel(files) 32 | [~, fName, ~] = fileparts(files(d).name); 33 | if strcmp(fName, RequestedUID) 34 | if isempty(FieldNames) 35 | Net = load([NetFolder filesep files(d).name]); 36 | else 37 | Net = load([NetFolder filesep files(d).name], FieldNames{:}); 38 | end 39 | return; 40 | end 41 | end 42 | end -------------------------------------------------------------------------------- /loadObjects.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function Objs = loadObjects(UID, FieldNames) 21 | %% Load objects matching ObjName 22 | if nargin <2 23 | FieldNames = {}; 24 | end 25 | 26 | folder = [pwd filesep 'objects']; 27 | files = dir([folder filesep '*.mat']); 28 | for d = 1:numel(files) 29 | [~, fName, ~] = fileparts(files(d).name); 30 | if strcmp(fName, UID) 31 | if isempty(FieldNames) 32 | Objs = load([folder filesep files(d).name]); 33 | else 34 | Objs = load([folder filesep files(d).name], FieldNames{:}); 35 | end 36 | return; 37 | end 38 | end 39 | end -------------------------------------------------------------------------------- /loadPreset.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function Preset = loadPreset(UID, FieldNames) 21 | %% Load objects matching ObjName 22 | if nargin <2 23 | FieldNames = {}; 24 | end 25 | 26 | Preset = []; 27 | folder = [userpath filesep 'ObjectFinder' filesep 'Presets']; 28 | files = dir([folder filesep '*.mat']); % List the content of /Objects folder 29 | for d = 1:numel(files) 30 | [~, fName, ~] = fileparts(files(d).name); 31 | if strcmp(fName, UID) 32 | if isempty(FieldNames) 33 | Preset = load([folder filesep files(d).name]); 34 | else 35 | Preset = load([folder filesep files(d).name], FieldNames{:}); 36 | end 37 | break; 38 | end 39 | end 40 | end -------------------------------------------------------------------------------- /loadSettings.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function Settings = loadSettings(FieldNames) 21 | %% Load objects matching ObjName 22 | if nargin < 1 23 | FieldNames = {}; 24 | end 25 | 26 | Settings = []; 27 | if ~exist([pwd filesep 'Settings.mat'],'file') 28 | return 29 | end 30 | 31 | if isempty(FieldNames) 32 | Settings = load([pwd filesep 'Settings.mat']); 33 | if isfield(Settings, 'Settings') 34 | Settings = Settings.Settings; 35 | end 36 | else 37 | Settings = load([pwd filesep 'Settings.mat'], FieldNames{:}); 38 | end 39 | 40 | end -------------------------------------------------------------------------------- /loadSimulation.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function Sim = loadSimulation(UID, FieldNames) 21 | %% Load simulation matching UID 22 | if nargin <2 23 | FieldNames = {}; 24 | end 25 | 26 | if isempty(FieldNames) 27 | Sim = load([pwd filesep 'simulations' filesep UID '.mat']); 28 | else 29 | Sim = load([pwd filesep 'simulations' filesep UID '.mat'], FieldNames{:}); 30 | end 31 | end -------------------------------------------------------------------------------- /loadSkel.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function Skel = loadSkel(UID, FieldNames) 21 | %% Load objects matching ObjName 22 | if nargin <2 23 | FieldNames = {}; 24 | end 25 | 26 | Skel = []; 27 | files = dir([pwd filesep 'skeletons' filesep '*.mat']); % List the content of /Objects folder 28 | for d = 1:numel(files) 29 | [~, fName, ~] = fileparts(files(d).name); 30 | if strcmp(fName, UID) 31 | if isempty(FieldNames) 32 | Skel = load([pwd filesep 'skeletons' filesep files(d).name]); 33 | else 34 | Skel = load([pwd filesep 'skeletons' filesep files(d).name], FieldNames{:}); 35 | end 36 | break; 37 | end 38 | end 39 | 40 | if ~isempty(Skel) && ~isfield(Skel, 'branches') 41 | 42 | if isa(Skel.Name, 'java.lang.String') 43 | % Convert to string if name is a Java char array 44 | Skel.Name = Skel.Name.toCharArray'; 45 | end 46 | 47 | Skel.XYZ = Skel.FilStats.aXYZ; 48 | Skel.SomaPtID = Skel.FilStats.SomaPtID+1; 49 | Skel.FilStats.aEdges = Skel.FilStats.aEdges - Skel.FilStats.aEdges(1,1) + 1; % shift index edges so that first element starts with 1 50 | 51 | % March edges to find matching pairs and recreate the branching pattern 52 | % For each branch first the march from cell body is computed, 53 | % then all points in common with previously calculated branches are removed 54 | % this leaves 1 segment per branch without any duplicates 55 | 56 | vNumberOfSpots = length(Skel.FilStats.aRad); % Store total number of points we need to iterate 57 | % Find position of terminal and biforcation points in the filament connectivity (aEdges) 58 | vNumberOfTerminals = 0; 59 | vTerminals = []; 60 | vNumberOfForks = 0; 61 | vForks = []; 62 | % Start investigating all spots except root (start from position #2 to exclude root) 63 | for vSpots = 2 : vNumberOfSpots 64 | vEdge = find(Skel.FilStats.aEdges == vSpots); 65 | % if current edge is a terminal point of the skeleton, it should be listed once 66 | if length(vEdge) == 1 67 | % disp('found a terminal point'); 68 | vNumberOfTerminals = vNumberOfTerminals + 1; 69 | vTerminals(vNumberOfTerminals) = vSpots; %#ok 70 | elseif length(vEdge) > 2 71 | % disp('found a fork point'); 72 | vNumberOfForks = vNumberOfForks + 1; 73 | vForks(vNumberOfForks) = vSpots; %#ok 74 | end 75 | end 76 | 77 | % March backwards from each terminal point to the root in orher to find entire branch path 78 | vPaths=[]; % keeps an ongoing list of points already assigned to a branch 79 | for vTerminalIndex = 1:vNumberOfTerminals 80 | vLength = 1; 81 | vTerminal = vTerminals(vTerminalIndex); % start from terminal point 82 | vPath = vTerminal; % add the terminal point to current path 83 | 84 | vFound = true; 85 | while vFound 86 | % find among edges which one is connect to current terminal 87 | % vEdge contains the number to wich vTerminal is connected 88 | % vSide contains which side of the edge is vTerminal in this connection 89 | [vEdge, vSide] = find(Skel.FilStats.aEdges == vTerminal); 90 | 91 | vFound = false; 92 | for vNeighborIndex = 1:length(vEdge) 93 | % looks like is marching both directions here 94 | vNeighbor = Skel.FilStats.aEdges(vEdge(vNeighborIndex), 3-vSide(vNeighborIndex)); 95 | if vNeighbor < vTerminal 96 | vNewTerminal = vNeighbor; 97 | vFound = true; 98 | end 99 | end 100 | if vFound 101 | vLength = vLength + 1; 102 | vTerminal = vNewTerminal; 103 | vPath(vLength) = vTerminal; 104 | end 105 | end 106 | 107 | vPath = fliplr(vPath); % Flip path so that is not going terminal->root but root->terminal instead 108 | vPath = setdiff(vPath, vPaths); % Remove common part with the paths previously calculated 109 | vPaths = cat(2,vPaths, vPath); % Add current path to paths 110 | 111 | Skel.branches(vTerminalIndex).points = Skel.FilStats.aXYZ(vPath,:); 112 | Skel.branches(vTerminalIndex).Rad = Skel.FilStats.aRad(vPath); 113 | %Skel.branches(vTerminalIndex).Edges = [1:vLength-1;2:vLength]'; 114 | Skel.TotalBranches = numel(Skel.branches); 115 | end 116 | end 117 | end -------------------------------------------------------------------------------- /saveNetwork.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function saveNetwork(Net, FieldName) 21 | %% Save a variable into a .mat file efficiently depending on its size 22 | NetFolder = [userpath filesep 'ObjectFinder' filesep 'NeuralNets']; 23 | if nargin == 1 24 | % If no FieldName then save all field of Training on file 25 | FieldName = []; 26 | end 27 | 28 | if ~exist(NetFolder,'dir') 29 | mkdir(NetFolder); 30 | end 31 | 32 | if ~isfield(Net, 'UID') 33 | Net.UID = generateUID; 34 | end 35 | FileName = [NetFolder filesep Net.UID '.mat']; 36 | 37 | if isempty(FieldName) 38 | % Save struct on file with fields split tino separate variables 39 | save(FileName, '-struct', 'Net', '-v7.3', '-nocompression'); 40 | else 41 | % Save only a specific FieldName on disk 42 | save(FileName, '-struct', 'Net', FieldName,'-append'); 43 | end 44 | end -------------------------------------------------------------------------------- /saveObjects.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | 21 | function saveObjects(Dots, FieldName) 22 | %% Save a variable into a .mat file efficiently depending on its size 23 | if nargin == 1 24 | % If no FieldName then save all field of Dots on file 25 | FieldName = []; 26 | end 27 | 28 | if ~isfield(Dots, 'UID'), Dots.UID = generateUID; end 29 | 30 | folder = [pwd filesep 'objects']; 31 | FileName = [folder filesep Dots.UID '.mat']; 32 | if ~isfolder(folder), mkdir(folder); end 33 | 34 | lastwarn('') % Clear last warning message 35 | 36 | if isempty(FieldName) 37 | % Save struct on file with fields split tino separate variables 38 | save(FileName, '-struct', 'Dots', '-v7'); 39 | [warnMsg, ~] = lastwarn; 40 | if ~isempty(warnMsg) 41 | disp('Objects are bigger than 2Gb, will be saved using larger file format, be patient...') 42 | save(FileName, '-struct', 'Dots', '-v7.3', '-nocompression'); 43 | end 44 | else 45 | % Save only a specific FieldName on disk 46 | save(FileName, '-struct', 'Dots', FieldName,'-append'); 47 | [warnMsg, ~] = lastwarn; 48 | if ~isempty(warnMsg) 49 | disp('Objects are bigger than 2Gb, will be saved using larger file format, be patient...') 50 | save(FileName, '-struct', 'Dots', FieldName, '-append'); 51 | end 52 | end 53 | end -------------------------------------------------------------------------------- /savePreset.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function savePreset(Preset, FieldName) 21 | %% Save a variable into a .mat file efficiently depending on its size 22 | 23 | if nargin == 1 24 | % If no FieldName then save all field of Dots on file 25 | FieldName = []; 26 | end 27 | 28 | if ~isfield(Preset, 'UID'), Preset.UID = generateUID; end 29 | if ~isfield(Preset, 'Name'), Preset.Name = 'MySettings'; end 30 | 31 | folder = [userpath filesep 'ObjectFinder' filesep 'Presets']; 32 | FileName = [folder filesep Preset.UID '.mat']; 33 | if ~isfolder(folder), mkdir(folder); end 34 | 35 | if isempty(FieldName) 36 | % Save struct on file with fields split tino separate variables 37 | save(FileName, '-struct', 'Preset'); 38 | else 39 | % Save only a specific FieldName on disk 40 | save(FileName, '-struct', 'Preset', FieldName,'-append'); 41 | end 42 | end -------------------------------------------------------------------------------- /saveSettings.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | 21 | function saveSettings(Settings, FieldName) 22 | %% Save a variable into a .mat file 23 | 24 | if nargin == 1 25 | % If no FieldName then save all field of Dots on file 26 | FieldName = []; 27 | end 28 | 29 | FileName = [pwd filesep 'Settings.mat']; 30 | 31 | lastwarn('') % Clear last warning message 32 | 33 | if isempty(FieldName) 34 | % Save struct on file with fields split tino separate variables 35 | save(FileName, '-struct', 'Settings'); 36 | else 37 | % Save only a specific FieldName on disk 38 | save(FileName, '-struct', 'Settings', FieldName,'-append'); 39 | end 40 | end -------------------------------------------------------------------------------- /saveSimulation.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | 21 | function saveSimulation(Sim, FieldName) 22 | %% Save a variable into a .mat file efficiently depending on its size 23 | 24 | if nargin == 1 25 | % If no FieldName then save all field of Sim on file 26 | FieldName = []; 27 | end 28 | 29 | if ~isfield(Sim, 'UID') 30 | Sim.UID = generateUID; 31 | end 32 | FileName = [pwd filesep 'simulations' filesep Sim.UID '.mat']; 33 | 34 | lastwarn('') % Clear last warning message 35 | 36 | if isempty(FieldName) 37 | % Save struct on file with fields split tino separate variables 38 | save(FileName, '-struct', 'Sim', '-v7'); 39 | [warnMsg, ~] = lastwarn; 40 | if ~isempty(warnMsg) 41 | disp('Simulation is bigger than 2Gb, will be saved using larger file format, be patient...') 42 | save(FileName, '-struct', 'Sim', '-v7.3', '-nocompression'); 43 | end 44 | else 45 | % Save only a specific FieldName on disk 46 | save(FileName, '-struct', 'Sim', FieldName,'-append'); 47 | [warnMsg, ~] = lastwarn; 48 | if ~isempty(warnMsg) 49 | disp('Simulation is bigger than 2Gb, will be saved using larger file format, be patient...') 50 | save(FileName, '-struct', 'Sim', FieldName, '-append'); 51 | end 52 | end 53 | end -------------------------------------------------------------------------------- /saveSkel.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | 20 | function saveSkel(Skel, FieldName) 21 | %% Save a variable into a .mat file efficiently depending on its size 22 | 23 | if nargin == 1 24 | % If no FieldName then save all field of Dots on file 25 | FieldName = []; 26 | end 27 | 28 | if ~isfield(Skel, 'UID'), Skel.UID = generateUID; end 29 | if ~isfield(Skel, 'Name'), Skel.Name = 'Skeleton'; end 30 | 31 | folder = [pwd filesep 'skeletons']; 32 | FileName = [folder filesep Skel.UID '.mat']; 33 | if ~isfolder(folder), mkdir(folder); end 34 | 35 | if isempty(FieldName) 36 | % Save struct on file with fields split tino separate variables 37 | save(FileName, '-struct', 'Skel'); 38 | else 39 | % Save only a specific FieldName on disk 40 | save(FileName, '-struct', 'Skel', FieldName,'-append'); 41 | end 42 | end -------------------------------------------------------------------------------- /skeletonizeMask.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function [SkelOld, SkelNew] = skeletonizeMask(MaskChName) 20 | %% Read Mask Image and find soma position 21 | FileName = [pwd filesep 'I' filesep MaskChName]; 22 | 23 | % Read the image size and resolution from file 24 | tmpImInfo = imfinfo(FileName); 25 | tmpImSizeZ = numel(tmpImInfo); 26 | tmpImSizeX = tmpImInfo.Width; 27 | tmpImSizeY = tmpImInfo.Height; 28 | 29 | % Read image resolution data 30 | try 31 | tmpXYres = 1/tmpImInfo(1).XResolution; 32 | if contains(tmpImInfo(1).ImageDescription, 'spacing=') 33 | tmpPos = strfind(tmpImInfo(1).ImageDescription,'spacing='); 34 | tmpZres = tmpImInfo(1).ImageDescription(tmpPos+8:end); 35 | tmpZres = regexp(tmpZres,'\n','split'); 36 | tmpZres = str2double(tmpZres{1}); 37 | else 38 | tmpZres = 0.3; % otherwise use default value 39 | end 40 | ImRes = [tmpXYres, tmpXYres, tmpZres]; 41 | catch 42 | ImRes = [1,1,1]; 43 | end 44 | 45 | 46 | % Load the image data into matlab 47 | fprintf('Loading image stack... '); 48 | I = uint8(ones(tmpImSizeX, tmpImSizeY, tmpImSizeZ)); 49 | for j = 1:tmpImSizeZ 50 | I(:,:,j)=imread(FileName, j); 51 | end 52 | mask = I==1; 53 | fprintf('DONE\n'); 54 | 55 | S.xyum = ImRes(1); 56 | S.zum = ImRes(3); 57 | %S.radius = 52; 58 | S = editStruct(S); 59 | 60 | SkelNew.calib.x = S.xyum; 61 | SkelNew.calib.y = S.xyum; 62 | SkelNew.calib.z = S.zum; 63 | SkelNew.imgsize.width = size(mask(2)); 64 | SkelNew.imgsize.height = size(mask(1)); 65 | SkelNew.imgsize.depth = size(mask(3)); 66 | 67 | fprintf('Searching soma... '); 68 | AreaMax = 0; 69 | AreaMaxPos = [1 1 1]; 70 | AreaMaxRad = 0; 71 | for z = 1:size(mask,3) 72 | RP = regionprops(mask(:,:,z),'Area', 'Centroid', 'MajorAxisLength'); 73 | if max([RP.Area]) > AreaMax 74 | AreaMax = max([RP.Area]); 75 | AreaMaxPos = [RP([RP.Area]==AreaMax).Centroid(2), RP([RP.Area]==AreaMax).Centroid(1), z]; 76 | AreaMaxRad = RP([RP.Area]==AreaMax).MajorAxisLength; 77 | end 78 | end 79 | SomaPos = AreaMaxPos; 80 | SomaRad = AreaMaxRad; 81 | fprintf('DONE\n'); 82 | clear z r Area* 83 | 84 | fprintf('Skeletonizing...'); 85 | skel = bwskel(mask, 'MinBranchLength', 0); 86 | [~,nodes,link] = Skel2Graph3D(skel, 0); 87 | fprintf('DONE\n'); 88 | 89 | %% Convert to old Skel format (segment means position and length) 90 | fprintf('Converting skeleton file format...'); 91 | Seg = []; 92 | nSeg = 0; 93 | Lengths = []; 94 | 95 | % Reconstruct segment connectivity into a list, 2 points at a time 96 | for l=1:numel(link) 97 | for point = 1 : numel(link(l).point) 98 | [x, y, z] = ind2sub(size(mask), link(l).point(point)); 99 | SkelNew.branches(l).points(point,:) = [y,x,z,y*S.xyum,x*S.xyum,z*S.zum,0]; 100 | SkelOld.branches(l).XYZ(point,:) = [y*S.xyum,x*S.xyum,z*S.zum]; 101 | end 102 | 103 | nSegStart = max(1,nSeg); 104 | for point = 2 : numel(link(l).point) 105 | nSeg = nSeg + 1; 106 | [x1, y1, z1] = ind2sub(size(mask), link(l).point(point-1)); 107 | Seg(nSeg, :, 1) = [y1, x1, z1]; 108 | [x2, y2, z2] = ind2sub(size(mask), link(l).point(point)); 109 | Seg(nSeg, :, 2) = [y2, x2, z2]; 110 | end 111 | 112 | % Calculate branch length in calibrated units 113 | SkelNew.branches(l).length = ... 114 | sum(sqrt( ((Seg(nSegStart:end,1,1)-Seg(nSegStart:end,1,2))*S.xyum).^2 +... 115 | ((Seg(nSegStart:end,2,1)-Seg(nSegStart:end,2,2))*S.xyum).^2 +... 116 | ((Seg(nSegStart:end,3,1)-Seg(nSegStart:end,3,2))*S.zum).^2)); 117 | 118 | end 119 | Lengths= sqrt( (Seg(:,1,1)-Seg(:,1,2)).^2 +... 120 | (Seg(:,2,1)-Seg(:,2,2)).^2 +... 121 | (Seg(:,3,1)-Seg(:,3,2)).^2); 122 | 123 | % Total dendritic length 124 | tmpTotalLen = 0; 125 | for i = 1:numel(SkelNew.branches) 126 | tmpBranch = SkelNew.branches(i); 127 | tmpTotalLen = tmpTotalLen + tmpBranch.length; 128 | end 129 | SkelNew.totalLength = tmpTotalLen; 130 | 131 | SkelOld.SegStats.Seg = single(Seg); 132 | SkelOld.SegStats.Lengths = single(Lengths); 133 | 134 | % Reconstruct filament connectivity, 1 point at a time 135 | aXYZ = []; 136 | aRad = []; 137 | aEdges = []; 138 | nPoint = 0; 139 | nSeg = 0; 140 | 141 | % TODO in order to reconstruct aEdges, we need to take into account the 142 | % idParent otherwise IDs continue to grow indefinitely 143 | for l=1:numel(link) 144 | for point = 1 : numel(link(l).point) 145 | nPoint = nPoint + 1; 146 | [x, y, z] = ind2sub(size(mask), link(l).point(point)); 147 | aXYZ(nPoint, :) = [y, x, z]; 148 | aRad(nPoint, :) = 0; 149 | if point >=1 150 | nSeg = nSeg + 1; 151 | aEdges(nSeg, 1) = nPoint -1; 152 | aEdges(nSeg, 2) = nPoint; 153 | end 154 | end 155 | end 156 | SkelOld.FilStats.aXYZ = single(aXYZ); 157 | SkelOld.FilStats.aRad = single(aRad'); 158 | SkelOld.FilStats.aEdges = uint32(aEdges); 159 | SkelOld.FilStats.SomaPtID = 0; 160 | SkelOld.FilStats.SomaPtXYZ = [SomaPos(2)*S.xyum, SomaPos(1)*S.xyum, SomaPos(3)*S.zum]; 161 | SkelOld.FilStats.SomaPtRad = SomaRad; 162 | fprintf('DONE\n'); 163 | 164 | end 165 | -------------------------------------------------------------------------------- /validateObjectWithNeuralNet.m: -------------------------------------------------------------------------------- 1 | %% ObjectFinder - Recognize 3D structures in image stacks 2 | % Copyright (C) 2016-2024 Luca Della Santina 3 | % 4 | % This file is part of ObjectFinder 5 | % 6 | % ObjectFinder is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License as published by 8 | % the Free Software Foundation, either version 3 of the License, or 9 | % (at your option) any later version. 10 | % 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | % 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | % 19 | function Filter = validateObjectWithNeuralNet(Dots, NeuralNet, Confidence) 20 | %% Classify objects using neural network (outcome == 'Object' or 'Noise') 21 | tic; 22 | sz = NeuralNet.Layers.Layers(1).InputSize; 23 | Filter = Dots.Filter; 24 | 25 | disp(['Validating objects using ' NeuralNet.Name]); 26 | for i = 1:length(Dots.Vox) 27 | % Reconstruct the image of current object from raw brightness values 28 | minPt = min(Dots.Vox(i).Pos(:,1:3)); 29 | maxPt = max(Dots.Vox(i).Pos(:,1:3)); 30 | imMat = zeros(maxPt-minPt+1, 'uint8'); 31 | for j=1:size(Dots.Vox(i).Pos, 1) 32 | pt = Dots.Vox(i).Pos(j,:) - minPt + 1; 33 | imMat(pt(1),pt(2),pt(3)) = Dots.Vox(i).RawBright(j); 34 | end 35 | 36 | % Treat differently 2D vs 3D images 37 | if size(imMat, 3) == 1 38 | % 2D image: Resize image and encode as RGB 39 | x = imresize(imMat, [sz(1) sz(2)]); 40 | I = cat(3,x,x,x); 41 | else 42 | % 3D image: Create MIPs along cardinal axes, resize and combine into RGB 43 | z = imresize(squeeze(max(imMat,[],3)), [sz(1) sz(2)]); 44 | y = imresize(squeeze(max(imMat,[],1)), [sz(1) sz(2)]); 45 | x = imresize(squeeze(max(imMat,[],2)), [sz(1) sz(2)]); 46 | I = cat(3,z,y,x); 47 | end 48 | 49 | % Classify using pretrained neural network 50 | %Filter.passF(i) = (classify(NeuralNet.Net, I) == 'Object'); 51 | [~, P] = classify(NeuralNet.Net, I); 52 | Filter.passF(i) = (P(2) >= Confidence); 53 | end 54 | disp(['Done in ' num2str(toc) ' seconds, valid objects: ' num2str(numel(find(Filter.passF))) ' / ' num2str(numel(Filter.passF))]); 55 | end --------------------------------------------------------------------------------