12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- function [MGwanted,MGvolume,res]=PreProMainStack(load_main,Animal,Cell,m,range,int,loadMainStack)
- info = imfinfo(strcat(load_main,Animal,'\',Cell,'\',loadMainStack,'.tif'));
- MGstack = zeros(info(1).Width,info(1).Height, range(2) - range (1)+1);
- count=0;
- for r=range(1):range(2)
- count=count+1;
- mg = imread(strcat(load_main,Animal,'\',Cell,'\',loadMainStack,'.tif'), r, 'Info', info);
- background = imopen(mg, strel('disk',50));
- mg = mg - background;
- MGstack(:,:,count) = mg;
- clear mg
- end
- [~, BWmg] = hysteresis3d(MGstack, 0.1, 0.5, 26); % thresholds the microglia image with lower threshold 0.1 and upper threshold 0.5 and segments it with connectivity of 26, only returns the hysteresis images (~negates first output)
- clear MGstack
- [MGstack] = ordfilt3D(BWmg,14); % filters the BW microglia stack for 26 neighbours
- clear BWmg
- [MGstack_label, MGnum] = bwlabeln (MGstack);% labels parts of one distinct microglia with one number
- size_mg = sum(MGstack_label(:)== 1:MGnum); % sums up pixels with the same number (so pixels of each microglial part or microglia)
- [MGvolume, idx] = max(size_mg);% returns the volume and the index of the highest pixel volume
- if m==2
- size_mg(1,idx)=0;
- clear idx MGvolume
- [MGvolume, idx] = max(size_mg);
- elseif m==3
- size_mg(1,idx)=0;
- clear idx MGvolume
- [MGvolume, idx] = max(size_mg);
- size_mg(1,idx)=0;
- clear idx MGvolume
- [MGvolume, idx] = max(size_mg);
- end
- MGwanted = (MGstack_label == idx);% makes stack from the original microglia stack but with only the desired microglia displayed as logical one (so only it is shown)
- res.pixel_width_um = info(1).Width./info(1).XResolution;% enter your pixel width in um (get from info in .tif)
- res.pixel_height_um = info(1).Height./info(1).YResolution; % enter your pixel heigth in um
- res.pixel_depth_um = int; % enter the step size (slice thickness) in um
- MGvolume = MGvolume* (res.pixel_width_um*res.pixel_height_um*res.pixel_depth_um);% calculates the volume in um of the microglia from the volume in pixels
-
-
-
-
|