Skip to content

Commit ebe7ec8

Browse files
committed
fixing typos and improving codes
1 parent f4000a8 commit ebe7ec8

File tree

3 files changed

+209
-1088
lines changed

3 files changed

+209
-1088
lines changed

Module2-ImageProcessing/M2A_Basic_Image_Processing.ipynb

+181-1,044
Large diffs are not rendered by default.

Module2-ImageProcessing/M2B_Segmenting_Images.ipynb

+12-15
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
" <left>Basic Image Manipulation in Python</left>\n",
1616
" </h1>\n",
1717
" <p><left>============================================================================</left> </p>\n",
18-
"<pre>Course: BIOM 421, Spring 2024\n",
19-
"Instructor: Brian Munsky\n",
20-
"Authors: Dr. Zach Fox, Dr. Luis Aguilera, Brian Munsky\n",
21-
"Contact Info: munsky@colostate.edu\n",
18+
"<pre>Course: UQ-Bio 2024\n",
19+
"Instructor: Luis Aguilera\n",
20+
"Authors: Luis Aguilera, Will Raymond, Brian Munsky\n",
21+
"Contact Info: luis.aguilera@colostate.edu\n",
2222
"</pre>\n",
2323
" </div>\n",
2424
" </p>\n",
@@ -200,7 +200,7 @@
200200
"metadata": {},
201201
"outputs": [],
202202
"source": [
203-
"# conda install pytorch\n",
203+
"# conda remove pytorch\n",
204204
"# conda install pytorch\n",
205205
"# pip uninstall cellpose\n",
206206
"# pip install cellpose\n"
@@ -253,9 +253,9 @@
253253
"metadata": {},
254254
"outputs": [],
255255
"source": [
256-
"#from biom421 import codes\n",
257-
"#students = codes.spring2024Students()\n",
258-
"students = ['name1', 'name'] #codes.spring2024Students()"
256+
"students = ['Daria', 'Wiktoria','Jinyi','Wei','Pilar','Camila','Jayden','Humberto',\n",
257+
"'Jakini','Varvara','Kanniese','Kristi','Eliud','Nam','Lakshay','Margaret',\n",
258+
"'Grace','Apurv','Yinfei','Samantha','Yingli','Rena','Emily','Pegah','Al-Bashir']"
259259
]
260260
},
261261
{
@@ -1356,8 +1356,8 @@
13561356
"outputs": [],
13571357
"source": [
13581358
"# Installing libraries\n",
1359-
"%pip install trackpy\n",
1360-
"import trackpy as tp # Library for particle tracking"
1359+
"#%pip install trackpy\n",
1360+
"#import trackpy as tp # Library for particle tracking"
13611361
]
13621362
},
13631363
{
@@ -1372,7 +1372,7 @@
13721372
"particle_size = 5 # according to the documentation must be an odd number 3,5,7,9 etc.\n",
13731373
"minimal_intensity_for_selection = 0 # minimal intensity to detect a particle.\n",
13741374
"# \"spots_detected_dataframe\" is a pandas data frame that contains the information about the detected spots\n",
1375-
"spots_detected_dataframe = tp.locate(img_spots, diameter=particle_size, minmass=minimal_intensity_for_selection)\n"
1375+
"spots_detected_dataframe = tp.locate(img_spots, diameter=particle_size, minmass=minimal_intensity_for_selection)"
13761376
]
13771377
},
13781378
{
@@ -1614,7 +1614,6 @@
16141614
" # Find the shortest distance in the matrix and record the indexes\n",
16151615
" indexes = np.unravel_index(np.argmin(dist_matrix, axis=None), dist_matrix.shape)\n",
16161616
" indexList.append(indexes)\n",
1617-
"\n",
16181617
" # Set all entries in the row and column of the minimum distance to infinity\n",
16191618
" dist_matrix[indexes[0],:] = np.inf\n",
16201619
" dist_matrix[:,indexes[1]] = np.inf\n",
@@ -1634,9 +1633,7 @@
16341633
"\n",
16351634
"# Create figure with three columns of 20 images\n",
16361635
"fig, ax = plt.subplots(20,3, figsize=(9, 20))\n",
1637-
"\n",
1638-
"img_to_show = img_spots_filtered\n",
1639-
"\n",
1636+
"img_to_show = img_spots_filtered.copy()\n",
16401637
"# Loop through the first 20 matches, and make a plot for each\n",
16411638
"for i in range(20):\n",
16421639
" # Plot the image\n",

Module2-ImageProcessing/M2C_Tracking_Particles.ipynb

+16-29
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
" <left>Particle Tracking</left>\n",
1616
" </h1>\n",
1717
" <p><left>============================================================================</left> </p>\n",
18-
"<pre>Course: BIOM 421, Spring 2024\n",
19-
"Instructor: Brian Munsky\n",
20-
"Authors: Dr. Luis Aguilera, Dr. Zach Fox, Brian Munsky\n",
21-
"Contact Info: munsky@colostate.edu\n",
18+
"<pre>Course: UQ-Bio 2024\n",
19+
"Instructor: Luis Aguilera\n",
20+
"Authors: Luis Aguilera, Will Raymond, Brian Munsky\n",
21+
"Contact Info: luis.aguilera@colostate.edu\n",
2222
"</pre>\n",
2323
" </div>\n",
2424
" </p>\n",
@@ -56,9 +56,9 @@
5656
"\n",
5757
"## List of objectives\n",
5858
"\n",
59-
"1. Simulate 2D random walks.\n",
60-
"2. Implement a code to track single particles.\n",
61-
"3. Calculate mean square displacement and diffusion coefficients.\n",
59+
"1. **Simulate 2D random walks.**\n",
60+
"2. Implement a code to **track single particles**.\n",
61+
"3. Calculate **mean square displacement** and **diffusion coefficients**.\n",
6262
"\n",
6363
"4. Use the scientific libraries needed to segment and track single molecules in live cells."
6464
]
@@ -116,9 +116,9 @@
116116
},
117117
"outputs": [],
118118
"source": [
119-
"#from biom421 import codes\n",
120-
"#students = codes.spring2024Students()\n",
121-
"students = ['name1', 'name'] #codes.spring2024Students()"
119+
"students = ['Daria', 'Wiktoria','Jinyi','Wei','Pilar','Camila','Jayden','Humberto',\n",
120+
"'Jakini','Varvara','Kanniese','Kristi','Eliud','Nam','Lakshay','Margaret',\n",
121+
"'Grace','Apurv','Yinfei','Samantha','Yingli','Rena','Emily','Pegah','Al-Bashir']"
122122
]
123123
},
124124
{
@@ -722,7 +722,6 @@
722722
"def movieFrame(i):\n",
723723
" ax.clear()\n",
724724
" ax.imshow(img_with_spots[i,:,:,0],cmap= 'gray')\n",
725-
"\n",
726725
" for iParticle in range(len(list_trajectories_short)):\n",
727726
" x_val = [x[1] for x in list_trajectories_short[iParticle][:i]]\n",
728727
" y_val = [x[0] for x in list_trajectories_short[iParticle][:i]]\n",
@@ -732,9 +731,7 @@
732731
" \n",
733732
" # Add a line to show the trajectory of the spot.\n",
734733
" ax.plot(x_val,y_val, linewidth = 2, alpha=0.75)\n",
735-
"\n",
736734
" return [fig]\n",
737-
"\n",
738735
"plt.close()\n",
739736
"anim = animation.FuncAnimation(fig, movieFrame, frames=img_with_spots.shape[0], interval=50, blit=True)\n",
740737
"\n",
@@ -1189,7 +1186,7 @@
11891186
"ax[1].imshow(img_with_spots_noisy[selected_time_point,:,:,0], cmap=plt.cm.gray, alpha=0.5)\n",
11901187
"for i in range(0,len(list_center_mass[selected_time_point])):\n",
11911188
" ax[1].plot(list_center_mass[selected_time_point][i][0], list_center_mass[selected_time_point][i][1], color='r',marker='*')\n",
1192-
"ax[1].set_title('Binary image with pixels above treshold')\n",
1189+
"ax[1].set_title('Binary image with pixels above threshold')\n",
11931190
"plt.show()"
11941191
]
11951192
},
@@ -1618,7 +1615,7 @@
16181615
"particle_size = 7 # according to the documentation must be an odd number 3,5,7,9 etc.\n",
16191616
"minimal_intensity_for_selection = 0 # minimal intensity to detect a particle.\n",
16201617
"\n",
1621-
"# \"f\" is a pandas data freame that contains the information about the detected spots\n",
1618+
"# \"f\" is a pandas data frame that contains the information about the detected spots\n",
16221619
"f = tp.locate(video[10,:,:,0], particle_size, minmass=minimal_intensity_for_selection)\n",
16231620
"\n",
16241621
"plt.rcParams[\"figure.figsize\"] = (5,5)\n",
@@ -1670,7 +1667,7 @@
16701667
"plt.rcParams[\"figure.figsize\"] = (10,10) # if movie is too big, change size to (7,7)\n",
16711668
"def figure_viewer_tr(time,mass_text, drop_size):\n",
16721669
" ch = 0\n",
1673-
" f = tp.locate(video[time,:,:,ch],drop_size, minmass=mass_text,maxsize=7,percentile=60) # \"f\" is a pandas data freame that contains the infomation about the detected spots\n",
1670+
" f = tp.locate(video[time,:,:,ch],drop_size, minmass=mass_text,maxsize=7,percentile=60) # \"f\" is a pandas data frame that contains the infomation about the detected spots\n",
16741671
" tp.annotate(f,video[time,:,:,ch]); # tp.anotate is a trackpy function that displays the image with the detected spots\n",
16751672
"\n",
16761673
"values_size=[3,5,7,9] # Notice value must be an odd number.\n",
@@ -1720,11 +1717,11 @@
17201717
"# Loop through each frame of the video, run TP to detect spots, and then create a single\n",
17211718
"# data frame for all time points.\n",
17221719
"ch = 0\n",
1723-
"df_TrackPy = tp.locate(video[0,:,:,ch],selected_size, minmass=selected_intensity,maxsize=7,percentile=60) # \"f\" is a pandas data freame that contains the infomation about the detected spots\n",
1720+
"df_TrackPy = tp.locate(video[0,:,:,ch],selected_size, minmass=selected_intensity,maxsize=7,percentile=60) # \"f\" is a pandas data frame that contains the infomation about the detected spots\n",
17241721
"df_TrackPy['frame'] = 0\n",
17251722
"\n",
17261723
"for iFrame in range(1,video.shape[0]):\n",
1727-
" f = tp.locate(video[iFrame,:,:,ch],selected_size, minmass=selected_intensity,maxsize=7,percentile=60) # \"f\" is a pandas data freame that contains the infomation about the detected spots\n",
1724+
" f = tp.locate(video[iFrame,:,:,ch],selected_size, minmass=selected_intensity,maxsize=7,percentile=60) # \"f\" is a pandas data frame that contains the infomation about the detected spots\n",
17281725
" f['frame'] = iFrame\n",
17291726
" df_TrackPy = pd.concat([df_TrackPy,f])\n",
17301727
"\n",
@@ -1749,7 +1746,7 @@
17491746
"outputs": [],
17501747
"source": [
17511748
"# Create a function that extracts the y and x coordinates from the dataframe and\n",
1752-
"# return an exteneded data frame that includes a boolean true if the spot is in \n",
1749+
"# return an extended data frame that includes a boolean true if the spot is in \n",
17531750
"# the mask and false otherwise.\n",
17541751
"def spots_in_mask(f,mask):\n",
17551752
" # extracting the contours in the image\n",
@@ -1981,15 +1978,11 @@
19811978
"outputs": [],
19821979
"source": [
19831980
"# Make a movie of the original, but now add squares over the tracked particles.\n",
1984-
"\n",
19851981
"# Plotting spots as a video\n",
1986-
"\n",
19871982
"fig, ax = plt.subplots(figsize=(7,7))\n",
1988-
"\n",
19891983
"def movieFrame(i):\n",
19901984
" ax.clear()\n",
19911985
" ax.imshow(video[i,:,:,0],cmap= 'gray')\n",
1992-
"\n",
19931986
" for iParticle in range(0,dfp['particle'].nunique() ):\n",
19941987
" x_val = dfp.loc[(dfp['particle']==iParticle) & (dfp['frame']<=i) ].x.values\n",
19951988
" y_val = dfp.loc[(dfp['particle']==iParticle) & (dfp['frame']<=i) ].y.values\n",
@@ -1999,9 +1992,7 @@
19991992
" \n",
20001993
" # Add a line to show the trajectory of the spot.\n",
20011994
" ax.plot(x_val,y_val, linewidth = 2, alpha=0.75)\n",
2002-
"\n",
20031995
" return [fig]\n",
2004-
"\n",
20051996
"plt.close()\n",
20061997
"anim = animation.FuncAnimation(fig, movieFrame, frames=video.shape[0], interval=50, blit=True)\n",
20071998
"from IPython.display import HTML\n",
@@ -2023,24 +2014,20 @@
20232014
" ax[0].clear(); ax[1].clear()\n",
20242015
" x_val = dfp.loc[(dfp['particle']==spot_number) & (dfp['frame']==i) ].x.values\n",
20252016
" y_val = dfp.loc[(dfp['particle']==spot_number) & (dfp['frame']==i) ].y.values \n",
2026-
" \n",
20272017
" ax[0].imshow(video[i,:,:,0],cmap= 'gray')\n",
20282018
" ax[0].plot(x_val,y_val, 'o', linewidth = 1, markersize=8, color='y', alpha=0.25)\n",
2029-
"\n",
20302019
" if len(x_val)>0: \n",
20312020
" ylim = [int(x_val[0]-7), int(x_val[0]+8)]\n",
20322021
" xlim = [int(y_val[0]-7), int(y_val[0]+8)]\n",
20332022
" ax[1].imshow(video[i,xlim[0]:xlim[1],ylim[0]:ylim[1],1],cmap= 'Spectral_r')\n",
20342023
" return [fig]\n",
2035-
"\n",
20362024
" plt.close()\n",
20372025
" anim = animation.FuncAnimation(fig, movieFrame, frames=video.shape[0], interval=50, blit=True)\n",
20382026
" return anim\n",
20392027
"\n",
20402028
"anim = movieViewer(spot_number=3)\n",
20412029
"HTML(anim.to_html5_video())\n",
20422030
"\n",
2043-
"\n",
20442031
"# interactive_plot = interactive(movieViewer,spot_number = widgets.IntSlider(min=0,max=dfp['particle'].nunique(),value=0,description='Particle Number'),continuous_update=False)\n",
20452032
"# controls = HBox(interactive_plot.children[:-1], layout = Layout(flex_flow='row wrap'))\n",
20462033
"# output = interactive_plot.children[-1]\n",

0 commit comments

Comments
 (0)