I have a jpg image of a wetland using RGN filter and would like to determine the % "colour" from this image. Any ideas? I'm very much a novice.... Thanks!

3 次查看(过去 30 天)
I am wondering if the green in the above image can be expressed as a % using a MatLab function
Currently, I am doing this manually.
I have tried using some simple code but the error I get is "file not found" so not sure how to even start the analysis.
Any assistance would be greatly appreciated :)
  2 个评论
DGM
DGM 2022-4-19
When you say you want a representation of green percentage, do you want a scalar metric for the whole image (the percent of the image that's "green") or do you want a map that represents the percentage of "greenness" at each location?
Is "green" a linear component of a given pixel's color, or is it a category of color?
Consider the tuple [R G B] = [1 1 0]. Is this color
  • 100% green (because the G value is 1)
  • 50% green (because G/(R+G+B) = 1/2)
  • 33% green (because G/3 = 1/3)
  • 100% yellow (because yellow is a distinct category of color)
Steven Lucas
Steven Lucas 2022-4-19
Yes, I would like a map that represents the % of "greeness".
The "green", as shown in the previously attached figure, are mangrove trees....and all the other vegetation has a yellow/orange hue (saltmarsh). Using a "category" of colour makes sense, as the there is a range of "green".
When I compare previous images from previous years I can visually see that the extent of "green" has changed, and the ability to process images and say that "mangrove density has increased/decreased by ?% since 2019"
My thought was to use the MatLab "colour thresholder" but, again, I can't even load an image into the program to run any analysis :(
Hope this makes sense :)

请先登录,再进行评论。

采纳的回答

DGM
DGM 2022-4-19
This isn't too far from what Yanqi Liu posted, but I'll throw this out there.
A = imread('marsh.jpg');
A = im2double(A);
[R G B] = imsplit(A);
% this is the amount by which G exceeds any other color
% if a pixel is pure green (i.e. [0 1 0]), the result is 1
% if a pixel has more R or B than G, the result is 0
Gexcess = imclamp(G-max(R,B));
imshow(Gexcess)
% maybe the faintly green areas are aquatic grasses
% or some other things which aren't of interest.
% maybe we're only interested in finding areas which
% are _significantly_ more green ...
thresh = 0.16;
Gmask = Gexcess>thresh;
imshow(Gmask)
% percent of entire image that's above the threshold
globalGpct = mean(Gmask,'all')*100
globalGpct = 7.7428
It's also possible that the faint green layers could be excluded without binarization by using imadjust().
I should note that I get slightly different results when I run this in R2019b. It seems imread() has subtle differences in how it decodes the JPG. I don't know what to think about that. I doubt it would be an issue so long as you're only using one version, but it's not like the format doesn't have other caveats already.
  3 个评论
Steven Lucas
Steven Lucas 2022-4-20
Hi DGM,
I have one last little issue......
In the "imread" line , where to I transfer/cut-paste/import the image to, for MatLab to be able to read it when I run the code? You have "Marsh.jpg", but I'm not sure where it is reading it from.
DGM
DGM 2022-4-20
The above code is using the copy of the image that I attached. It's the same image as the one you posted. I just renamed the file when I downloaded it so that it has a unique name. You can change marsh.jpg to whatever path points to your image file.
Also, I attached imclamp().

请先登录,再进行评论。

更多回答(1 个)

yanqi liu
yanqi liu 2022-4-19
yes,sir,may be use color enhance to process,such as
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/968655/image.jpeg');
R = img(:,:,1);
G = img(:,:,2);
V = rgb2gray(img);
Y = 255-img(:,:,3);
xz_green = imsubtract(G,V);
xz_green = imadjust(xz_green, [0.10 0.30], [0 1]);
figure;
imshow(img); hold on;
h = imshow(xz_green, []);
set(h, 'AlphaData',0.8)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by