<jupyter_start><jupyter_text>Module 1: Introduction to handling image data in Python<jupyter_code>%matplotlib widget
import numpy as np
from plantcv import plantcv as pcv
from matplotlib import pyplot as plt
pcv.params.debug = "plot"
pcv.params.text_size=5
pcv.params.text_thickness=10
pcv.params.line_thickness = 10
def plot_color_channels(img):
    # List of colormaps
    colors = ["Blues", "Greens", "Reds"]
    # Create a new figure with 3 subplots
    figure, plots = plt.subplots(ncols=3, nrows=1, constrained_layout=True)
    # iterate over each subplot
    for i, subplot in zip(range(3), plots):
        # Plot the ith image color channel with the ith colormap
        subplot.imshow(img[:, :, i], cmap=colors[i])
        # Turn off the coordinates
        subplot.set_axis_off()
    # Show the image
    plt.show()<jupyter_output><empty_output><jupyter_text>Help:- PlantCV - https://plantcv.readthedocs.io/en/stable/- NumPy - https://numpy.org/doc/stable/  What is an image?We will open an image and explore the components of it.<jupyter_code># Read in the image fmax.png

# Show what is in the second and third outputs from pcv.readimage<jupyter_output><empty_output><jupyter_text>What are some things we notice about the image?* The image is composed of small square elements, or pixels* The pixel coordinate system origin is in the top left* The coordinate system is left-handed, coordinate values increase down and right* The image is composed of gray values (no color)![2D gird](./figures/grid2D.png)<jupyter_code># Plot the image using a different colormap, some options: 'YlGn', 'viridis', 'magma', 'Oranges', 'RdPu'<jupyter_output><empty_output><jupyter_text>How are images represented in Python?<jupyter_code># Use the Python type function to determine the data type of the image<jupyter_output><empty_output><jupyter_text>Most common Python image analysis packages store images as NumPy arrays[NumPy](https://numpy.org/) is a core package of the scientific Python community.We can use NumPy to determine the shape and size of the image. The dimensions are in the order y (rows), x (columns), z (channels) for images.We can also determine what type of data is stored in each pixel (dtype).<jupyter_code># Print the image data

# Determine the shape and size of the image

# Determine the data type of the image<jupyter_output><empty_output><jupyter_text>Common image data typesThe data type tells how the pixel values are encoded and how many bits they require. It is usefull because it determines the range of values a pixel can take. Unsigned integers (uint) are commonly used:- uint8 = 8-bit (2^8 = 256 possible values. Darkest value = 0, brightest = 255)- uint16 = 16-bit (2^16 = 65,536 possible values. Darkest value = 0, brightest = 65,535)<jupyter_code># Calculate the minimum value observed in gray_img

# Calculate the maximum value observed in gray_img<jupyter_output><empty_output><jupyter_text>Indexing and slicingHelp us to select portions of an array.<jupyter_code># Show the value of the pixel in row 580 and column 940<jupyter_output><empty_output><jupyter_text>The basic slice syntax is _i:j_ where _i_ is the starting index and _j_ is the stopping index<jupyter_code># Create a new image by cropping around the plant part and display it<jupyter_output><empty_output><jupyter_text>* If _i_ is not given it defaults to 0. * If _j_ is not given it defaults to the last value.* : means select all indices along this axis.<jupyter_code># Change the pixels in a full column of the cropped image to an arbitrary value

# Add a constant value to a part of the image

# Extract a full line and make a linear plot<jupyter_output><empty_output><jupyter_text>HistogramHistograms show how the pixels in an image are distributed across the range of values<jupyter_code># Plot a histogram of the pixel intensity values<jupyter_output><empty_output><jupyter_text>RGB imagesThis is a color image encoded using a Red Green Blue (RGB) color model.Note that in OpenCV the color order is BGR.![3D gird](./figures/grid3D.png)The color channels are stacked in a third dimension and increase from the 'front' to the 'back'<jupyter_code># Create a constant color image:
# Initialization with all values to zero

# Create a color image:
# Give a value to each color channel

# Read a color image into the program

# Determine the shape and size of the image

# Determine the data type of the image

# Calculate the minimum value observed in rgb_img

# Calculate the maximum value observed in rgb_img

# Subset the green color channel

# Plot all three color channels

# Calculate the min, max, and mean values in the green color channel

# crop the rgb_img to obtain a single plant

# Print dimensions of subset image

# Save the cropped image<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06980146290491118, 'fraction_numerical': 0.01044932079414838, 'mean_word_length': 4.908641975308642, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '617137', 'license': 'MIT', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1395, 'n_words': 621, 'path': 'module1/start_here.ipynb', 'repo_name': 'danforthcenter/nsf-iuse-hssu-intro', 'size': '4785'}