macrobot package¶
Submodules¶
macrobot.bgt module¶
- class macrobot.bgt.BgtSegmenter(image_list, path_source, destination_path, store_leaf_path, experiment, dai, file_results)¶
Bases:
MacrobotPipeline
Macrobot analysis for blumeria graminis tritici pathogen.
- NAME = 'BGT'¶
- get_features()¶
Feature extraction for Bgt based on Minimum intensity projection (MinIP). doi:10.1148/rg.255055044
- Returns
A list with the features per lane and it’s position sorted left to right.
- Return type
list with tuple(feature, position)
- get_frames(image_source)¶
Segment the white frame on a microtiter plate. Algorithm is based on Otsu thresholding of the UVS image.
- Parameters
image_source (numpy array.) – The UVS-image (x, y, 1) which is used as source for thresholding.
- Returns
The binary image after Otsu thresholding.
- Return type
numpy array
- get_lanes_rgb()¶
Calls segment_lanes_rgb to extract the RGB lanes within the white frames.
- get_prediction_per_lane(plate_id, destination_path)¶
Predict the Bgt pathogen from the feature extraction method based on thresholding. 255 = pathogen, 0 = background
- Returns
A list with the predictions per lane and it’s position sorted left to right.
- Return type
list with tuple(prediction, position)
macrobot.helpers module¶
Image helper functions.
- macrobot.helpers.get_saturation(image)¶
Extract the saturation channel of a 3-channel image from the HSV color space.
- Parameters
image (numpy array.) – 3-channel image.
- Returns
The 1-channel image saturation channel.
- Return type
numpy array
- macrobot.helpers.rgb_features(image_array, feature_type)¶
Extract min or max intensity projection.
Example Maximum RGB=[50,100,79] -> max_rgb=[0, 100, 0]
Example Minimum RGB=[50,100,79] -> min_rgb=[50, 0, 0].
- Parameters
image_array (numpy array.) – 3-channel image.
feature_type (numpy array.) – minimum or maximum
- Returns
The 3-channel image after intensity projection.
- Return type
numpy array
- macrobot.helpers.save_img_array()¶
- macrobot.helpers.wb_helper(channel, perc=0.05)¶
Performing a white balance on a single channel.
- Parameters
channel (numpy array.) – 1-channel image.
perc (float) – Percentile.
- Returns
The channel after white balance.
- Return type
numpy array
- macrobot.helpers.whitebalance(image)¶
Performing a white balance on a 3-channel image.
Similar to GIMP white balance method.
- Parameters
image (numpy array.) – 3-channel image.
- Returns
The 3-channel image after white balance.
- Return type
numpy array
macrobot.mb_pipeline module¶
Main class for the Macrobot pathogen segmentation pipelines. Version 0.4
- class macrobot.mb_pipeline.MacrobotPipeline(image_list, path_source, destination_path, store_leaf_path, experiment, dai, file_results)¶
Bases:
object
Macrobot pipeline main class.
- Parameters
image_list (list) – A list of all images names per plate (green channel, blue channel, red channel, backlight image, UVS image.
path (str) – The path which contains the raw images coming from the macrobot image acquisition.
destination_path (str) – The path to store the final result images and csv file.
file_results (file object) – The CSV file for each experiments which contains the pathogen prediction per leaf.
experiment (str) – The experiment name.
dai (str) – Days after inoculation.
resize_scale (float) – Scale for resizing the images.
plate_id (str) – Plate ID without the barcode.
y_position (int) – Y Position for the leaves.
- NAME = 'invalid'¶
- create_folder_structure()¶
Create all necessary folders.
- create_report()¶
- do_whitebalance()¶
Calling white balance function in helpers module.
- get_features()¶
Features extraction. Different for each pathogen should be overridden
- get_lanes_binary()¶
Create a binary image from the lanes.
- get_lanes_rgb()¶
Extracts the lanes of the RGB image. Different for each pathogen. Should be overwritten.
- get_leaves_binary()¶
Segment the single leaves.
- get_prediction_per_lane()¶
Predict pathogen. Different for each pathogen should be overridden
- merge_channels()¶
Merging blue, red and green image to create a true 3-channel RGB image.
- read_images()¶
Reading and resizing the images.
- save_images_for_report()¶
- start_pipeline()¶
Starts the Macrobot analysis pipeline.
macrobot.prediction module¶
- macrobot.prediction.predict_leaf(predicted_image, leaf_binary_image)¶
Predict the pathogen per leaf.
- Parameters
predicted_image (numpy array.) – The predicted image with the pathogen. 255 = pathogen, 0 = background
leaf_binary_image (numpy array.) – The binary leaf image to extract the leaf.
- Returns
The infected area in percent. black_pixels * 100 / white_pixels
- Return type
numpy array
- macrobot.prediction.predict_max_rgb(maxrgb_image, backlight_image, rgb_image)¶
Predict the pathogen by thresholding the maxRGB image. Used for BGT.
- Parameters
maxrgb_image (numpy array.) – The max RGB feature image.
backlight_image (numpy array.) – The backlight image used for necrosis detection.
rgb_image (numpy array.) – The RGB image.
- Returns
The predicted image after thresholding. 255 = pathogen, 0 = background
- Return type
numpy array
- macrobot.prediction.predict_min_rgb(minrgb_image, backlight_image, rgb_image)¶
Predict the pathogen by thresholding the minRGB image. Used for BGT.
- Parameters
minrgb_image (numpy array.) – The min RGB feature image.
backlight_image (numpy array.) – The backlight image used for necrosis detection.
rgb_image (numpy array.) – The RGB image.
- Returns
The predicted image after thresholding. 255 = pathogen, 0 = background
- Return type
numpy array
- macrobot.prediction.predict_saturation(image_saturation, image_backlight)¶
Predict the pathogen by thresholding the saturation image. Used for Rust.
- Parameters
image_saturation (numpy array.) – The saturation feature image of HSV color space.
image_backlight (numpy array.) – The backlight image used for necrosis detection.
- Returns
The predicted image after thresholding. 255 = pathogen, 0 = background
- Return type
numpy array
macrobot.puccinia module¶
- class macrobot.puccinia.RustSegmenter(image_list, path_source, destination_path, store_leaf_path, experiment, dai, file_results)¶
Bases:
MacrobotPipeline
Macrobot analysis for Puccinia plant pathogen. Currently works for leaf and stripe rust.
- NAME = 'RUST'¶
- get_features()¶
Feature extraction for Rust based on thresholding the saturation channel.
- Returns
A list with the features per lane and it’s position sorted left to right.
- Return type
list with tuple(feature, position)
- get_frames(image_source)¶
Segment the white frame on a microtiter plate. Algorithm is based on Triangle thresholding of the green channel image. Different from IPK Macrobot!
- Parameters
image_source (numpy array.) – The green channel image (x, y, 1) which is used as source for thresholding.
- Returns
The binary image after thresholding.
- Return type
numpy array
- get_lanes_rgb()¶
Calls segment_lanes_rgb to extract the RGB lanes within the white frames.
- get_prediction_per_lane(plate_id, destination_path)¶
Predict the Rust pathogen from the feature extraction method based on thresholding. 255 = pathogen, 0 = background
- Returns
A list with the predictions per lane and it’s position sorted left to right.
- Return type
list with tuple(prediction, position)
macrobot.cli module¶
- macrobot.cli.main()¶
macrobot.segmentation module¶
- macrobot.segmentation.segment_lanes_binary(lanes_roi_backlight)¶
Threshold the lanes by Otsu method to get a binary image for leaf segmentation. The backlight image is used for this step.
- Parameters
lanes_roi_backlight (list) – The lanes of the backlight image as list of tuple(image, position).
- Returns
Two list with contains the backlight lanes as binary image and it’s positions as tuple(image, position).
- Return type
list
- macrobot.segmentation.segment_lanes_rgb(rgb_image, image_backlight, image_tresholded, experiment, plate_id)¶
Extraction the lanes between the white frames. First we find and filter the contours of the threshold image to find the frames. Then we extract a rectangle inside the white frames and oder the position from left to right.
- Parameters
rgb_image (numpy array.) – 3-channel RGB image to extract the lanes.
image_backlight (numpy array.) – The backlight image.
image_tresholded (numpy array.) – The threshold image we use as source to find the frames.
- Returns
Two list with contains the RGB and backlight lanes and their positions as tuple(image, position).
- Return type
list
- macrobot.segmentation.segment_leaf_binary(lanes_roi_binary, lanes_roi_rgb, plate_id, leaves_per_lane, predicted_lanes, destination_path, y_position, experiment, dai, file_results, store_leaf_path, report_path, report=True)¶
Threshold the leaves by finding and filtering the contours of the binary lane image.
- Parameters
lanes_roi_binary – The lanes of the binary image as list of tuple(image, position).
lanes_roi_rgb (list) – The lanes of the RGB image as list of tuple(image, position).
plate_id (str) – The plate ID.
leaves_per_lane (int) – maximum leaves per lane.
predicted_lanes (list) – The lanes of the predicted image as list of tuple(image, position).
destination_path (str) – The path to store the final result images and csv file.
y_position (int) – Y Position for the leaves.
experiment (str) – The experiment name.
dai (str) – Days after inoculation.
file_results (file object) – The CSV file for each experiments which contains the pathogen prediction per leaf.
- Returns
Two list with contains the backlight lanes as binary image and it’s positions as tuple(image, position).
- Return type
list