diff --git a/inPhase_Segmentation_v11.m b/inPhase_Segmentation_v11.m index c21701bb869f7223f0efeea8c98df7edbfc6eadc..b0c2f26a84134e44cec142efaa74c5aabdf38aab 100644 --- a/inPhase_Segmentation_v11.m +++ b/inPhase_Segmentation_v11.m @@ -1,7 +1,7 @@ %% inPhase segemntation routine % It assumes pairs of BF images and fluorescent maximum projections in .tif format % These pairs should have the same name with "BF" and "Max" as labels. -% these pairs are supposed to have the used temperature in the name of the file (_xxC_) +% These pairs are supposed to have the used temperature in the name of the file (_xxC_) % Example: % BF_proteinName_20C % Max_proteinName_20C @@ -13,7 +13,7 @@ filesTiff = dir([pathi '/**/*.tif']); folderExp = unique({filesTiff.folder}); % Save images of segmentation for all individual emulsion droplets -saveImage = true; +saveImage = false; % Experimental setup related constants pixelSize = 0.1625; @@ -300,7 +300,18 @@ for k = 1 : length(folderExp) currImageCropBF = imgaussfilt(currImageCropBF, 3); currImageCropBF2 = imgradient(currImageCropBF); currImageCropBF2(~emulsionMask) = mean(currImageCropBF2(emulsionMask)); - [centerBF, radiusBF, metricBF] = imfindcircles(imadjust(currImageCropBF2), [10, round(size(currImageCropBF2, 1)/5)], 'Sensitivity', 0.6, 'ObjectPolarity', 'dark'); + [centerBF, radiusBF, ~] = imfindcircles(imadjust(currImageCropBF2), [10, round(size(currImageCropBF2, 1)/5)], 'Sensitivity', 0.6, 'ObjectPolarity', 'dark'); + % remove misdetection of bright spots + if ~isempty(centerBF) + currImageCropBF_Mask = createCirclesMask(size(currImageCropBF), centerBF, radiusBF); + currImageCropBF_Mask = regionprops(currImageCropBF_Mask, currImageCropBF, 'MeanIntensity', 'Centroid'); + currImageCropBF_Int = vertcat(currImageCropBF_Mask.MeanIntensity); + currImageCropBF_Centroid = vertcat(currImageCropBF_Mask.Centroid); + currIndx = currImageCropBF_Int <= mean(currImageCropBF(emulsionMask)); + currIndx = sum(abs(centerBF - currImageCropBF_Centroid(currIndx, :)),2) <= 2; + centerBF = centerBF(currIndx, :); + radiusBF = radiusBF(currIndx); + end if saveImage hf1 = figure('visible', 'off'); imshow(currImageCropBF) @@ -370,5 +381,4 @@ for k = 1 : length(folderExp) % save Output data as .mat save([currFolderExp{1}, filesep, 'ResultsNew.mat'], 'Results') -end - +end \ No newline at end of file