Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- eclear,clc
- close all
- file=uigetfile('*.jpg');
- Image_Raw=imread(file);
- disp('Select Scale Length')
- imshow(Image_Raw)
- title('Select Scale Length (Pixel) 2 clicks')
- [X,Y]=ginputc(2,'Color','r');
- Pixel_Length=sqrt((Y(2)-Y(1))^2+(X(2)-X(1))^2);
- close all
- Actual_Length=input('Enter actual scale length (unit determines histogram x axis unit): ');
- response1=input('How many regions do you want to analyze? ');
- while ~(floor(response1)==response1)
- response1=input('Please only enter integers: ');
- end
- file2=input('What do you want to call your excel file?','s');
- %Image_Eq=histeq(Image_Raw);
- %figure
- %imshow(Image_Eq)
- level=0.7;
- major_t=[];
- minor_t=[];
- area_t=[];
- for i=1:response1
- disp('Select region of interest, then double click to finish')
- Image_Crop=imcrop(Image_Raw);
- close all
- Image_Bin=im2bw(Image_Crop,level);
- Image_Bin=imcomplement(Image_Bin);
- Image_Bin=imclearborder(Image_Bin);
- imshow(Image_Bin)
- fprintf('Current threshold is %.2f. n',level)
- response=input('Enter new threshold (0.1-0.9) or type 0 if done ');
- close all
- while ~(response==0)
- level=response;
- Image_Bin=im2bw(Image_Crop,level);
- Image_Bin=imcomplement(Image_Bin);
- Image_Bin=imclearborder(Image_Bin);
- imshow(Image_Bin)
- response=input('Enter new threshold (0.1-0.9) or type 0 if done ');
- close all
- end
- properties = regionprops(Image_Bin, {'Area','MajorAxisLength', 'MinorAxisLength'});
- properties_table = struct2table(properties);
- Major=properties_table.MajorAxisLength.*(Actual_Length/Pixel_Length);
- Minor=properties_table.MinorAxisLength.*(Actual_Length/Pixel_Length);
- Area=properties_table.Area.*(Actual_Length^2/Pixel_Length^2);
- major_t=[major_t Major'];
- minor_t=[minor_t Minor'];
- area_t=[area_t Area'];
- xlswrite([file2 '.xlsx'],{'Major Axis Length','Minor Axis Length','Area'},['Region' num2str(i)],'A1')
- xlswrite([file2 '.xlsx'],Major,['Region' num2str(i)],'A2')
- xlswrite([file2 '.xlsx'],Minor,['Region' num2str(i)],'B2')
- xlswrite([file2 '.xlsx'],Area,['Region' num2str(i)],'C2')
- end
- xlswrite([file2 '.xlsx'],{'Major Axis Length','Minor Axis Length','Area'},'Total','A1')
- xlswrite([file2 '.xlsx'],major_t./2','Total','A2')
- xlswrite([file2 '.xlsx'],minor_t./2','Total','B2')
- xlswrite([file2 '.xlsx'],area_t','Total','C2')
- histogram(major_t./2,'Normalization','probability','NumBins',round(length(major_t)^0.5))
- xlabel('Radius (unit)')
- ylabel('Probability')
- title('Edit Title')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement