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!
2 views (last 30 days)
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 :)
DGM on 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));
% 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;
% 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.
More Answers (1)
yanqi liu on 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]);
imshow(img); hold on;
h = imshow(xz_green, );