Skip to content

Commit 9754ccb

Browse files
committed
cleanup first codeblock, comment
1 parent 15e833e commit 9754ccb

1 file changed

Lines changed: 51 additions & 56 deletions

File tree

index.ipynb

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,26 @@
99
"\n",
1010
"For dual VIS/NIR workflows, a visible image is used to identify an image mask for the plant material. We use a landmark transformation to place the VIS image mask over the NIR image. This allows two workflows to be done at once and also allows plant material to be identified in low-quality images. We do not recommend this approach if there is a lot of plant movement between capture of NIR and VIS images.\n",
1111
"\n",
12-
"Updated July 2025."
12+
"Updated August 2025."
1313
]
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 1,
17+
"execution_count": null,
1818
"id": "186ac1ba-a34e-4d01-8c66-b7b8d05ca5da",
1919
"metadata": {},
20-
"outputs": [
21-
{
22-
"name": "stdout",
23-
"output_type": "stream",
24-
"text": [
25-
"Binder detected.\n"
26-
]
27-
}
28-
],
29-
"source": [
30-
"import os\n",
31-
"\n",
32-
"# Detect notebook environment\n",
33-
"def detect_notebook_environment():\n",
34-
" if 'COLAB_GPU' in os.environ:\n",
35-
" print('Google Colaboratory detected.')\n",
36-
" %pip install \"altair>=5\" ipympl plantcv\n",
37-
" \n",
38-
" # Give access and mount your Google Drive (need a Google Account)\n",
39-
" from google.colab import drive\n",
40-
" drive.mount('/content/gdrive')\n",
41-
" \n",
42-
" # Enable widget feature with matplotlib\n",
43-
" from google.colab import output\n",
44-
" output.enable_custom_widget_manager()\n",
45-
" \n",
46-
" #View working directory, may need to change\n",
47-
" %pwd\n",
48-
" else:\n",
49-
" print('Binder detected.')\n",
50-
"\n",
51-
"environment = detect_notebook_environment()"
52-
]
53-
},
54-
{
55-
"cell_type": "code",
56-
"execution_count": 2,
57-
"id": "e1712db7",
58-
"metadata": {
59-
"tags": []
60-
},
6120
"outputs": [],
6221
"source": [
63-
"# Import the needed packages needed to run \n",
64-
"\n",
22+
"# Set the notebook display method\n",
23+
"# If widget is not working, then change to inline\n",
6524
"%matplotlib widget\n",
25+
"\n",
26+
"# Import libraries\n",
6627
"from plantcv import plantcv as pcv\n",
67-
"from plantcv.parallel import WorkflowInputs\n"
28+
"from plantcv.parallel import WorkflowInputs\n",
29+
"\n",
30+
"# Print out the version of PlantCV being used by the Jupyter kernel\n",
31+
"pcv.__version__"
6832
]
6933
},
7034
{
@@ -152,7 +116,7 @@
152116
},
153117
{
154118
"cell_type": "code",
155-
"execution_count": 6,
119+
"execution_count": null,
156120
"id": "85879454-217d-4d85-92e0-d82e8678e6a7",
157121
"metadata": {},
158122
"outputs": [
@@ -208,13 +172,15 @@
208172
}
209173
],
210174
"source": [
175+
"# Segment the plant from background using the blue-yellow channel from the LAB colorspace\n",
176+
"\n",
211177
"b = pcv.rgb2gray_lab(rgb_img=img, channel='b')\n",
212178
"thresh = pcv.threshold.binary(gray_img=b, threshold=145, object_type='light')"
213179
]
214180
},
215181
{
216182
"cell_type": "code",
217-
"execution_count": 7,
183+
"execution_count": null,
218184
"id": "stylish-fifth",
219185
"metadata": {
220186
"tags": []
@@ -247,12 +213,14 @@
247213
}
248214
],
249215
"source": [
216+
"# Clean small objects (noise) from the plant mask will a fill step\n",
217+
"\n",
250218
"filled_mask = pcv.fill(bin_img=thresh, size=1000)"
251219
]
252220
},
253221
{
254222
"cell_type": "code",
255-
"execution_count": 8,
223+
"execution_count": null,
256224
"id": "useful-metallic",
257225
"metadata": {
258226
"tags": []
@@ -285,12 +253,14 @@
285253
}
286254
],
287255
"source": [
256+
"# Make a Region Of Interest\n",
257+
"\n",
288258
"roi = pcv.roi.rectangle(img=img, x=1000, y=700, h=650, w=500)"
289259
]
290260
},
291261
{
292262
"cell_type": "code",
293-
"execution_count": 9,
263+
"execution_count": null,
294264
"id": "destroyed-dimension",
295265
"metadata": {
296266
"tags": []
@@ -324,12 +294,13 @@
324294
],
325295
"source": [
326296
"# Filter binary image to make a clean mask\n",
297+
"\n",
327298
"mask = pcv.roi.quick_filter(mask=filled_mask, roi=roi)"
328299
]
329300
},
330301
{
331302
"cell_type": "code",
332-
"execution_count": 10,
303+
"execution_count": null,
333304
"id": "intermediate-nightlife",
334305
"metadata": {
335306
"tags": []
@@ -442,7 +413,9 @@
442413
],
443414
"source": [
444415
"############### VIS (RGB) Analysis ################ \n",
416+
"# Extract size traits\n",
445417
"analysis_image = pcv.analyze.size(img=img, labeled_mask=mask, label=\"default\")\n",
418+
"# Extract color traits (RGB)\n",
446419
"color_histogram = pcv.analyze.color(rgb_img=img, labeled_mask=mask, label=\"default\")"
447420
]
448421
},
@@ -485,9 +458,19 @@
485458
"nir, path1, filename1 = pcv.readimage(filename=args.nir, mode='native')"
486459
]
487460
},
461+
{
462+
"cell_type": "markdown",
463+
"id": "be73a23f",
464+
"metadata": {},
465+
"source": [
466+
"## Transform the plant mask to get used in NIR analysis\n",
467+
"\n",
468+
"Apply landmark transformation (we chose to use the screws in the background) to align both images. \n"
469+
]
470+
},
488471
{
489472
"cell_type": "code",
490-
"execution_count": 12,
473+
"execution_count": null,
491474
"id": "sustained-slope",
492475
"metadata": {
493476
"tags": []
@@ -570,7 +553,7 @@
570553
}
571554
],
572555
"source": [
573-
"# Apply landmark transformation (we chose to use the screws in the background) to align both images \n",
556+
"# Apply landmark transformation\n",
574557
"img_warped, mat = pcv.transform.warp(img=mask, refimg=nir,\n",
575558
" pts = [(500, 454), (1995, 454), (1995, 1136), (1984, 1811), (511, 1804), \n",
576559
" (500, 1136)],\n",
@@ -767,17 +750,29 @@
767750
" title=\"Histogram of NIR signal intensity\")"
768751
]
769752
},
753+
{
754+
"cell_type": "markdown",
755+
"id": "914d94db",
756+
"metadata": {},
757+
"source": [
758+
"## Save results\n",
759+
"\n",
760+
"The save results function will take the measurements stored when running any PlantCV analysis functions, format, and print an output text file for data analysis.\n",
761+
"\n",
762+
"Results are saved to JSON file, and this allows for database concatenation while running workflows in parallel.\n",
763+
"\n"
764+
]
765+
},
770766
{
771767
"cell_type": "code",
772-
"execution_count": 15,
768+
"execution_count": null,
773769
"id": "direct-nashville",
774770
"metadata": {
775771
"tags": []
776772
},
777773
"outputs": [],
778774
"source": [
779-
"# The save results function will take the measurements stored when running any PlantCV analysis functions, format, \n",
780-
"# and print an output text file for data analysis.\n",
775+
"# Save results to file\n",
781776
"pcv.outputs.save_results(filename=args.result, outformat=\"json\")"
782777
]
783778
}

0 commit comments

Comments
 (0)