- 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)
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!
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
DGM
am 19 Apr. 2022
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
Akzeptierte Antwort
DGM
am 19 Apr. 2022
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
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 Kommentare
DGM
am 20 Apr. 2022
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().
Weitere Antworten (1)
yanqi liu
am 19 Apr. 2022
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)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!