can any one help me find area under a curve?
1 view (last 30 days)
Show older comments
Surya Gnyawali
on 1 Jul 2017
Commented: Walter Roberson
on 4 Jul 2017
Hi, I have an RGB image I of size 1047x995 uint8, to integrate in matlab, using with trapz() or cumtrapz(). I separated the channels R, G, B. Now I plotted a curve that averages all columns and gives a curve. Now I need to find the area under the curve. Please help
The idea is to quantify a rgb image and it's red, green & blue channels.
3 Comments
Walter Roberson
on 4 Jul 2017
The formula for trapz(y) for vector y works out as
result = sum(y) - 1/2*(y(1) + y(end))
When the input is a vector, the result is a scalar.
The formula for cumtrapz(y) for vector y works out as
result = cumsum(y) - 1/2*(y(1) + y)
For example,
[ 0, x1/2 + x2/2, x1/2 + x2 + x3/2, x1/2 + x2 + x3 + x4/2, x1/2 + x2 + x3 + x4 + x5/2, x1/2 + x2 + x3 + x4 + x5 + x6/2, x1/2 + x2 + x3 + x4 + x5 + x6 + x7/2, x1/2 + x2 + x3 + x4 + x5 + x6 + x7 + x8/2, x1/2 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9/2, x1/2 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10/2]
"Is this area in mm^2. or depends on the resolution of the original images?"
For your purposes, neither. You are integrating mean intensity units over a width, so the area is going to be intensity units times pixels. Mean intensity units is found by integrating intensity units by pixels and then dividing by the length, so it has no remaining length unit.
I have no idea what you are going to use the result for.
If you had doing a 2D trapz then you could have been integrating intensity units over area, which would have given you a measure of total energy over the rectangular area, which could then be scaled according to the area of one square pixel -- if, that is, you knew the resolution.
Chances are that you do not know the resolution. If the picture was taken with most cameras, then if there is a resolution in the picture headers at all, it is likely to be 72, the common nominal pixels-per-inch of older displays (not of the camera itself.) DSLR with auto-focus just might happen to record enough information in the headers to do a reasonable pixel size estimate, by looking at the autofocus distance and the aperture and knowing the lens focal length, but you cannot really count on the image headers unless you are using a scientific camera with firmware developed for imaging applications (e.g., a precision microscope.)
Accepted Answer
Walter Roberson
on 1 Jul 2017
? You mean like
red = YourImage(:,:,1);
red_int = cumtrapz( mean(red, 2 ) );
I am not at all sure what the point is in taking the integral of the mean of the red channel...
2 Comments
Walter Roberson
on 2 Jul 2017
I do not get an error with that code.
YourImage = imread('tape.png');
r = YourImage(:,:,1);
pp = plot(mean(r));
pp.Color = 'red'; %line color
Int = cumtrapz(mean(r,2));
What error do you observe?
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!