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 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 :)
Steven Lucas
Steven Lucas on 19 Apr 2022
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 :)

Sign in to comment.

Accepted Answer

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
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.
DGM on 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().

Sign in to comment.

More Answers (1)

yanqi liu
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, []);
set(h, 'AlphaData',0.8)

Community Treasure Hunt

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

Start Hunting!