diff --git a/process_results/parse_regenerating_fragments.m b/process_results/parse_regenerating_fragments.m index 55226a2..4a2adce 100644 --- a/process_results/parse_regenerating_fragments.m +++ b/process_results/parse_regenerating_fragments.m @@ -1,809 +1,809 @@ % PARSE_REGENERATING_FRAGMENT studies the properties of the vascular tissue during regeneration % % Blanchoud Group, UNIFR % Simon Blanchoud % 06/12/2021 function parse_regenerating_fragments(frag_indx) % load the required packages pkg load matgeom pkg load image pkg load statistics % Absolute path to the directory containing the segmentation files - %fdir = '/home/guest/data/Nathalie/Quantifications/*.roi'; - fdir = '/home/blanchou/Documents/Nathalie/Quantifications/*.roi'; + fdir = '/home/guest/data/Nathalie/Quantifications/*.roi'; + %fdir = '/home/blanchou/Documents/Nathalie/Quantifications/*.roi'; files = glob(fdir); nfiles = length(files); % Determine which data to show if nargin < 1 frag_indx = [1:nfiles]; else frag_indx = frag_indx(isfinite(frag_indx) & (frag_indx <= nfiles)); end % Structures to store the data all_tunic = cell(nfiles, 2, 1); all_ampullae = cell(nfiles, 2, 4); all_vessels = cell(nfiles, 2, 2); all_evals = cell(nfiles, 2, 4); all_quants = cell(nfiles, 2, 4); % Display? plot_segmentations = true; % Statistics nrepeats = 100; nothers = 5; disp('Parsing segmentations...') % Loop through all files for i=1:nfiles % Extract the parts of the filename [dir, name, ext] = fileparts (files{i}); filename = fullfile(dir, name); % Inform the user on the progress disp([num2str(i) ': ' name]); % The actual files imfile = [filename '.tif']; ijfile = [filename '.zip']; umfile = [filename '.txt']; tgfile = [filename '.roi']; % Extract the segmentations ROIs = ReadImageJROI(ijfile); [props, data] = analyze_ROI(ROIs, 'Slice', 'Area', 'Length', 'Centroid'); % Setup the various thresholds scale = csvread(umfile); tdist = (550/scale); rdist = ( 50/scale); pdist = ( 30/scale); vdist = ( 10/scale); % Measure the size of the dataset nframes = max(props(:,1)); ntracks = length(data); % Prepare some temporary variables start = props(:,1)0) l = sum((pts(indxs(end),:) - pts(indx,:)).^2); if l > sqthresh && sets(indxs(end))==sets(indx) p = grShortestPath(pts, edges, indxs(end), indx); p = p(:).'; indxs = [indxs(1:end-1), p(1:end-1)]; end end indxs(end+1) = indx; curr_indx = indx; end end indxs(end+1) = indxs(1); periph = pts(indxs([1:end 1]),:); %figure;plot(resampl(:,1), resampl(:,2), 'r'); %hold on; %scatter(pts(:,1), pts(:,2), 'k'); %plot([pts(edges(:,1),1) pts(edges(:,2),1)].', [pts(edges(:,1),2) pts(edges(:,2),2)].', 'k') %plot(periph(:,1), periph(:,2), 'm'); return; end % Mesh the vertices with a connectivity network function [edges, nneigh] = span_vertices(pts, thresh) tri = delaunay(pts); thresh2 = thresh*thresh; ntri = size(tri,1); props = NaN(ntri, 3); for i=1:ntri vertices = tri(i, [1:3 1]); pt1 = pts(vertices(1),:); pt2 = pts(vertices(2),:); pt3 = pts(vertices(3),:); area = triangleArea(pt1, pt2, pt3); side = sqrt(sum([pt1-pt2; pt2 - pt3; pt3 - pt1].^2, 2)); [l,imax] = max(side); peri = sum(side); props(i, 1) = peri/area; props(i, 2:3) = vertices(imax:imax+1); end tiny = (abs(props(:,1)) > 1); tri = tri(~tiny,:); edges = [tri(:,[1 2]); tri(:,[1 3]); tri(:,[2 3])]; [edges] = unique(edges, 'rows'); bads = ismember(edges, props(tiny,2:3), 'rows'); edges = edges(~bads,:); dist = bsxfun(@minus, pts(:,1), pts(:,1).').^2 + bsxfun(@minus, pts(:,2), pts(:,2).').^2; ind = sub2ind(size(dist), edges(:,1), edges(:,2)); edist = dist(ind); edges = edges(edist <= thresh2,:); nneigh = histc(edges(:),[1:size(pts,1)]); return end % Fuse close points function merged = merge_points(pts, thresh) merged = pts; if (size(pts, 1) < 2) return; end thresh = thresh*thresh; dist = bsxfun(@minus, pts(:,1), pts(:,1).').^2 + bsxfun(@minus, pts(:,2), pts(:,2).').^2; groups = {}; npts = size(pts,1); candidates = [1:npts]; for i=1:npts if isempty(candidates) break; end ncands = size(candidates, 1); cluster = false(ncands,1); cluster(1) = true; num = 1; for j=1:ncands d = dist(candidates(cluster), candidates); cluster = any(d