%% Master file for segmenting gamma prime particles close all [fname, pathname] = uigetfile({'*.tif', 'image files (*.tif)'}, ... 'Select the original intensity *.tif image'); filename = [pathname fname]; scrsz = get(0,'ScreenSize'); clear pathname % filename is the original intensity image I = imread(filename); I = imcrop(I); close(1) filename = strrep(filename,'.tif','_crop.tif'); imwrite(I,filename,'tif') % Find previously segmented objects if exist(strrep(filename,'.tif','_auto1.tif')) == 2 J_master = imread(strrep(filename,'.tif','_auto1.tif')); else J_master = I == -1; end %% Detect seeds & Grow region % Crop the original area (or else it is really slow) I = imread(filename); I(:,1) = 255; I(:,end) = 255; I(1,:) = 255; I(end,:) = 255; clear I2 K4 = bwperim(J_master); I_tmp = I; I_tmp(K4) = 255; I2(:,:,1) = I_tmp; I_tmp = I; I_tmp(K4) = 0; I2(:,:,2) = I_tmp; I_tmp = I; I_tmp(K4) = 0; I2(:,:,3) = I_tmp; [I2 rect] = imcrop(I2); rect = round(rect); I = I(rect(2):rect(2)+rect(4)-1,rect(1):rect(1)+rect(3)-1); clear I2 I_tmp K4 close all % Select the points % Hit return to exit figure('Name','Select point(s) and hit return to exit','NumberTitle','off') imshow(I,[]); set(gcf,'Position',[1 1 scrsz(3) scrsz(4)]) [y1,x1] = ginput; x1 = round(x1); y1 = round(y1); close(1) % Grow region % What are the optimum parameters based on Tschopp et al MS&T (2010)? % Parameters get passed into the region growing algorithm parameters.fill_holes_flag = 0; parameters.fill_holes_mod = 100; parameters.output_flag = 1; parameters.output_mod = 200; parameters.min_size = 100; parameters.max_size = 10000000; parameters.whole_region = 0; parameters.boundary_layer = 15; parameters.image_growth_flag = 0; parameters.image_growth_file = 'image99.tif'; parameters.decreasing_max = 10; parameters.trace_boundary = 0; parameters.threshplot = 0; parameters.nhood_size = 5; %m parameters.nhood_median = 9; %c parameters.f_ceiling = 1; parameters.w1_reduce = 1; % The function that executes it all! tic [J,thresh_plot] = segment_particle_RegionGrow(I,x1,y1,parameters); K = J_master(rect(2):rect(2)+rect(4)-1,rect(1):rect(1)+rect(3)-1); K(J) = 1; J_master(rect(2):rect(2)+rect(4)-1,rect(1):rect(1)+rect(3)-1) = K; close all toc %% Save segmentation imwrite(J_master, strrep(filename,'.tif','_auto1.tif'),'tif') I = imread(filename); I(:,1) = 255; I(:,end) = 255; I(1,:) = 255; I(end,:) = 255; clear I2 K4 = bwperim(J_master); I_tmp = I; I_tmp(K4) = 255; I2(:,:,1) = I_tmp; I_tmp = I; I_tmp(K4) = 0; I2(:,:,2) = I_tmp; I_tmp = I; I_tmp(K4) = 0; I2(:,:,3) = I_tmp; imwrite(I2, strrep(filename,'.tif','_auto2.tif'),'tif') clear I2 I_tmp K4