Identify Lobed and bumps of Leaves
Categories:
Automated Leaf Feature Extraction: Identifying Lobes and Bumps with MATLAB
Learn how to programmatically identify and quantify lobes and bumps on leaf margins using image processing techniques in MATLAB, crucial for botanical classification and analysis.
Automated identification of leaf features like lobes and bumps is a critical task in digital botany and plant phenotyping. These morphological characteristics are often key discriminators for species identification and can provide insights into plant health and development. This article will guide you through a MATLAB-based approach to detect and quantify these features from leaf images using image processing and computer vision techniques.
Understanding Leaf Margin Features
Leaf margins exhibit a wide variety of shapes, from entire (smooth) to serrate (toothed), dentate (toothed with teeth pointing outwards), crenate (rounded teeth), and lobed. Lobes are prominent projections, often rounded or pointed, that extend from the main body of the leaf. Bumps, on the other hand, refer to smaller, often more numerous undulations or irregularities along the margin. Distinguishing between these can be challenging, but a systematic approach using curvature analysis of the leaf boundary can provide robust results.
Common leaf margin types and their characteristics.
Preprocessing and Boundary Extraction
Before we can analyze the leaf margin, we need to isolate the leaf from its background and extract its boundary. This typically involves converting the image to grayscale, applying a threshold to create a binary mask, and then using morphological operations to clean up the mask. Finally, the bwboundaries
function in MATLAB is used to find the coordinates of the leaf's perimeter.
%% Load Image and Preprocess
I = imread('leaf_sample.jpg');
% Convert to grayscale if not already
if size(I, 3) == 3
grayI = rgb2gray(I);
else
grayI = I;
end
% Binarize the image (adjust threshold as needed)
bwI = imbinarize(grayI, 'adaptive'); % Or use a fixed threshold like graythresh(grayI)
% Invert if the leaf is dark on a light background
if mean(bwI(:)) > 0.5
bwI = ~bwI;
end
% Fill holes and remove small objects
bwI = imfill(bwI, 'holes');
bwI = bwareaopen(bwI, 500); % Remove objects smaller than 500 pixels
% Extract boundaries
B = bwboundaries(bwI, 'noholes');
% Assuming the largest boundary is the leaf
if ~isempty(B)
[~, idx] = max(cellfun(@numel, B));
boundary = B{idx};
else
error('No boundaries found.');
end
% Display the boundary
figure;
imshow(I);
hold on;
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2);
title('Extracted Leaf Boundary');
hold off;
MATLAB code for loading, preprocessing, and extracting the leaf boundary.
Curvature Analysis for Feature Detection
Lobed and bumpy features manifest as regions of high curvature along the leaf margin. We can calculate the curvature at each point along the boundary. Peaks in positive curvature often correspond to the tips of lobes or bumps, while valleys (negative curvature) correspond to the sinuses between them. A common method for curvature estimation involves fitting a local polynomial or using finite differences on smoothed boundary coordinates.
%% Curvature Calculation (Simplified Example)
% Smooth the boundary to reduce noise
windowSize = 15; % Adjust window size based on leaf size and desired smoothing
smoothedBoundaryX = movmean(boundary(:,2), windowSize);
smoothedBoundaryY = movmean(boundary(:,1), windowSize);
% Calculate derivatives using finite differences
dx = gradient(smoothedBoundaryX);
dy = gradient(smoothedBoundaryY);
ddx = gradient(dx);
ddy = gradient(dy);
% Curvature formula: K = (dx*ddy - dy*ddx) / (dx^2 + dy^2)^(3/2)
curvature = (dx .* ddy - dy .* ddx) ./ ((dx.^2 + dy.^2).^(3/2));
% Normalize curvature for better visualization/thresholding
curvature = (curvature - min(curvature)) / (max(curvature) - min(curvature));
% Find peaks in curvature (potential lobes/bumps)
[pks, locs] = findpeaks(curvature, 'MinPeakHeight', 0.5, 'MinPeakDistance', 20); % Adjust thresholds
% Display curvature and detected peaks
figure;
subplot(2,1,1);
plot(curvature);
title('Normalized Curvature along Boundary');
xlim([0 length(curvature)]);
subplot(2,1,2);
imshow(I);
hold on;
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 1);
plot(smoothedBoundaryX(locs), smoothedBoundaryY(locs), 'go', 'MarkerSize', 8, 'LineWidth', 2);
title('Detected Lobes/Bumps');
hold off;
MATLAB code for calculating curvature and detecting peaks.
windowSize
for smoothing and MinPeakHeight
, MinPeakDistance
parameters for findpeaks
are crucial. Experiment with these values based on the resolution of your images and the typical size of the lobes/bumps you wish to detect. Larger values will detect fewer, larger features (lobes), while smaller values might pick up more fine-grained bumps.Distinguishing Lobes from Bumps
Once potential features are identified by curvature peaks, further analysis is needed to classify them as lobes or bumps. This can be done by considering the prominence or width of the curvature peak, or by analyzing the local geometry around the peak. For instance, a lobe might correspond to a wider, more pronounced curvature peak, while a bump might be narrower. You could also measure the distance between adjacent peaks and valleys to infer the size of the feature.
Workflow for automated leaf lobe and bump identification.
1. Prepare Your Image Data
Ensure your leaf images are well-lit and have good contrast between the leaf and the background. Use a consistent imaging setup if possible.
2. Adjust Preprocessing Parameters
Experiment with the binarization threshold and morphological operation sizes (bwareaopen
) to get a clean, accurate leaf mask for your specific dataset.
3. Refine Curvature Analysis Settings
Carefully tune the windowSize
for boundary smoothing and the MinPeakHeight
and MinPeakDistance
parameters in findpeaks
to accurately capture the desired features (lobes or bumps) without excessive noise.
4. Implement Feature Classification Logic
Develop additional logic based on peak prominence, width, or local geometry to differentiate between larger lobes and smaller bumps, if required for your analysis.