Permalink
Browse files

Added various unorganized matlab files to the repo.

  • Loading branch information...
0 parents commit 03308c4e0d160a051fce43e4ef7662c878c8c548 ajdecon committed Sep 22, 2010
Showing with 7,295 additions and 0 deletions.
  1. +646 −0 CircularHough_Grd.m
  2. +30 −0 DrawCircle.m
  3. +37 −0 HoughList.m
  4. +20 −0 HoughMovie.m
  5. +28 −0 HoughTracking.m
  6. +28 −0 HoughTracking2.m
  7. +177 −0 Watershed3D_Final.m
  8. +33 −0 assign_fields.m
  9. +32 −0 average_intensity.m
  10. +15 −0 avg_array.m
  11. +10 −0 avg_array_inc.m
  12. +21 −0 avg_frames.m
  13. +25 −0 bersen.m
  14. +33 −0 bondlengths.m
  15. +63 −0 bounded_array.m
  16. +56 −0 boxtracking.m
  17. +155 −0 bpass.m
  18. +82 −0 canny_edge.m
  19. +146 −0 cefit_4C.m
  20. +20 −0 cell2num.m
  21. +22 −0 centerpos.m
  22. +36 −0 check_dist.m
  23. +143 −0 cntrd.m
  24. +33 −0 compare_labels.m
  25. +34 −0 compare_stacks.m
  26. +34 −0 compare_stacks_labels.m
  27. +20 −0 connect_circles.m
  28. +55 −0 convert_tifs.m
  29. +67 −0 create_help_menu.m
  30. +16 −0 d2dgauss.m
  31. +35 −0 demo_thresh_box.m
  32. +12 −0 devices_volfrac.m
  33. +2 −0 dgauss.m
  34. +141 −0 dna_boxtracking.m
  35. +82 −0 dna_pairing.m
  36. +77 −0 dna_particle_tracking.m
  37. +82 −0 dpt2.m
  38. +25 −0 drawline.m
  39. +78 −0 dt_percent_threshold.m
  40. +163 −0 dumbbell_pos.m
  41. +22 −0 extract_circles_1img.m
  42. +24 −0 fast_tracking.m
  43. +27 −0 fixed_ints.m
  44. +3 −0 gauss.m
  45. +13 −0 gen_gauss_signal.m
  46. +129 −0 group_backbone.m
  47. +17 −0 histstack.m
  48. +48 −0 houghtrackmovie.m
  49. +22 −0 info2label.m
  50. +35 −0 intensity_at_points.m
  51. +32 −0 label_and_time_stamp.m
  52. +17 −0 lentrk.m
  53. +6 −0 loadrgbtiffstack.m
  54. +6 −0 loadtiffstack.m
  55. +25 −0 local_otsu.m
  56. +83 −0 local_percent_threshold.m
  57. +31 −0 local_threshold.m
  58. +91 −0 lpt3d.m
  59. +12 −0 makesplinederiv.m
  60. +96 −0 maketables.m
  61. +24 −0 mean_thresh.m
  62. +47 −0 meanplot.m
  63. +24 −0 median_thresh.m
  64. +28 −0 msd.m
  65. +163 −0 msd_a.m
  66. +180 −0 msd_d.m
  67. +12 −0 myfunc.m
  68. +40 −0 myview.m
  69. +22 −0 niblack.m
  70. +19 −0 norm_ratio.m
  71. +40 −0 orient_batch.m
  72. +47 −0 orient_corr.m
  73. +27 −0 parse_noran.m
  74. +9 −0 particle_averages.m
  75. +6 −0 particle_split.m
  76. +16 −0 perc_thresh.m
  77. +102 −0 pkfnd.m
  78. +44 −0 pretrack.m
  79. +45 −0 pretrack2.m
  80. +39 −0 random_particles.m
  81. +57 −0 read_gdf.m
  82. +41 −0 read_noran.m
  83. +85 −0 ring_section.m
  84. +26 −0 sauvola.m
  85. +31 −0 showmovie.m
  86. +195 −0 slice_view_2d.m
  87. +14 −0 slopes.m
  88. +19 −0 sortvtime.m
  89. +34 −0 stack_intensity.m
  90. +16 −0 stackmovie.m
  91. +15 −0 stackmovie_labels.m
  92. +9 −0 temp.m
  93. +22 −0 test.m
  94. +23 −0 test_function.m
  95. +23 −0 test_function2.m
  96. +23 −0 test_function3.m
  97. +1,112 −0 track.m
  98. +116 −0 track_intensities.m
  99. +29 −0 units2tex.m
  100. +38 −0 vector2str.m
  101. +200 −0 vol3d.m
  102. +136 −0 vol3dtool.m
  103. +225 −0 volume_browser.m
  104. +50 −0 watershed_pos.m
  105. +113 −0 watershed_tracking.m
  106. +77 −0 watertracking2.m
  107. +27 −0 welch_t_test.m
  108. +26 −0 x_section.m
  109. +26 −0 y_section.m
Oops, something went wrong.
@@ -0,0 +1,30 @@
+function DrawCircle(x, y, r, nseg, S)
+% Draw a circle on the current figure using ploylines
+%
+% DrawCircle(x, y, r, nseg, S)
+% A simple function for drawing a circle on graph.
+%
+% INPUT: (x, y, r, nseg, S)
+% x, y: Center of the circle
+% r: Radius of the circle
+% nseg: Number of segments for the circle
+% S: Colors, plot symbols and line types
+%
+% OUTPUT: None
+%
+% BUG REPORT:
+% Please send your bug reports, comments and suggestions to
+% pengtao@glue.umd.edu . Thanks.
+
+% Author: Tao Peng
+% Department of Mechanical Engineering
+% University of Maryland, College Park, Maryland 20742, USA
+% pengtao@glue.umd.edu
+% Version: alpha Revision: Jan. 10, 2006
+
+
+theta = 0 : (2 * pi / nseg) : (2 * pi);
+pline_x = r * cos(theta) + x;
+pline_y = r * sin(theta) + y;
+
+plot(pline_x, pline_y, S);
@@ -0,0 +1,37 @@
+function [poslist,cirrad]=HoughList(img,radrange,plot)
+
+
+ [accum,circen,cirrad]=CircularHough_Grd(img(:,:),radrange);
+
+ % First, remove duplicates.
+ k=0;
+ rem_ind = [];
+ for i=1:size(circen,1)
+ x0=circen(i,1);
+ y0=circen(i,2);
+ for j=i:size(circen,1)
+ x1=circen(j,1);
+ y1=circen(j,2);
+ dist=sqrt((x1-x0)^2 + (y1-y0)^2);
+ if ((dist<min(radrange)) && (i~=j))
+ k=k+1;
+ rem_ind(k)=j;
+ end
+ end
+ end
+ circen(rem_ind,:)=[];
+ cirrad(rem_ind)=[];
+
+ if (plot>0)
+ imagesc(img);
+ colormap('gray');axis image;hold on;
+ for k=1:size(circen,1),DrawCircle(circen(k,1),circen(k,2),cirrad(k),32,'b-');end;
+ for i=1:size(circen,1)
+ h=text(circen(i,1),circen(i,2),num2str(i));
+ set(h,'Color','g');
+ set(h,'FontWeight','bold');
+ end
+ hold off;
+ end
+
+poslist=circen;
@@ -0,0 +1,20 @@
+function poslist=HoughList(img,radrange)
+
+numim=size(img,3);
+
+for m=1:numim
+ [accum,circen,cirrad]=CircularHough_Grd(img(:,:,m),radrange);
+ imagesc(img(:,:,m));
+ colormap('gray');axis image;hold on;plot(circen(:,1),circen(:,2),'r+');
+ for k=1:size(circen,1),DrawCircle(circen(k,1),circen(k,2),cirrad(k),32,'b-');end;hold off;
+
+ for x=1:size(circen,1)
+ for y=1:size(circen,2)
+ cirarray(x,y,m)=circen(x,y);
+ end
+ end
+
+ pause(0.05);
+end
+
+poslist=cirarray;
@@ -0,0 +1,28 @@
+function [positions,tracklist]=HoughTracking(img,radrange,timerange,plot)
+
+interval=5;
+for t=timerange
+ img0=img(:,:,t);
+ poslist=HoughList(img0,radrange,plot);
+ pause(0.05);
+ for k=1:size(poslist,1)
+ for m=1:size(poslist,2)
+ positions(k,m,t)=poslist(k,m);
+ end
+ end
+ if (mod(t,interval)==0)
+ t
+ end
+end
+
+k=0;
+for i=1:size(positions,3)
+ for j=1:size(positions,1)
+ if (positions(j,1,i)~=0)
+ k=k+1;
+ tracklist(k,1)=positions(j,1,i);
+ tracklist(k,2)=positions(j,2,i);
+ tracklist(k,3)=i;
+ end
+ end
+end
@@ -0,0 +1,28 @@
+function [positions,tracklist]=HoughTracking2(img,radrange,timerange,plot)
+
+interval=5;
+for t=timerange
+ img0=img(:,:,t);
+ [poslist,cirrad]=HoughList(img0,radrange,plot);
+ pause(0.05);
+ for k=1:size(poslist,1)
+ for m=1:size(poslist,2)
+ positions(k,m,t)=poslist(k,m);
+ end
+ end
+ if (mod(t,interval)==0)
+ t
+ end
+end
+
+k=0;
+for i=1:size(positions,3)
+ for j=1:size(positions,1)
+ if (positions(j,1,i)~=0)
+ k=k+1;
+ tracklist(k,1)=positions(j,1,i);
+ tracklist(k,2)=positions(j,2,i);
+ tracklist(k,3)=i;
+ end
+ end
+end
@@ -0,0 +1,177 @@
+SKIZdepth=input('number of images in sequence: '); %61
+SKIZheight=input('height of images: '); %312
+SKIZwidth=input('width of images: '); %346
+THRESH=.2; %Threshold amount
+FudgeFactor=2;
+scrsz = get(0,'ScreenSize');
+stack=zeros([SKIZheight SKIZwidth SKIZdepth]);
+BWstack=zeros([SKIZheight SKIZwidth SKIZdepth]);
+
+
+
+for count=1:SKIZdepth
+ stack(:,:,count) = imread('BEADZ_INV.tif',count);%Probably not necessary
+ BWstack(:,:,count) = im2bw(stack(:,:,count),THRESH);
+end
+
+InvDst=bwdist(~BWstack);
+InvDst2=bwdist(BWstack);
+
+Dst=-InvDst;
+Dst(~BWstack) = -Inf;
+Wtr = watershed(Dst,26);
+WtrTrnsfrm = Wtr;
+
+%Find a way to automatically detect background pixellation!!!!!
+for w=1:SKIZwidth
+ for h=1:SKIZheight
+ for d=1:SKIZdepth
+ if Wtr(h,w,d)==FudgeFactor
+ WtrTrnsfrm(h,w,d)=0;
+ end
+ end
+ d=1;
+ end
+h=1;
+end
+
+
+%%
+%Makes Binary 3D matrix of Wtr, for Distance Transform
+%Then takes a distance transform of total 3D backgroun
+BWwtr=WtrTrnsfrm;
+
+figure('Position', [scrsz(4)/2 scrsz(3) scrsz(3)/2 scrsz(4)/2]),
+for d=1:SKIZdepth
+ imshow(label2rgb(uint8(WtrTrnsfrm(:,:,d)),'jet'));
+ pause(.1);
+end
+title ('Segmented Granules');
+
+figure,
+for d=1:SKIZdepth
+ BWwtr(:,:,d) = im2bw(WtrTrnsfrm(:,:,d));
+end
+
+BWwtrDst=bwdist(BWwtr); %used for background subtraction at end
+figure('Position', [scrsz(4)/2 scrsz(3) scrsz(3)/2 scrsz(4)/2]),
+imshow(label2rgb(uint8(BWwtr(:,:,d))))
+title ('Global Distance Transform')
+
+
+
+%%
+WtrSegment=WtrTrnsfrm;
+TotalGranules=max(max((max(Wtr))));
+
+GRANS=zeros([SKIZheight SKIZwidth SKIZdepth TotalGranules]);
+for Granule=1:TotalGranules
+%%
+%This will take only a single granule from the Watertransform, then make it
+%binary and take its distance transform, stored in GRANS
+for w=1:SKIZwidth
+ for h=1:SKIZheight
+ for d=1:SKIZdepth
+ if WtrTrnsfrm(h,w,d)==Granule
+ WtrSegment(h,w,d)=1;
+ end
+ if WtrTrnsfrm(h,w,d)~=Granule
+ WtrSegment(h,w,d)=0;
+ end
+ end
+ d=1;
+ end
+h=1;
+end
+%%
+GRANS(:,:,:,Granule)=bwdist(WtrSegment);
+end
+%% Subtracts individual distance transform from total distance transform
+Voronoi=GRANS;
+Voronoi2=GRANS;
+for i=1:TotalGranules
+ Voronoi(:,:,:,i) = GRANS(:,:,:,i) - BWwtrDst;
+ Voronoi2(:,:,:,i) = GRANS(:,:,:,i) - InvDst2;
+ Voronoi(:,:,:,i)=255-Voronoi(:,:,:,i) - InvDst*333;%makes lowest hill into highest hill, making granule center brightest
+ Voronoi2(:,:,:,i)=255-Voronoi2(:,:,:,i);
+ %Voronoi(:,:,:,i)=imextendedmax(Voronoi(:,:,:,i),26)*i;
+end
+
+figure('Position', [scrsz(4)/2 scrsz(1) scrsz(3)/2 scrsz(4)/2]),
+for k=1:SKIZdepth
+imshow(label2rgb((uint8(Voronoi(:,:,k,10))),'jet'))
+pause(.1);
+end
+title ('Local Void Region');
+PureVoronoi=zeros([SKIZheight SKIZwidth SKIZdepth]);
+
+maxVal = 0;
+for j=1:SKIZwidth %interrogates and eliminates non 250 pixels
+ for i=1:SKIZheight
+
+ for k=1:SKIZdepth
+ maxVal=0;
+ for count=1:TotalGranules
+ if Voronoi(i,j,k,count)> maxVal;
+ maxVal=Voronoi(i,j,k,count);
+ PureVoronoi(i,j,k)= count;
+ end
+ end
+
+ end
+ end
+end
+
+
+figure('Position', [scrsz(2)/2 scrsz(1) scrsz(3)/2 scrsz(4)/2]),
+for k=1:SKIZdepth
+imshow(label2rgb((uint8(PureVoronoi(:,:,k))),'jet'))
+pause(.1);
+end
+title ('Voronoi Void Region');
+
+%So far I have made the background transform, called BWwtrDst and labelled
+%each individual granules background and stored this transform in GRANS
+%which is a 4D array, where the last column is the granule ID from the
+%watershed transform at the beginning. Voronoi subtracts the Individual
+%granules background from the total background, determining the voronoi
+%map. To get the standard Vornoi volume, I need to find the pixels that are
+%closest (255) to the granule and eliminate everything else, then squeeze
+%into a 3D array from the 4D array and make an isosurface.
+%% Imaging in 3D the voronoi volumes
+image_num = 3;
+image(PureVoronoi(:,:,image_num));
+x=xlim;
+y=ylim;
+contourslice(PureVoronoi,[],[],image_num)
+axis ij
+xlim(x)
+ylim(y)
+daspect([1,1,1])
+colormap(jet)
+pause(1);
+%layered contour images
+phandles = contourslice(PureVoronoi,[],[],[1,2,3,4,5],8);
+view(3); axis tight
+set(phandles,'LineWidth',2)
+pause(1);
+%Isosurface
+Ls = smooth3(PureVoronoi);
+hiso = patch(isosurface(Ls,500),...
+ 'FaceColor',[1,.75,.65],...
+ 'EdgeColor','red');
+hcap = patch(isocaps(Ls,100),...
+ 'FaceColor','interp',...
+ 'EdgeColor','none');
+colormap(jet)
+view(45,30)
+axis tight
+
+daspect([1,1,.4])
+%better rendering
+lightangle(305,30);
+set(gcf,'Renderer','zbuffer'); lighting phong
+isonormals(Ls,hiso)
+set(hcap,'AmbientStrength',.6)
+set(hiso,'SpecularColorReflectance',0,'SpecularExponent',50)
+view(215,30);
@@ -0,0 +1,33 @@
+function param=assign_fields(param,newparam)
+% Copy fields from structure "newparam" to like-named fields of
+% structure "param"
+%
+% Written by: E. Rietsch: October 15, 2006
+% Last updated:
+%
+% param=assign_fields(param,newparam)
+% INPUT
+% param structure with fields representing default parameters
+% newparam structure with fields representing new parameters
+% OUTPUT
+% param input structure with updated fields
+
+% Check if the fields of newparam are a subset of those of "param"
+if isempty(newparam)
+ return
+end
+
+fields=fieldnames(param);
+newfields=fieldnames(newparam);
+bool=ismember(newfields,fields);
+if ~all(bool)
+ disp(' The following fieldes are probably misspelled:')
+ disp([' ',cell2str(newfields(~bool),',')])
+ disp(' Possible fields are:')
+ disp([' ',cell2str(fields,',')])
+ error('Abnormal termination')
+end
+
+for ii=1:length(newfields)
+ param.(newfields{ii})=newparam.(newfields{ii});
+end
@@ -0,0 +1,32 @@
+function result=average_intensity(img,mask,r)
+
+[x0,y0]=centerpos(mask);
+
+sizex=size(img,2);
+sizey=size(img,1);
+
+pxcount=0.0;
+intensity=0.0;
+
+for i=1:sizex
+ for j=1:sizey
+
+ distance=sqrt( (i-x0)^2 + (j-y0)^2 );
+ if (distance <= r)
+ pxcount = pxcount + 1;
+ end
+ end
+end
+
+for i=1:sizex
+ for j=1:sizey
+
+ distance=sqrt( (i-x0)^2 + (j-y0)^2 );
+ if (distance <= r)
+ intensity = intensity + img(j,i)/pxcount;
+ end
+ end
+end
+
+
+result = intensity;
Oops, something went wrong.

0 comments on commit 03308c4

Please sign in to comment.