Skip to content

Commit 04ee8af

Browse files
authored
Merge pull request #1 from danforthcenter/adding_docs
Adding docs
2 parents acf72d1 + b7ff803 commit 04ee8af

File tree

10 files changed

+258
-6
lines changed

10 files changed

+258
-6
lines changed

docs/analyze_size.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Analyze the Size and Shape Characteristics of Objects
2+
3+
Size and shape analysis outputs numeric properties for individual plants, seeds, leaves, etc.
4+
5+
**littlecv.analyze.size**(*img, mask, label="littlecv_test", plot=True*)
6+
7+
**returns** analysis_image
8+
9+
- **Parameters:**
10+
- img - numpy.ndarray, RGB or grayscale image data for plotting.
11+
- mask - numpy.ndarray, binary mask of object.
12+
- label - str, label for outputs
13+
- plot - Logical, should a debug image be printed? Defaults to True.
14+
- **Context:**
15+
- Used to output size and shape characteristics of individual objects (labeled regions).
16+
- About the analysis image: We draw some of the measured shape characteristics on the input `img`. The height, width,
17+
longest path, convex hull, and centroid are drawn in magenta. The edges of the object is drawn in blue.
18+
- **Output data stored:** Data ('area', 'convex_hull_area', 'solidity', 'perimeter', 'width', 'height', 'longest_path',
19+
'center_of_mass, 'convex_hull_vertices', 'object_in_frame', 'ellipse_center', 'ellipse_major_axis', 'ellipse_minor_axis',
20+
'ellipse_angle', 'ellipse_eccentricity', 'total_edge_length') are returned as an Outputs class object, which is basically a dictionary.
21+
22+
23+
```python
24+
25+
from littlecv import littlecv as lcv
26+
27+
# Characterize object shapes
28+
outputs, analysis_image = lcv.size(img=img, mask=mask)
29+
30+
```
31+
32+
**Source Code:** [Here](https://github.com/danforthcenter/contributing_functions_tutorial/blob/main/littlecv/littlecv/analyze_size.py)

docs/binary.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Binary Threshold
2+
3+
Creates a binary image from a gray image based on the threshold values.
4+
The object target can be specified as dark or light.
5+
6+
**littlecv.threshold.binary**(*gray_img, threshold, object_type="light"*)
7+
8+
**returns** thresholded/binary image
9+
10+
- **Parameters:**
11+
- gray_img - Grayscale image data
12+
- threshold - Threshold value (0-255). Values lighter than this are kept.
13+
- plot - Logical, should a debug image be plotted? Defaults to True.
14+
- **Context:**
15+
- Used to help differentiate plant and background
16+
- **Example use:**
17+
- Below
18+
19+
20+
```python
21+
22+
from littlecv import littlecv as lcv
23+
24+
threshold_light = lcv.threshold.binary(gray_img=gray_img, threshold=36)
25+
26+
```
27+
28+
**Source Code:** [Here](https://github.com/danforthcenter/contributing_functions_tutorial/blob/main/littlecv/littlecv/threshold_binary.py)

docs/fill.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Fill
2+
3+
Identifies objects and fills objects that are less than specified size
4+
5+
**littlecv.fill**(*bin_img, size, roi=None*)
6+
7+
**returns** fill_image
8+
9+
- **Parameters:**
10+
- bin_img - Binary image data
11+
- size - minimum object area size in pixels (integer), smaller objects will be filled
12+
- plot - Logical, should a debug image be plotted? Defaults to True.
13+
- **Context:**
14+
- Used to reduce image noise
15+
16+
```python
17+
18+
from littlecv import littlecv as lcv
19+
20+
fill_image = lcv.fill(bin_img=binary_img, size=200)
21+
22+
```
23+
24+
**Source Code:** [Here](https://github.com/danforthcenter/contributing_functions_tutorial/blob/main/littlecv/littlecv/fill.py)

docs/index.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributing New Functions to PlantCV
2+
3+
This repository is a place for you to learn to contribute to PlantCV in one of our guided new contributor workshops. For full documentation or asynchronous learning about contributing to PlantCV please see the [contribution docs](http://plantcv.readthedocs.io/en/latest/CONTRIBUTING/).
4+
5+
## Getting started
6+
7+
To get started you will need an environment with at least `numpy`, `cv2`, `matplotlib`, `pandas`, `python-dateutil`, and `skikit-image` Python libraries installed. We recommend installing `PlantCV` in editable mode if you have not already done so as that will be best for contributing and will install everything you need for this activity. If you are looking to contribute to PlantCV then you may already have a conda environment set up for `PlantCV` and that would work for this workshop as well, whether `PlantCV` is editable or not in that installation.
8+
9+
### Installing littlecv
10+
11+
* First, Clone this repository (`git clone https://github.com/danforthcenter/contributing_tutorial.git`). Throughout this readme we include git CLI commands but [Github Desktop](https://github.com/apps/desktop), [Git Kraken](https://www.gitkraken.com/), or Git through VSCode/other IDEs are all friendlier options and worth learning to use.
12+
* Next, `cd` to the cloned repo (`cd contributing_tutorial`)
13+
* Finally, with your `PlantCV` or equivalent environment active, install `littlecv` by running `pip install -e .`.
14+
15+
Now you will have an editable version of `littlecv` installed locally. You can check your installation by running this command, which should tell you that you'll be an author soon:
16+
17+
```
18+
python -c "from littlecv import littlecv as lcv; print(lcv.__author__)"
19+
```
20+
21+
## The task
22+
23+
In this repository there is a small Python library called `littleCV`, these are just a handful of `PlantCV` functions with some of the more complicated features removed.
24+
25+
There is also an iPython notebook running a simple workflow using `littleCV`. The functions that exist in `littleCV` work in this tutorial, but you'll need a new function to get what you want. In the [`contributing_tutorial`](https://github.com/danforthcenter/contributing_tutorial) activity your task was just to find an error in existing code, which is an important kind of contribution to a codebase like `PlantCV`. In this tutorial your task is to add a totally new outward facing (exported) function. The point of this task is not to do complex Python coding but to familiarize with making edits to the files that define a Python package, writing clean code to match a codebase's style requirements, and making useful docstrings. If you get stuck on the Python coding aspect of this exercise that is okay, everyone contributing to `PlantCV` has different background and experience in Python so some tasks will be easier or harder for different people, you can check the example at the bottom of this readme file for guidance.
26+
27+
The function that you are adding should crop an image using a top left coordinate (x, y), height of the cropped section, and width of the cropped section. Your function should be callable by a user after the standard `from littlecv import littlecv as lcv` import syntax as `lcv.crop` or something similarly named. Other than that, just make a function that crops an image and make the tests pass on github actions (note that this includes making sure that you cover your new function with tests).
28+
29+
30+
31+
#### Steps
32+
33+
* 1: Open a branch with your name (`git checkout -b first_last`).
34+
* 2: Set up an image object to crop in jupyter (run `jupyter-lab` and use GUI).
35+
* 3: Edit `littlecv` code to add your function to `littlecv` OR write your function in jupyter. Some of our team likes to prototype functions in jupyter cells first, others prefer to edit python files and restart the kernel after each set of changes. Which you choose is up to you. Either way you will eventually need a module that defines your function and to add that module to `__init__.py`.
36+
* 4: Restart Jupyter Kernel (or run the cell with your function in it) and test your function, alternating between edits and interactive testing until you are satisfied.
37+
* 5: Write tests for your function. In `PlantCV` this would mean a new `test_crop.py` file, but you can add it to `tests/test_littlecv.py` or make another file, that is up to you. When you are satisfied use `py.test --cov littlecv --cov-report="term-missing"`.
38+
* 6: Write documentation for your new function (see the `docs` folder in this repo) and add the new docs page to `mkdocs.yml`.
39+
* 7: Commit your changes (`git commit -m "your commit message here"`). This is like saving the files on your branch. How often you do this and how granular commits are is mostly up to you.
40+
* 8: Push your changes to github (`git push origin main`). This syncs the changes you've committed to github so that other people could pull them and use them locally.
41+
* 9: Open a Pull Request. These are a feature of Github, not of Git itself, so we'll have to do this online or through a software like Github Desktop. Go to `https://github.com/danforthcenter/contributing_functions_tutorial/tree/YOUR_BRANCH_NAME` or to [`https://github.com/danforthcenter/contributing_functions_tutorial`](https://github.com/danforthcenter/contributing_functions_tutorial) and use the branch dropdown menu to select your branch. On your branch there should be a green `Compare and pull request` button, click that and fill out the template. There is a sidebar of options for labels, assignees, reviewers, etc. In `PlantCV` you'll; use those to describe the purpose of your PR at a very high level, mark it for a certain version milestone or request certain reviewers based on who has domain expertise or last edited those files. Once you are done with the description click `create pull request`. Once the pull request is created the automated checks will run, if those pass then you are done. You might see deepsource problems that do not show up on your local tests since deepsource is more particular about code style, etc.
42+
43+
### The Functions
44+
45+
`littlecv` only has 6 exposed functions, they are:
46+
47+
* [`readimage`](readimage.md): Reads an image into a numpy.ndarray. Simplified from `plantcv.plantcv.read_image`
48+
* [`rgb2gray_lab`](rgb2gray_lab.md): Converts an RGB image to grayscale with either L, A, or B channel. Simplified from `plantcv.plantcv.rgb2gray_lab`.
49+
* [`binary`](binary.md): Applies a binary threshold. Simplified from `plantcv.plantcv.threshold.binary`.
50+
* [`fill`](fill.md): Filters small objects. Simplified from `plantcv.plantcv.fill`.
51+
* [`size`](analyze_size.md): Calculates single value phenotypes given a mask and image. Simplified from `plantcv.analyze.size`
52+
* [`plot_image`](plot_image.md): Plots an image. Simplified from `plantcv.plantcv.plot_image`.
53+
54+
There is also a minimal `Outputs` class called by `size` to store results which is based on the `plantcv.plantcv.Outputs` class.
55+
56+
57+
### If you get stuck
58+
59+
If you get stuck with the Python coding part of this exercise then start from something like this example to familiarize with subsetting numpy arrays:
60+
61+
```
62+
import numpy as np
63+
# images are numpy arrays
64+
# numpy arrays can have each dimension subset with a range [inclusive, exclusive)
65+
a1 = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
66+
print(a1[0:1, 0:3]) # first "row", first, second, and third "columns". Remember Python is 0 indexed.
67+
68+
# many images will have at least 3 channels
69+
a2 = np.zeros((100, 100,3))
70+
# ":" is shorthand for "all"
71+
a2[:,:,0] = 255
72+
# print a small piece of this array
73+
a2[0:2, 0:2, 0:4]
74+
```

docs/plot_image.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Plot Image
2+
3+
Open the image in a window or plot in a Jupyter notebook using [matplotlib](https://matplotlib.org/).
4+
5+
**plot_image**(*img, plot=True*)
6+
7+
**returns** none
8+
9+
- **Parameters:**
10+
- img - image object
11+
- **Context:**
12+
- Often used to debug new image processing workflows
13+
- Used to view images in Jupyter notebooks (or in a window)
14+
15+
```python
16+
17+
from littlecv import littlecv as lcv
18+
lcv.plot_image(img)
19+
20+
```
21+
22+
**Source Code:** [Here](https://github.com/danforthcenter/contributing_functions_tutorial/tree/main/littlecv/littlecv/plot_image.py)

docs/readimage.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Read Image
2+
3+
Reads image into numpy ndarray and splits the path and image filename (*see note about when `mode='envi'`). Most modes of use of this function is a wrapper for the OpenCV function [imread](http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html).
4+
5+
**littlecv.readimage**(*filename, plot=True*)
6+
7+
**returns** img, path, image filename
8+
9+
- **Parameters:**
10+
- filename - image file to be read (possibly including a path)
11+
- plot - Logical, should the image be plotted when read? Defaults to True.
12+
- **Context:**
13+
- Reads in file to be processed
14+
- **Notes:**
15+
- Simplified from `plantcv.plantcv.readimage`.
16+
17+
```python
18+
from littlecv import littlecv as lcv
19+
20+
#read in image
21+
img, path, img_filename = lcv.readimage(filename="home/user/images/test-image.png")
22+
23+
```
24+
25+
**Source Code:** [Here](https://github.com/danforthcenter/contributing_functions_tutorial/blob/main/littlecv/littlecv/readimage.py)

docs/rgb2gray_lab.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## RGB to LAB
2+
3+
Convert image from RGB color space to LAB color space and split the channels.
4+
5+
**littlecv.rgb2gray_lab**(*rgb_img, channel, plot=True*)
6+
7+
**returns** split image (l, a, or b channel)
8+
9+
- **Parameters:**
10+
- rgb_img - RGB image data
11+
- channel - Split 'l' (lightness), 'a' (green-magenta), or 'b' (blue-yellow) channel
12+
- plot - Logical, should a debug image be printed? Defaults to True.
13+
14+
- **Context:**
15+
- Used to help differentiate plant and background
16+
17+
```python
18+
19+
from littlecv import littlecv as lcv
20+
21+
l_channel = lcv.rgb2gray_lab(rgb_img=rgb_img, channel='l')
22+
23+
```
24+
25+
**Source Code:** [Here](https://github.com/danforthcenter/contributing_functions_tutorial/blob/main/littlecv/littlecv/rgb2gray_lab.py)

littlecv/littlecv/plot_image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
from matplotlib import pyplot as plt
66

77

8-
def plot_image(img, plot=True, **kwargs):
8+
def plot_image(img, plot=True):
99
"""Plot an image to the screen.
1010
1111
:param img: numpy.ndarray, ggplot, xarray.core.dataarray.DataArray
1212
:param plot: bool, make a plot
1313
(defaults True, only used internally in place of pcv.params.debug)
14-
:param kwargs: key-value arguments to xarray.plot method
1514
:return:
1615
"""
1716
dimensions = numpy.shape(img)

mkdocs.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
site_name: LittleCV
2+
site_url: https://https://datasci.danforthcenter.org/littlecv/
3+
site_description: Learn to contribute to PlantCV
4+
site_author: PlantCV Development Team
5+
repo_url: https://github.com/danforthcenter/contributing_functions_tutorial
6+
copyright: Copyright 2025, Donald Danforth Plant Science Center
7+
theme: readthedocs
8+
9+
nav:
10+
- Home: index.md
11+
- Documentation:
12+
- 'Read an Image': readimage.md
13+
- 'Plot an Image': plot_image.md
14+
- 'RGB to Grayscale': rgb2gray_lab.md
15+
- 'Binary Thresholding': binary.md
16+
- 'Fill Holes': fill.md
17+
- 'Shape Analysis': analyze_size.md
18+
markdown_extensions:
19+
- toc:
20+
permalink: True
21+
- admonition

readme.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ The function that you are adding should crop an image using a top left coordinat
3232

3333
* 1: Open a branch with your name (`git checkout -b first_last`).
3434
* 2: Set up an image object to crop in jupyter (run `jupyter-lab` and use GUI).
35-
* 3: Edit `littlecv` code to add your function to `littlecv` OR write your function in jupyter. Some of our team likes to prototype functions in jupyter cells first, others prefer to edit python files and restart the kernel after each set of changes. Which you choose is up to you.
35+
* 3: Edit `littlecv` code to add your function to `littlecv` OR write your function in jupyter. Some of our team likes to prototype functions in jupyter cells first, others prefer to edit python files and restart the kernel after each set of changes. Which you choose is up to you. Either way you will eventually need a module that defines your function and to add that module to `__init__.py`.
3636
* 4: Restart Jupyter Kernel (or run the cell with your function in it) and test your function, alternating between edits and interactive testing until you are satisfied.
3737
* 5: Write tests for your function. In `PlantCV` this would mean a new `test_crop.py` file, but you can add it to `tests/test_littlecv.py` or make another file, that is up to you. When you are satisfied use `py.test --cov littlecv --cov-report="term-missing"`.
38-
* 6: Commit your changes (`git commit -m "your commit message here"`). This is like saving the files on your branch. How often you do this and how granular commits are is mostly up to you.
39-
* 7: Push your changes to github (`git push origin main`). This syncs the changes you've committed to github so that other people could pull them and use them locally.
40-
* 8: Open a Pull Request. These are a feature of Github, not of Git itself, so we'll have to do this online or through a software like Github Desktop. Go to `https://github.com/danforthcenter/contributing_functions_tutorial/tree/YOUR_BRANCH_NAME` or to [`https://github.com/danforthcenter/contributing_functions_tutorial`](https://github.com/danforthcenter/contributing_functions_tutorial) and use the branch dropdown menu to select your branch. On your branch there should be a green `Compare and pull request` button, click that and fill out the template. There is a sidebar of options for labels, assignees, reviewers, etc. In `PlantCV` you'll; use those to describe the purpose of your PR at a very high level, mark it for a certain version milestone or request certain reviewers based on who has domain expertise or last edited those files. Once you are done with the description click `create pull request`. Once the pull request is created the automated checks will run, if those pass then you are done. You might see deepsource problems that do not show up on your local tests since deepsource is more particular about code style, etc.
38+
* 6: Write documentation for your new function (see the `docs` folder in this repo) and add the new docs page to `mkdocs.yml`.
39+
* 7: Commit your changes (`git commit -m "your commit message here"`). This is like saving the files on your branch. How often you do this and how granular commits are is mostly up to you.
40+
* 8: Push your changes to github (`git push origin main`). This syncs the changes you've committed to github so that other people could pull them and use them locally.
41+
* 9: Open a Pull Request. These are a feature of Github, not of Git itself, so we'll have to do this online or through a software like Github Desktop. Go to `https://github.com/danforthcenter/contributing_functions_tutorial/tree/YOUR_BRANCH_NAME` or to [`https://github.com/danforthcenter/contributing_functions_tutorial`](https://github.com/danforthcenter/contributing_functions_tutorial) and use the branch dropdown menu to select your branch. On your branch there should be a green `Compare and pull request` button, click that and fill out the template. There is a sidebar of options for labels, assignees, reviewers, etc. In `PlantCV` you'll; use those to describe the purpose of your PR at a very high level, mark it for a certain version milestone or request certain reviewers based on who has domain expertise or last edited those files. Once you are done with the description click `create pull request`. Once the pull request is created the automated checks will run, if those pass then you are done. You might see deepsource problems that do not show up on your local tests since deepsource is more particular about code style, etc.
42+
4143

4244
### The Functions
4345

0 commit comments

Comments
 (0)