% MATLAB R2019b % % This script reads a microscope image of hand-picked zircon mounts and % overlays contours generated by 'ImageProcess_Zr-contour-xy.py' from the % same image. The contours can be manually adjusted from the user. The new % contour is accepted by a double click and by typing 'n'(-Enter) or rejected by % typing 'y'(-Enter) into the command window. Then the next contour pops up a.s.o. % As an output a table with the area value of the contoured object is generated. % % USER INPUT: % Image - filename.png (line 25) % x|y coordinates of the contour vertices - filename.csv (line 28 and 29) % % Created: 12/08/2021 % Last Modified: 07/09/2021 % Author: Isabel Zutterkirch clc clear close all %% INPUT % image I= imread('filename.png'); % x- and y-coordinate of the contour vertices, which are generated by the % python script "ImageProcess_Zr-contour-xy.py" x= regexp(fileread('filename.csv'),'[\n\r]+','split'); y= regexp(fileread('filename.csv'),'[\n\r]+','split'); %% PROCESSING % iteration over contour vertices % to minimize the amount of vertices, set the number to only take the nth n=10; % tracking the iteration, area in the table will be 0 when the contour is % rejected, see if-statement j=0; % storage for the accepted polygons NewPoly=[]; % iteration for i= 1:1:length(x) strx = regexprep(x{1,i},',',' '); stry = regexprep(y{1,i},',',' '); xcoo= str2num(strx); ycoo= str2num(stry); % take nth element on list xcoo_modi= xcoo(1:n:end); ycoo_modi= ycoo(1:n:end); % create tuple and transpose pgon=[xcoo_modi;ycoo_modi]; pgon_transposed= pgon.'; % plot image and polygon imshow(I); h= drawpolygon('Position', pgon_transposed); xlim([min(xcoo_modi)-50 max(xcoo_modi)+50]) ylim([min(ycoo_modi)-20 max(ycoo_modi)+20]) % wait for user modification until user double clicks wait(h) % get new positions pos= h.Position(); % figure() new_polygon=polyshape(pos(:,1).', pos(:,2).'); plot(new_polygon) NewPoly= [NewPoly,new_polygon]; % tracking the iteration and adding the area value to the list 'A' j=j+1; prompt= 'Would you like to reject the contour? y/n (or s for stop): '; str= input(prompt,'s'); if str == 'n' A(j)= area(new_polygon); area(new_polygon) elseif str == 's' break elseif i== length(x) break else end end % transpose A a= A.'; %% OUTPUT % csv table with area values csvwrite('2123198_bw_Area.csv',a) % optional for checking save desired variables in a matrix %save ('2123198_Poly.mat','I','x','y','a','NewPoly')