Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. eclear,clc
  2. close all
  3. file=uigetfile('*.jpg');
  4. Image_Raw=imread(file);
  5.  
  6. disp('Select Scale Length')
  7. imshow(Image_Raw)
  8. title('Select Scale Length (Pixel) 2 clicks')
  9. [X,Y]=ginputc(2,'Color','r');
  10. Pixel_Length=sqrt((Y(2)-Y(1))^2+(X(2)-X(1))^2);
  11. close all
  12. Actual_Length=input('Enter actual scale length (unit determines histogram x axis unit): ');
  13.  
  14.  
  15.  
  16. response1=input('How many regions do you want to analyze? ');
  17. while ~(floor(response1)==response1)
  18. response1=input('Please only enter integers: ');
  19. end
  20.  
  21. file2=input('What do you want to call your excel file?','s');
  22.  
  23. %Image_Eq=histeq(Image_Raw);
  24. %figure
  25. %imshow(Image_Eq)
  26. level=0.7;
  27. major_t=[];
  28. minor_t=[];
  29. area_t=[];
  30. for i=1:response1
  31.  
  32. disp('Select region of interest, then double click to finish')
  33. Image_Crop=imcrop(Image_Raw);
  34. close all
  35. Image_Bin=im2bw(Image_Crop,level);
  36. Image_Bin=imcomplement(Image_Bin);
  37. Image_Bin=imclearborder(Image_Bin);
  38. imshow(Image_Bin)
  39. fprintf('Current threshold is %.2f. n',level)
  40. response=input('Enter new threshold (0.1-0.9) or type 0 if done ');
  41. close all
  42. while ~(response==0)
  43. level=response;
  44. Image_Bin=im2bw(Image_Crop,level);
  45. Image_Bin=imcomplement(Image_Bin);
  46. Image_Bin=imclearborder(Image_Bin);
  47. imshow(Image_Bin)
  48. response=input('Enter new threshold (0.1-0.9) or type 0 if done ');
  49. close all
  50. end
  51.  
  52. properties = regionprops(Image_Bin, {'Area','MajorAxisLength', 'MinorAxisLength'});
  53.  
  54. properties_table = struct2table(properties);
  55. Major=properties_table.MajorAxisLength.*(Actual_Length/Pixel_Length);
  56. Minor=properties_table.MinorAxisLength.*(Actual_Length/Pixel_Length);
  57. Area=properties_table.Area.*(Actual_Length^2/Pixel_Length^2);
  58. major_t=[major_t Major'];
  59. minor_t=[minor_t Minor'];
  60. area_t=[area_t Area'];
  61. xlswrite([file2 '.xlsx'],{'Major Axis Length','Minor Axis Length','Area'},['Region' num2str(i)],'A1')
  62. xlswrite([file2 '.xlsx'],Major,['Region' num2str(i)],'A2')
  63. xlswrite([file2 '.xlsx'],Minor,['Region' num2str(i)],'B2')
  64. xlswrite([file2 '.xlsx'],Area,['Region' num2str(i)],'C2')
  65. end
  66. xlswrite([file2 '.xlsx'],{'Major Axis Length','Minor Axis Length','Area'},'Total','A1')
  67. xlswrite([file2 '.xlsx'],major_t./2','Total','A2')
  68. xlswrite([file2 '.xlsx'],minor_t./2','Total','B2')
  69. xlswrite([file2 '.xlsx'],area_t','Total','C2')
  70.  
  71. histogram(major_t./2,'Normalization','probability','NumBins',round(length(major_t)^0.5))
  72. xlabel('Radius (unit)')
  73. ylabel('Probability')
  74. title('Edit Title')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement