How to find the green area?
15 ビュー (過去 30 日間)
古いコメントを表示
I am trying to find the area within the green boundaries. How should I go about with the codes?
2 件のコメント
Image Analyst
2013 年 10 月 23 日
Why are you starting a new thread instead of continuing your prior duplicate thread? Even if you didn't like my answer, you don't need to start a new discussion for others to answer.
採用された回答
Image Analyst
2013 年 10 月 23 日
All right, well let's start all over again here.
Do you have the coordinates of the green dots on the perimeter? I think you must because you put the green dots into the overlay, or someone did. If you don't want to use concave hull, then alpha shapes will certainly scare you off, so another approach we can take is morphology. Take the green coordinates and make it a binary image, or if someone else gave you this image and won't tell you the green coordinates, then you can extract it from the image. But with morphology because some of the green dots are spaces quite far apart compared to the others, to get those to close the gap we need to use a large structuring element which will distort the boundary. It won't be exact like the convave hull solution I gave you in your duplicate question. Nonetheless, here is a morphological solution.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in a color demo image.
folder = 'C:\Users\Sharifah\Documents\Temporary';
baseFileName = 'Screen Shot 2013-10-23 at 8.18.51 PM.png';
% 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, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
axis on;
title('Original Color Image', 'FontSize', fontSize);
% 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);
binaryImage = greenChannel >= 250 & redChannel == 0;
% Display the binary image.
subplot(2, 2, 2);
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize);
% Do a morphological closing on it.
se = strel('disk',15);
closedImage = imclose(binaryImage, se);
% Fill the image.
filledImage = imfill(closedImage, 'holes');
% Display the binary image.
subplot(2, 2, 3);
imshow(filledImage);
title('Closed, filled Image', 'FontSize', fontSize);
area = bwarea(filledImage)
message = sprintf('The Area = %.3f pixels', area);
msgbox(message);
2 件のコメント
Image Analyst
2013 年 10 月 27 日
編集済み: Image Analyst
2013 年 10 月 27 日
That is not an error. You have an array of structures. Each element is a structure that describes one single object with whatever measurements you asked for. You can extract them all into individual arrays if you want:
allAreas = [results.Area];
allMajorAxesLengths = [results.MajorAxesLength];
その他の回答 (2 件)
aredhel_vlsi
2014 年 2 月 19 日
Hello people, I would like to locate the green pixels of the image and extract their position in the image. For example at this image : folder = fullfile(matlabroot, '\toolbox\images\imdemos'); baseFileName = 'peppers.png';
I would like to remove the green peppers, and know their position at my image. Could you please help me in that ? Is there any tool I could use? I don't have skills at Image processing, I just want to use it for extracting information. I have managed so far to read the image, imageshow the R,G,B channels but I am stuck now. Please help !Thank you in advance !
1 件のコメント
Image Analyst
2014 年 2 月 19 日
Look at my color segmentation demos. It's simple matter to adapt the thresholds in the demo to pick out green. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
riya reetu
2017 年 9 月 1 日
編集済み: riya reetu
2017 年 9 月 1 日
Could you please give me code for Detection of roadside vegetation
1 件のコメント
Image Analyst
2017 年 9 月 1 日
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!