Sir, How to extract color and shape features for a leaf image?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
To detect disease in an image we need color and shape features to relate to the database.
0 Commenti
Risposte (2)
Shree Harsha Kodi
il 17 Giu 2023
% Step 1: Read the leaf image
leafImage = imread('leaf.jpg');
% Step 2: Preprocess the image (if needed)
% Step 3: Extract color features
hsvImage = rgb2hsv(leafImage);
hueChannel = hsvImage(:, :, 1);
hueMean = mean(hueChannel(:));
% Step 4: Extract shape features
binaryImage = imbinarize(rgb2gray(leafImage), graythresh(leafImage));
binaryImage = imopen(binaryImage, strel('disk', 5));
leafArea = regionprops(binaryImage, 'Area');
% Step 5: Combine the extracted features
featureVector = [hueMean, leafArea.Area];
% Step 6: Perform further analysis or comparison with a database
% Display the extracted features
disp('Extracted Features:');
disp('-------------------');
disp(['Hue Mean: ', num2str(hueMean)]);
disp(['Leaf Area: ', num2str(leafArea.Area)]);
disp('-------------------');
0 Commenti
Image Analyst
il 17 Giu 2023
Search for the tag leaf. There have been so many in the past and I've given code for lots of them.
For example, the attached.
% Mask a leaf out of an RGB image.
clc; % Clear the command window.
clear all;
close all;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 24;
%===============================================================================
% Read in leaf color demo image.
folder = pwd
baseFileName = 'leaf.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
% Extract the individual red, green, and blue color channels.
% redChannel = rgbImage(:, :, 1);
% greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Create a mask of the background only.
mask = blueChannel > 200;
% Display the mask image.
subplot(2, 2, 2);
imshow(mask);
title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Mask out the leaf, leaving only the background.
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
% Display the mask image.
subplot(2, 2, 3);
imshow(maskedRgbImage);
title('Background-Only Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Mask out the background, leaving only the leaf.
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(~mask, 'like', rgbImage));
% Display the mask image.
subplot(2, 2, 4);
imshow(maskedRgbImage);
title('Leaf-Only Image', 'FontSize', fontSize, 'Interpreter', 'None');
0 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!